Test output
+
+ \`\`\`
+ $(cat test_output.txt)
+ \`\`\`
+
+
+ " --head $(git branch --show-current)
diff --git a/dev-tools/gen-target-info/src/lib.rs b/dev-tools/gen-target-info/src/lib.rs
index 48bb5550..ea4420a6 100644
--- a/dev-tools/gen-target-info/src/lib.rs
+++ b/dev-tools/gen-target-info/src/lib.rs
@@ -3,6 +3,3 @@ pub use target_specs::*;
mod read;
pub use read::*;
-
-mod write;
-pub use write::*;
diff --git a/dev-tools/gen-target-info/src/main.rs b/dev-tools/gen-target-info/src/main.rs
index 383d2920..b7f8dad5 100644
--- a/dev-tools/gen-target-info/src/main.rs
+++ b/dev-tools/gen-target-info/src/main.rs
@@ -5,76 +5,18 @@ use gen_target_info::{
get_target_spec_from_msrv, get_target_specs_from_json, get_targets_msrv, RustcTargetSpecs,
};
-const PRELUDE: &str = r#"//! This file is generated code. Please edit the generator
-//! in dev-tools/gen-target-info if you need to make changes.
+const PRELUDE: &str = r#"//! This file is generated code. Please edit the generator in
+//! dev-tools/gen-target-info if you need to make changes, or see
+//! src/target/llvm.rs if you need to configure a specific LLVM triple.
"#;
fn generate_target_mapping(f: &mut File, target_specs: &RustcTargetSpecs) -> std::io::Result<()> {
- writeln!(f, "use super::TargetInfo;")?;
- writeln!(f)?;
- writeln!(
- f,
- "pub(crate) const LIST: &[(&str, TargetInfo<'static>)] = &["
- )?;
+ writeln!(f, "#[rustfmt::skip]")?;
+ writeln!(f, "pub(crate) const LLVM_TARGETS: &[(&str, &str)] = &[")?;
- for (triple, spec) in &target_specs.0 {
- let full_arch = triple.split_once('-').unwrap().0;
- let arch = &spec.arch;
- let vendor = spec.vendor.as_deref().unwrap_or("unknown");
- let os = spec.os.as_deref().unwrap_or("none");
- let env = spec.env.as_deref().unwrap_or("");
- let abi = spec.abi.as_deref().unwrap_or("");
-
- // FIXME(madsmtm): Unnecessary once we bump MSRV to Rust 1.74
- let llvm_target = if spec.llvm_target == "armv7-apple-ios7.0.0" {
- "armv7-apple-ios".to_string()
- } else if os == "uefi" {
- // Override the UEFI LLVM targets.
- //
- // The rustc mappings (as of 1.82) for the UEFI targets are:
- // * i686-unknown-uefi -> i686-unknown-windows-gnu
- // * x86_64-unknown-uefi -> x86_64-unknown-windows
- // * aarch64-unknown-uefi -> aarch64-unknown-windows
- //
- // However, in cc-rs all the UEFI targets use
- // -windows-gnu. This has been the case since 2021 [1].
- // * i686-unknown-uefi -> i686-unknown-windows-gnu
- // * x86_64-unknown-uefi -> x86_64-unknown-windows-gnu
- // * aarch64-unknown-uefi -> aarch64-unknown-windows-gnu
- //
- // For now, override the UEFI mapping to keep the behavior
- // of cc-rs unchanged.
- //
- // TODO: as discussed in [2], it may be possible to switch
- // to new UEFI targets added to clang, and regardless it
- // would be good to have consistency between rustc and
- // cc-rs.
- //
- // [1]: https://github.com/rust-lang/cc-rs/pull/623
- // [2]: https://github.com/rust-lang/cc-rs/pull/1264
- let arch = if spec.arch == "x86" {
- "i686"
- } else {
- &spec.arch
- };
- format!("{}-unknown-windows-gnu", arch)
- } else {
- spec.llvm_target.clone()
- };
-
- writeln!(f, " (")?;
- writeln!(f, " {triple:?},")?;
- writeln!(f, " TargetInfo {{")?;
- writeln!(f, " full_arch: {full_arch:?},")?;
- writeln!(f, " arch: {arch:?},")?;
- writeln!(f, " vendor: {vendor:?},")?;
- writeln!(f, " os: {os:?},")?;
- writeln!(f, " env: {env:?},")?;
- writeln!(f, " abi: {abi:?},")?;
- writeln!(f, " llvm_target: {llvm_target:?},")?;
- writeln!(f, " }},")?;
- writeln!(f, " ),")?;
+ for (target_name, spec) in &target_specs.0 {
+ writeln!(f, " ({target_name:?}, {:?}),", spec.llvm_target)?;
}
writeln!(f, "];")?;
@@ -92,13 +34,13 @@ fn main() {
.unwrap()
!= 0
{
- for target_triple in get_targets_msrv().lines() {
- let target_triple = target_triple.unwrap();
- let target_triple = target_triple.trim();
+ for target_name in get_targets_msrv().lines() {
+ let target_name = target_name.unwrap();
+ let target_name = target_name.trim();
target_specs
.0
- .entry(target_triple.to_string())
- .or_insert_with(|| get_target_spec_from_msrv(target_triple));
+ .entry(target_name.to_string())
+ .or_insert_with(|| get_target_spec_from_msrv(target_name));
}
}
diff --git a/dev-tools/gen-target-info/src/write.rs b/dev-tools/gen-target-info/src/write.rs
deleted file mode 100644
index 5ea545e6..00000000
--- a/dev-tools/gen-target-info/src/write.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-use std::{collections::BTreeMap, fmt::Write as _, fs, io::Write as _};
-
-pub fn write_target_tuple_mapping(
- f: &mut fs::File,
- variable_name: &str,
- data: &BTreeMap<&str, &str>,
-) {
- let mut content = format!("pub const {variable_name}: &[(&str, &str)] = &[\n");
-
- for (f1, f2) in data {
- write!(&mut content, r#" ("{f1}", "{f2}"),"#).unwrap();
- content.push('\n');
- }
-
- content.push_str("];\n");
-
- f.write_all(content.as_bytes()).unwrap();
-}
diff --git a/src/lib.rs b/src/lib.rs
index ded30395..343fa332 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -145,11 +145,11 @@
//!
//! * Unix platforms require `cc` to be the C compiler. This can be found by
//! installing cc/clang on Linux distributions and Xcode on macOS, for example.
-//! * Windows platforms targeting MSVC (e.g. your target triple ends in `-msvc`)
+//! * Windows platforms targeting MSVC (e.g. your target name ends in `-msvc`)
//! require Visual Studio to be installed. `cc-rs` attempts to locate it, and
//! if it fails, `cl.exe` is expected to be available in `PATH`. This can be
//! set up by running the appropriate developer tools shell.
-//! * Windows platforms targeting MinGW (e.g. your target triple ends in `-gnu`)
+//! * Windows platforms targeting MinGW (e.g. your target name ends in `-gnu`)
//! require `cc` to be available in `PATH`. We recommend the
//! [MinGW-w64](https://www.mingw-w64.org/) distribution.
//! You may also acquire it via
@@ -2169,9 +2169,9 @@ impl Build {
// libstdc++ (this behavior was changed in llvm 14).
//
// This breaks C++11 (or greater) builds if targeting FreeBSD with the
- // generic xxx-unknown-freebsd triple on clang 13 or below *without*
+ // generic xxx-unknown-freebsd target on clang 13 or below *without*
// explicitly specifying that libc++ should be used.
- // When cross-compiling, we can't infer from the rust/cargo target triple
+ // When cross-compiling, we can't infer from the rust/cargo target name
// which major version of FreeBSD we are targeting, so we need to make sure
// that libc++ is used (unless the user has explicitly specified otherwise).
// There's no compelling reason to use a different approach when compiling
@@ -2202,14 +2202,14 @@ impl Build {
// So instead, we pass the deployment target with `-m*-version-min=`, and only
// pass it here on visionOS and Mac Catalyst where that option does not exist:
// https://github.com/rust-lang/cc-rs/issues/1383
- let clang_target = if target.os == "visionos" || target.abi == "macabi" {
- Cow::Owned(
- target.versioned_llvm_target(&self.apple_deployment_target(target)),
- )
+ let version = if target.os == "visionos" || target.abi == "macabi" {
+ Some(self.apple_deployment_target(target))
} else {
- Cow::Borrowed(target.llvm_target)
+ None
};
+ let clang_target =
+ target.llvm_target(&self.get_raw_target()?, version.as_deref());
cmd.push_cc_arg(format!("--target={clang_target}").into());
}
}
@@ -2235,7 +2235,13 @@ impl Build {
//