Skip to content

Commit 1fb91dc

Browse files
committed
iOS: updated targets
- target_word_size -> target_pointer_width - added armv7 and armv7s targets - enabled building binaries so tests could be run on a jailbroken device
1 parent 5b3cd39 commit 1fb91dc

File tree

6 files changed

+152
-42
lines changed

6 files changed

+152
-42
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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::{Command, IoError, OtherIoError};
12+
use target::TargetOptions;
13+
14+
use self::Arch::*;
15+
16+
#[allow(non_camel_case_types)]
17+
pub enum Arch {
18+
Armv7,
19+
Armv7s,
20+
Arm64,
21+
I386,
22+
X86_64
23+
}
24+
25+
impl Arch {
26+
pub fn to_string(&self) -> &'static str {
27+
match self {
28+
&Armv7 => "armv7",
29+
&Armv7s => "armv7s",
30+
&Arm64 => "arm64",
31+
&I386 => "i386",
32+
&X86_64 => "x86_64"
33+
}
34+
}
35+
}
36+
37+
pub fn get_sdk_root(sdk_name: &str) -> String {
38+
let res = Command::new("xcrun")
39+
.arg("--show-sdk-path")
40+
.arg("-sdk")
41+
.arg(sdk_name)
42+
.spawn()
43+
.and_then(|c| c.wait_with_output())
44+
.and_then(|output| {
45+
if output.status.success() {
46+
Ok(String::from_utf8(output.output).unwrap())
47+
} else {
48+
Err(IoError {
49+
kind: OtherIoError,
50+
desc: "process exit with error",
51+
detail: String::from_utf8(output.error).ok()})
52+
}
53+
});
54+
55+
match res {
56+
Ok(output) => output.trim().to_string(),
57+
Err(e) => panic!("failed to get {} SDK path: {}", sdk_name, e)
58+
}
59+
}
60+
61+
fn pre_link_args(arch: Arch) -> Vec<String> {
62+
let sdk_name = match arch {
63+
Armv7 | Armv7s | Arm64 => "iphoneos",
64+
I386 | X86_64 => "iphonesimulator"
65+
};
66+
67+
let arch_name = arch.to_string();
68+
69+
vec!["-arch".to_string(), arch_name.to_string(),
70+
"-Wl,-syslibroot".to_string(), get_sdk_root(sdk_name)]
71+
}
72+
73+
pub fn opts(arch: Arch) -> TargetOptions {
74+
TargetOptions {
75+
dynamic_linking: false,
76+
executables: true,
77+
// Although there is an experimental implementation of LLVM which
78+
// supports SS on armv7 it wasn't approved by Apple, see:
79+
// http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140505/216350.html
80+
// It looks like it might be never accepted to upstream LLVM.
81+
//
82+
// SS might be also enabled on Arm64 as it has builtin support in LLVM
83+
// but I haven't tested it through yet
84+
morestack: false,
85+
pre_link_args: pre_link_args(arch),
86+
.. super::apple_base::opts()
87+
}
88+
}

src/librustc_back/target/arm_apple_ios.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 target::{Target, TargetOptions};
12+
use super::apple_ios_base::{opts, Arch};
13+
14+
pub fn target() -> Target {
15+
Target {
16+
data_layout: "e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(),
17+
llvm_target: "armv7-apple-ios".to_string(),
18+
target_endian: "little".to_string(),
19+
target_pointer_width: "32".to_string(),
20+
arch: "arm".to_string(),
21+
target_os: "ios".to_string(),
22+
options: TargetOptions {
23+
features: "+v7,+vfp3,+neon".to_string(),
24+
.. opts(Arch::Armv7)
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 target::{Target, TargetOptions};
12+
use super::apple_ios_base::{opts, Arch};
13+
14+
pub fn target() -> Target {
15+
Target {
16+
data_layout: "e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(),
17+
llvm_target: "armv7s-apple-ios".to_string(),
18+
target_endian: "little".to_string(),
19+
target_pointer_width: "32".to_string(),
20+
arch: "arm".to_string(),
21+
target_os: "ios".to_string(),
22+
options: TargetOptions {
23+
features: "+v7,+vfp4,+neon".to_string(),
24+
.. opts(Arch::Armv7s)
25+
}
26+
}
27+
}

src/librustc_back/target/i386_apple_ios.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use target::Target;
12+
use super::apple_ios_base::{opts, Arch};
1213

1314
pub fn target() -> Target {
1415
Target {
@@ -22,7 +23,6 @@ pub fn target() -> Target {
2223
target_pointer_width: "32".to_string(),
2324
arch: "x86".to_string(),
2425
target_os: "ios".to_string(),
25-
26-
options: super::apple_base::opts()
26+
options: opts(Arch::I386)
2727
}
2828
}

src/librustc_back/target/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ use std::io::fs::PathExtensions;
5353
mod windows_base;
5454
mod linux_base;
5555
mod apple_base;
56+
mod apple_ios_base;
5657
mod freebsd_base;
5758
mod dragonfly_base;
5859

59-
mod arm_apple_ios;
60+
mod armv7_apple_ios;
61+
mod armv7s_apple_ios;
62+
mod i386_apple_ios;
63+
6064
mod arm_linux_androideabi;
6165
mod arm_unknown_linux_gnueabi;
6266
mod arm_unknown_linux_gnueabihf;
6367
mod aarch64_unknown_linux_gnu;
6468
mod i686_apple_darwin;
65-
mod i386_apple_ios;
6669
mod i686_pc_windows_gnu;
6770
mod i686_unknown_dragonfly;
6871
mod i686_unknown_linux_gnu;
@@ -346,8 +349,10 @@ impl Target {
346349

347350
x86_64_apple_darwin,
348351
i686_apple_darwin,
352+
349353
i386_apple_ios,
350-
arm_apple_ios,
354+
armv7_apple_ios,
355+
armv7s_apple_ios,
351356

352357
x86_64_pc_windows_gnu,
353358
i686_pc_windows_gnu

0 commit comments

Comments
 (0)