Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remap Windows targets triples to their LLVM counterparts #1176

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions dev-tools/gen-target-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ fn generate_riscv_arch_mapping(f: &mut File, target_specs: &RustcTargetSpecs) {
write_target_tuple_mapping(f, "RISCV_ARCH_MAPPING", &riscv_target_mapping);
}

fn generate_windows_triple_mapping(f: &mut File, target_specs: &RustcTargetSpecs) {
let mut windows_target_mapping = target_specs
.0
.iter()
.filter_map(|(target, target_spec)| {
let rust_target_parts = target.splitn(4, '-').collect::<Vec<_>>();
let os = *rust_target_parts.get(2)?;
(os.contains("windows") && target != &*target_spec.llvm_target)
.then_some((&**target, &*target_spec.llvm_target))
})
.collect::<Vec<_>>();
windows_target_mapping.sort_unstable_by_key(|(triple, _)| &**triple);
windows_target_mapping.dedup();
write_target_tuple_mapping(f, "WINDOWS_TRIPLE_MAPPING", &windows_target_mapping);
}

fn main() {
let target_specs = get_target_specs_from_json();

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

// Start generating
generate_riscv_arch_mapping(&mut f, &target_specs);
generate_windows_triple_mapping(&mut f, &target_specs);

// Flush the data onto disk
f.flush().unwrap();
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,17 @@ impl Build {
}

cmd.push_cc_arg(format!("--target={}", target).into());
} else if let Ok(index) = target_info::WINDOWS_TRIPLE_MAPPING
.binary_search_by_key(&target, |(target, _)| target)
{
cmd.args.push(
format!(
"--target={}-{}",
target_info::WINDOWS_TRIPLE_MAPPING[index].1,
rest
)
.into(),
)
} else {
cmd.push_cc_arg(format!("--target={}", target).into());
}
Expand Down
12 changes: 12 additions & 0 deletions src/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ pub const RISCV_ARCH_MAPPING: &[(&str, &str)] = &[
("riscv64gc", "riscv64"),
("riscv64imac", "riscv64"),
];
pub const WINDOWS_TRIPLE_MAPPING: &[(&str, &str)] = &[
("aarch64-pc-windows-gnullvm", "aarch64-pc-windows-gnu"),
("aarch64-uwp-windows-msvc", "aarch64-pc-windows-msvc"),
("i686-pc-windows-gnullvm", "i686-pc-windows-gnu"),
("i686-uwp-windows-gnu", "i686-pc-windows-gnu"),
("i686-uwp-windows-msvc", "i686-pc-windows-msvc"),
("i686-win7-windows-msvc", "i686-pc-windows-msvc"),
("thumbv7a-uwp-windows-msvc", "thumbv7a-pc-windows-msvc"),
("x86_64-pc-windows-gnullvm", "x86_64-pc-windows-gnu"),
("x86_64-uwp-windows-gnu", "x86_64-pc-windows-gnu"),
("x86_64-uwp-windows-msvc", "x86_64-pc-windows-msvc"),
];