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.
12 use std::process::Command;
13 use spec::{LinkArgs, LinkerFlavor, TargetOptions};
17 #[allow(non_camel_case_types)]
18 #[derive(Copy, Clone)]
28 pub fn to_string(&self) -> &'static str {
39 pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
40 let res = Command::new("xcrun")
41 .arg("--show-sdk-path")
46 if output.status.success() {
47 Ok(String::from_utf8(output.stdout).unwrap())
49 let error = String::from_utf8(output.stderr);
50 let error = format!("process exit with error: {}",
52 Err(io::Error::new(io::ErrorKind::Other,
58 Ok(output) => Ok(output.trim().to_string()),
59 Err(e) => Err(format!("failed to get {} SDK path: {}", sdk_name, e))
63 fn build_pre_link_args(arch: Arch) -> Result<LinkArgs, String> {
64 let sdk_name = match arch {
65 Armv7 | Armv7s | Arm64 => "iphoneos",
66 I386 | X86_64 => "iphonesimulator"
69 let arch_name = arch.to_string();
71 let sdk_root = get_sdk_root(sdk_name)?;
73 let mut args = LinkArgs::new();
74 args.insert(LinkerFlavor::Gcc,
75 vec!["-arch".to_string(),
76 arch_name.to_string(),
77 "-Wl,-syslibroot".to_string(),
83 fn target_cpu(arch: Arch) -> String {
85 Armv7 => "cortex-a8", // iOS7 is supported on iPhone 4 and higher
86 Armv7s => "cortex-a9",
93 pub fn opts(arch: Arch) -> Result<TargetOptions, String> {
94 let pre_link_args = build_pre_link_args(arch)?;
96 cpu: target_cpu(arch),
97 dynamic_linking: false,
101 // The following line is a workaround for jemalloc 4.5 being broken on
102 // ios. jemalloc 5.0 is supposed to fix this.
103 // see https://github.com/rust-lang/rust/issues/45262
104 exe_allocation_crate: None,
105 .. super::apple_base::opts()