X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_target%2Fsrc%2Fspec%2Fapple_base.rs;h=ba8f9a8ce11607fcc04629a97b9ccf45e0aaabda;hb=b376f5621b801460b911a75048a70698021bbc69;hp=a21b784e11b1ca4578c3dd7454704e87720e0e1e;hpb=e4d257e1d359cb0ec25f7a38964eef8a19d7ae71;p=rust.git diff --git a/compiler/rustc_target/src/spec/apple_base.rs b/compiler/rustc_target/src/spec/apple_base.rs index a21b784e11b..ba8f9a8ce11 100644 --- a/compiler/rustc_target/src/spec/apple_base.rs +++ b/compiler/rustc_target/src/spec/apple_base.rs @@ -13,8 +13,10 @@ pub fn opts(os: &str) -> TargetOptions { // warnings about the usage of ELF TLS. // // Here we detect what version is being requested, defaulting to 10.7. ELF - // TLS is flagged as enabled if it looks to be supported. - let version = macos_deployment_target(); + // TLS is flagged as enabled if it looks to be supported. The architecture + // only matters for default deployment target which is 11.0 for ARM64 and + // 10.7 for everything else. + let has_elf_tls = macos_deployment_target("x86_64") >= (10, 7); TargetOptions { os: os.to_string(), @@ -31,7 +33,7 @@ pub fn opts(os: &str) -> TargetOptions { has_rpath: true, dll_suffix: ".dylib".to_string(), archive_format: "darwin".to_string(), - has_elf_tls: version >= (10, 7), + has_elf_tls, abi_return_struct_as_int: true, emit_debug_gdb_scripts: false, eh_frame_header: false, @@ -63,15 +65,32 @@ fn deployment_target(var_name: &str) -> Option<(u32, u32)> { .and_then(|(a, b)| a.parse::().and_then(|a| b.parse::().map(|b| (a, b))).ok()) } -fn macos_deployment_target() -> (u32, u32) { - deployment_target("MACOSX_DEPLOYMENT_TARGET").unwrap_or((10, 7)) +fn macos_default_deployment_target(arch: &str) -> (u32, u32) { + if arch == "arm64" { (11, 0) } else { (10, 7) } +} + +fn macos_deployment_target(arch: &str) -> (u32, u32) { + deployment_target("MACOSX_DEPLOYMENT_TARGET") + .unwrap_or_else(|| macos_default_deployment_target(arch)) } pub fn macos_llvm_target(arch: &str) -> String { - let (major, minor) = macos_deployment_target(); + let (major, minor) = macos_deployment_target(arch); format!("{}-apple-macosx{}.{}.0", arch, major, minor) } +pub fn macos_link_env(arch: &str) -> Vec<(String, String)> { + // Use the default deployment target for linking just as with the LLVM target if not + // specified via MACOSX_DEPLOYMENT_TARGET, otherwise the system linker would use its + // default which varies with Xcode version. + if env::var("MACOSX_DEPLOYMENT_TARGET").is_err() { + let default = macos_default_deployment_target(arch); + vec![("MACOSX_DEPLOYMENT_TARGET".to_string(), format!("{}.{}", default.0, default.1))] + } else { + vec![] + } +} + pub fn macos_link_env_remove() -> Vec { let mut env_remove = Vec::with_capacity(2); // Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which