1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 use target::TargetOptions;
15 pub fn opts() -> TargetOptions {
16 // ELF TLS is only available in OSX 10.7+. If you try to compile for 10.6
17 // either the linker will complain if it is used or the binary will end up
18 // segfaulting at runtime when run on 10.6. Rust by default supports OSX
19 // 10.7+, but there is a standard environment variable,
20 // MACOSX_DEPLOYMENT_TARGET, which is used to signal targeting older
21 // versions of OSX. For example compiling on 10.10 with
22 // MACOSX_DEPLOYMENT_TARGET set to 10.6 will cause the linker to generate
23 // warnings about the usage of ELF TLS.
25 // Here we detect what version is being requested, defaulting to 10.7. ELF
26 // TLS is flagged as enabled if it looks to be supported.
27 let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
28 let version = deployment_target.as_ref().and_then(|s| {
29 let mut i = s.splitn(2, ".");
30 i.next().and_then(|a| i.next().map(|b| (a, b)))
31 }).and_then(|(a, b)| {
32 a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok()
33 }).unwrap_or((10, 7));
36 // OSX has -dead_strip, which doesn't rely on ffunction_sections
37 function_sections: false,
38 linker: "cc".to_string(),
39 dynamic_linking: true,
43 dll_prefix: "lib".to_string(),
44 dll_suffix: ".dylib".to_string(),
45 archive_format: "bsd".to_string(),
46 pre_link_args: Vec::new(),
47 exe_allocation_crate: super::maybe_jemalloc(),
48 has_elf_tls: version >= (10, 7),