]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/apple_base.rs
Don't default on std crate when manipulating browser history
[rust.git] / src / librustc_target / spec / apple_base.rs
1 use std::env;
2
3 use 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 deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
18     let version = deployment_target.as_ref().and_then(|s| {
19         let mut i = s.splitn(2, '.');
20         i.next().and_then(|a| i.next().map(|b| (a, b)))
21     }).and_then(|(a, b)| {
22         a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok()
23     }).unwrap_or((10, 7));
24
25     TargetOptions {
26         // macOS has -dead_strip, which doesn't rely on function_sections
27         function_sections: false,
28         dynamic_linking: true,
29         executables: true,
30         target_family: Some("unix".to_string()),
31         is_like_osx: true,
32         has_rpath: true,
33         dll_prefix: "lib".to_string(),
34         dll_suffix: ".dylib".to_string(),
35         archive_format: "bsd".to_string(),
36         pre_link_args: LinkArgs::new(),
37         has_elf_tls: version >= (10, 7),
38         abi_return_struct_as_int: true,
39         emit_debug_gdb_scripts: false,
40         .. Default::default()
41     }
42 }