]> git.proxmox.com Git - rustc.git/blob - src/librustc_back/target/apple_ios_base.rs
Imported Upstream version 1.7.0+dfsg1
[rustc.git] / src / librustc_back / target / apple_ios_base.rs
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.
4 //
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.
10
11 use std::io;
12 use std::process::Command;
13 use target::TargetOptions;
14
15 use self::Arch::*;
16
17 #[allow(non_camel_case_types)]
18 #[derive(Copy, Clone)]
19 pub enum Arch {
20 Armv7,
21 Armv7s,
22 Arm64,
23 I386,
24 X86_64
25 }
26
27 impl Arch {
28 pub fn to_string(&self) -> &'static str {
29 match self {
30 &Armv7 => "armv7",
31 &Armv7s => "armv7s",
32 &Arm64 => "arm64",
33 &I386 => "i386",
34 &X86_64 => "x86_64"
35 }
36 }
37 }
38
39 pub fn get_sdk_root(sdk_name: &str) -> String {
40 let res = Command::new("xcrun")
41 .arg("--show-sdk-path")
42 .arg("-sdk")
43 .arg(sdk_name)
44 .output()
45 .and_then(|output| {
46 if output.status.success() {
47 Ok(String::from_utf8(output.stdout).unwrap())
48 } else {
49 let error = String::from_utf8(output.stderr);
50 let error = format!("process exit with error: {}",
51 error.unwrap());
52 Err(io::Error::new(io::ErrorKind::Other,
53 &error[..]))
54 }
55 });
56
57 match res {
58 Ok(output) => output.trim().to_string(),
59 Err(e) => panic!("failed to get {} SDK path: {}", sdk_name, e)
60 }
61 }
62
63 fn pre_link_args(arch: Arch) -> Vec<String> {
64 let sdk_name = match arch {
65 Armv7 | Armv7s | Arm64 => "iphoneos",
66 I386 | X86_64 => "iphonesimulator"
67 };
68
69 let arch_name = arch.to_string();
70
71 vec!["-arch".to_string(), arch_name.to_string(),
72 "-Wl,-syslibroot".to_string(), get_sdk_root(sdk_name)]
73 }
74
75 fn target_cpu(arch: Arch) -> String {
76 match arch {
77 Armv7 => "cortex-a8", // iOS7 is supported on iPhone 4 and higher
78 Armv7s => "cortex-a9",
79 Arm64 => "cyclone",
80 I386 => "yonah",
81 X86_64 => "core2",
82 }.to_string()
83 }
84
85 pub fn opts(arch: Arch) -> TargetOptions {
86 TargetOptions {
87 cpu: target_cpu(arch),
88 dynamic_linking: false,
89 executables: true,
90 pre_link_args: pre_link_args(arch),
91 has_elf_tls: false,
92 .. super::apple_base::opts()
93 }
94 }