Skip to content

Commit 8db7ac3

Browse files
committed
Add UWP targets
i686 support doesn't compile yet, but x86_64 does, and resulting cdylib's are passing the WACK tests
1 parent 312e9ce commit 8db7ac3

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::spec::{LinkerFlavor, Target, TargetResult};
2+
3+
pub fn target() -> TargetResult {
4+
let mut base = super::uwp_base::opts();
5+
base.cpu = "pentium4".to_string();
6+
base.max_atomic_width = Some(64);
7+
base.eliminate_frame_pointer = false; // Required for backtraces
8+
9+
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
10+
// space available to x86 Windows binaries on x86_64.
11+
base.pre_link_args
12+
.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,--large-address-aware".to_string());
13+
14+
Ok(Target {
15+
llvm_target: "i686-pc-windows-gnu".to_string(),
16+
target_endian: "little".to_string(),
17+
target_pointer_width: "32".to_string(),
18+
target_c_int_width: "32".to_string(),
19+
data_layout: "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32".to_string(),
20+
arch: "x86".to_string(),
21+
target_os: "uwp".to_string(),
22+
target_env: "gnu".to_string(),
23+
target_vendor: "pc".to_string(),
24+
linker_flavor: LinkerFlavor::Gcc,
25+
options: base,
26+
})
27+
}

src/librustc_target/spec/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ mod solaris_base;
6161
mod uefi_base;
6262
mod windows_base;
6363
mod windows_msvc_base;
64+
mod uwp_base;
6465
mod thumb_base;
6566
mod l4re_base;
6667
mod fuchsia_base;
@@ -434,6 +435,8 @@ supported_targets! {
434435

435436
("x86_64-pc-windows-gnu", x86_64_pc_windows_gnu),
436437
("i686-pc-windows-gnu", i686_pc_windows_gnu),
438+
("i686-pc-uwp-gnu", i686_pc_uwp_gnu),
439+
("x86_64-pc-uwp-gnu", x86_64_pc_uwp_gnu),
437440

438441
("aarch64-pc-windows-msvc", aarch64_pc_windows_msvc),
439442
("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc),

src/librustc_target/spec/uwp_base.rs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
2+
use std::default::Default;
3+
4+
pub fn opts() -> TargetOptions {
5+
let mut pre_link_args = LinkArgs::new();
6+
pre_link_args.insert(LinkerFlavor::Gcc, vec![
7+
// Tell GCC to avoid linker plugins, because we are not bundling
8+
// them with Windows installer, and Rust does its own LTO anyways.
9+
"-fno-use-linker-plugin".to_string(),
10+
11+
// Always enable DEP (NX bit) when it is available
12+
"-Wl,--nxcompat".to_string(),
13+
14+
// Do not use the standard system startup files or libraries when linking
15+
"-nostdlib".to_string(),
16+
]);
17+
18+
let mut late_link_args = LinkArgs::new();
19+
late_link_args.insert(LinkerFlavor::Gcc, vec![
20+
//"-lwinstorecompat".to_string(),
21+
//"-lmingwex".to_string(),
22+
//"-lwinstorecompat".to_string(),
23+
"-lwinstorecompat".to_string(),
24+
"-lruntimeobject".to_string(),
25+
"-lsynchronization".to_string(),
26+
"-lvcruntime140_app".to_string(),
27+
"-lucrt".to_string(),
28+
"-lwindowsapp".to_string(),
29+
"-lmingwex".to_string(),
30+
"-lmingw32".to_string(),
31+
]);
32+
33+
TargetOptions {
34+
// FIXME(#13846) this should be enabled for windows
35+
function_sections: false,
36+
linker: Some("gcc".to_string()),
37+
dynamic_linking: true,
38+
executables: false,
39+
dll_prefix: String::new(),
40+
dll_suffix: ".dll".to_string(),
41+
exe_suffix: ".exe".to_string(),
42+
staticlib_prefix: "lib".to_string(),
43+
staticlib_suffix: ".a".to_string(),
44+
no_default_libraries: true,
45+
target_family: Some("windows".to_string()),
46+
is_like_windows: true,
47+
allows_weak_linkage: false,
48+
pre_link_args,
49+
pre_link_objects_exe: vec![
50+
"crt2.o".to_string(), // mingw C runtime initialization for executables
51+
"rsbegin.o".to_string(), // Rust compiler runtime initialization, see rsbegin.rs
52+
],
53+
pre_link_objects_dll: vec![
54+
"dllcrt2.o".to_string(), // mingw C runtime initialization for dlls
55+
"rsbegin.o".to_string(),
56+
],
57+
late_link_args,
58+
post_link_objects: vec![
59+
"rsend.o".to_string(),
60+
"libgcc.a".to_string(), // libgcc or compiler-rt
61+
],
62+
custom_unwind_resume: true,
63+
abi_return_struct_as_int: true,
64+
emit_debug_gdb_scripts: false,
65+
requires_uwtable: true,
66+
67+
.. Default::default()
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::spec::{LinkerFlavor, Target, TargetResult};
2+
3+
pub fn target() -> TargetResult {
4+
let mut base = super::uwp_base::opts();
5+
base.cpu = "x86-64".to_string();
6+
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
7+
base.max_atomic_width = Some(64);
8+
9+
Ok(Target {
10+
llvm_target: "x86_64-pc-windows-gnu".to_string(),
11+
target_endian: "little".to_string(),
12+
target_pointer_width: "64".to_string(),
13+
target_c_int_width: "32".to_string(),
14+
data_layout: "e-m:w-i64:64-f80:128-n8:16:32:64-S128".to_string(),
15+
arch: "x86_64".to_string(),
16+
target_os: "uwp".to_string(),
17+
target_env: "gnu".to_string(),
18+
target_vendor: "pc".to_string(),
19+
linker_flavor: LinkerFlavor::Gcc,
20+
options: base,
21+
})
22+
}

0 commit comments

Comments
 (0)