]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/apple_base.rs
Rollup merge of #61675 - fintelia:riscv-frame-pointer, r=nagisa
[rust.git] / src / librustc_target / spec / apple_base.rs
1 use std::env;
2
3 use crate::spec::{LinkArgs, TargetOptions};
4
5 pub fn opts() -> TargetOptions {
6     // ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
7     // either the linker will complain if it is used or the binary will end up
8     // segfaulting at runtime when run on 10.6. Rust by default supports macOS
9     // 10.7+, but there is a standard environment variable,
10     // MACOSX_DEPLOYMENT_TARGET, which is used to signal targeting older
11     // versions of macOS. For example compiling on 10.10 with
12     // MACOSX_DEPLOYMENT_TARGET set to 10.6 will cause the linker to generate
13     // warnings about the usage of ELF TLS.
14     //
15     // Here we detect what version is being requested, defaulting to 10.7. ELF
16     // TLS is flagged as enabled if it looks to be supported.
17     let version = macos_deployment_target();
18
19     TargetOptions {
20         // macOS has -dead_strip, which doesn't rely on function_sections
21         function_sections: false,
22         dynamic_linking: true,
23         executables: true,
24         target_family: Some("unix".to_string()),
25         is_like_osx: true,
26         has_rpath: true,
27         dll_prefix: "lib".to_string(),
28         dll_suffix: ".dylib".to_string(),
29         archive_format: "bsd".to_string(),
30         pre_link_args: LinkArgs::new(),
31         has_elf_tls: version >= (10, 7),
32         abi_return_struct_as_int: true,
33         emit_debug_gdb_scripts: false,
34         .. Default::default()
35     }
36 }
37
38 fn macos_deployment_target() -> (u32, u32) {
39     let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
40     let version = deployment_target.as_ref().and_then(|s| {
41         let mut i = s.splitn(2, '.');
42         i.next().and_then(|a| i.next().map(|b| (a, b)))
43     }).and_then(|(a, b)| {
44         a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok()
45     });
46
47     version.unwrap_or((10, 7))
48 }
49
50 pub fn macos_llvm_target(arch: &str) -> String {
51     let (major, minor) = macos_deployment_target();
52     format!("{}-apple-macosx{}.{}.0", arch, major, minor)
53 }