Skip to content

Commit 1c10013

Browse files
authored
Remap Windows targets triples to their LLVM counterparts (#1176)
1 parent 4b723d9 commit 1c10013

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

dev-tools/gen-target-info/src/main.rs

+17
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ fn generate_riscv_arch_mapping(f: &mut File, target_specs: &RustcTargetSpecs) {
2121
write_target_tuple_mapping(f, "RISCV_ARCH_MAPPING", &riscv_target_mapping);
2222
}
2323

24+
fn generate_windows_triple_mapping(f: &mut File, target_specs: &RustcTargetSpecs) {
25+
let mut windows_target_mapping = target_specs
26+
.0
27+
.iter()
28+
.filter_map(|(target, target_spec)| {
29+
let rust_target_parts = target.splitn(4, '-').collect::<Vec<_>>();
30+
let os = *rust_target_parts.get(2)?;
31+
(os.contains("windows") && target != &*target_spec.llvm_target)
32+
.then_some((&**target, &*target_spec.llvm_target))
33+
})
34+
.collect::<Vec<_>>();
35+
windows_target_mapping.sort_unstable_by_key(|(triple, _)| &**triple);
36+
windows_target_mapping.dedup();
37+
write_target_tuple_mapping(f, "WINDOWS_TRIPLE_MAPPING", &windows_target_mapping);
38+
}
39+
2440
fn main() {
2541
let target_specs = get_target_specs_from_json();
2642

@@ -34,6 +50,7 @@ fn main() {
3450

3551
// Start generating
3652
generate_riscv_arch_mapping(&mut f, &target_specs);
53+
generate_windows_triple_mapping(&mut f, &target_specs);
3754

3855
// Flush the data onto disk
3956
f.flush().unwrap();

src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -2189,6 +2189,17 @@ impl Build {
21892189
}
21902190

21912191
cmd.push_cc_arg(format!("--target={}", target).into());
2192+
} else if let Ok(index) = target_info::WINDOWS_TRIPLE_MAPPING
2193+
.binary_search_by_key(&target, |(target, _)| target)
2194+
{
2195+
cmd.args.push(
2196+
format!(
2197+
"--target={}-{}",
2198+
target_info::WINDOWS_TRIPLE_MAPPING[index].1,
2199+
rest
2200+
)
2201+
.into(),
2202+
)
21922203
} else {
21932204
cmd.push_cc_arg(format!("--target={}", target).into());
21942205
}

src/target_info.rs

+12
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ pub const RISCV_ARCH_MAPPING: &[(&str, &str)] = &[
1212
("riscv64gc", "riscv64"),
1313
("riscv64imac", "riscv64"),
1414
];
15+
pub const WINDOWS_TRIPLE_MAPPING: &[(&str, &str)] = &[
16+
("aarch64-pc-windows-gnullvm", "aarch64-pc-windows-gnu"),
17+
("aarch64-uwp-windows-msvc", "aarch64-pc-windows-msvc"),
18+
("i686-pc-windows-gnullvm", "i686-pc-windows-gnu"),
19+
("i686-uwp-windows-gnu", "i686-pc-windows-gnu"),
20+
("i686-uwp-windows-msvc", "i686-pc-windows-msvc"),
21+
("i686-win7-windows-msvc", "i686-pc-windows-msvc"),
22+
("thumbv7a-uwp-windows-msvc", "thumbv7a-pc-windows-msvc"),
23+
("x86_64-pc-windows-gnullvm", "x86_64-pc-windows-gnu"),
24+
("x86_64-uwp-windows-gnu", "x86_64-pc-windows-gnu"),
25+
("x86_64-uwp-windows-msvc", "x86_64-pc-windows-msvc"),
26+
];

0 commit comments

Comments
 (0)