Skip to content

Commit

Permalink
iOS: updated targets
Browse files Browse the repository at this point in the history
- target_word_size -> target_pointer_width
- added armv7 and armv7s targets
- enabled building binaries so tests could be run on a jailbroken device
  • Loading branch information
vhbit committed Jan 9, 2015
1 parent 5b3cd39 commit 1fb91dc
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 42 deletions.
88 changes: 88 additions & 0 deletions src/librustc_back/target/apple_ios_base.rs
@@ -0,0 +1,88 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::io::{Command, IoError, OtherIoError};
use target::TargetOptions;

use self::Arch::*;

#[allow(non_camel_case_types)]
pub enum Arch {
Armv7,
Armv7s,
Arm64,
I386,
X86_64
}

impl Arch {
pub fn to_string(&self) -> &'static str {
match self {
&Armv7 => "armv7",
&Armv7s => "armv7s",
&Arm64 => "arm64",
&I386 => "i386",
&X86_64 => "x86_64"
}
}
}

pub fn get_sdk_root(sdk_name: &str) -> String {
let res = Command::new("xcrun")
.arg("--show-sdk-path")
.arg("-sdk")
.arg(sdk_name)
.spawn()
.and_then(|c| c.wait_with_output())
.and_then(|output| {
if output.status.success() {
Ok(String::from_utf8(output.output).unwrap())
} else {
Err(IoError {
kind: OtherIoError,
desc: "process exit with error",
detail: String::from_utf8(output.error).ok()})
}
});

match res {
Ok(output) => output.trim().to_string(),
Err(e) => panic!("failed to get {} SDK path: {}", sdk_name, e)
}
}

fn pre_link_args(arch: Arch) -> Vec<String> {
let sdk_name = match arch {
Armv7 | Armv7s | Arm64 => "iphoneos",
I386 | X86_64 => "iphonesimulator"
};

let arch_name = arch.to_string();

vec!["-arch".to_string(), arch_name.to_string(),
"-Wl,-syslibroot".to_string(), get_sdk_root(sdk_name)]
}

pub fn opts(arch: Arch) -> TargetOptions {
TargetOptions {
dynamic_linking: false,
executables: true,
// Although there is an experimental implementation of LLVM which
// supports SS on armv7 it wasn't approved by Apple, see:
// http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140505/216350.html
// It looks like it might be never accepted to upstream LLVM.
//
// SS might be also enabled on Arm64 as it has builtin support in LLVM
// but I haven't tested it through yet
morestack: false,
pre_link_args: pre_link_args(arch),
.. super::apple_base::opts()
}
}
37 changes: 0 additions & 37 deletions src/librustc_back/target/arm_apple_ios.rs

This file was deleted.

27 changes: 27 additions & 0 deletions src/librustc_back/target/armv7_apple_ios.rs
@@ -0,0 +1,27 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::{Target, TargetOptions};
use super::apple_ios_base::{opts, Arch};

pub fn target() -> Target {
Target {
data_layout: "e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(),
llvm_target: "armv7-apple-ios".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
arch: "arm".to_string(),
target_os: "ios".to_string(),
options: TargetOptions {
features: "+v7,+vfp3,+neon".to_string(),
.. opts(Arch::Armv7)
}
}
}
27 changes: 27 additions & 0 deletions src/librustc_back/target/armv7s_apple_ios.rs
@@ -0,0 +1,27 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::{Target, TargetOptions};
use super::apple_ios_base::{opts, Arch};

pub fn target() -> Target {
Target {
data_layout: "e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(),
llvm_target: "armv7s-apple-ios".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
arch: "arm".to_string(),
target_os: "ios".to_string(),
options: TargetOptions {
features: "+v7,+vfp4,+neon".to_string(),
.. opts(Arch::Armv7s)
}
}
}
4 changes: 2 additions & 2 deletions src/librustc_back/target/i386_apple_ios.rs
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use target::Target;
use super::apple_ios_base::{opts, Arch};

pub fn target() -> Target {
Target {
Expand All @@ -22,7 +23,6 @@ pub fn target() -> Target {
target_pointer_width: "32".to_string(),
arch: "x86".to_string(),
target_os: "ios".to_string(),

options: super::apple_base::opts()
options: opts(Arch::I386)
}
}
11 changes: 8 additions & 3 deletions src/librustc_back/target/mod.rs
Expand Up @@ -53,16 +53,19 @@ use std::io::fs::PathExtensions;
mod windows_base;
mod linux_base;
mod apple_base;
mod apple_ios_base;
mod freebsd_base;
mod dragonfly_base;

mod arm_apple_ios;
mod armv7_apple_ios;
mod armv7s_apple_ios;
mod i386_apple_ios;

mod arm_linux_androideabi;
mod arm_unknown_linux_gnueabi;
mod arm_unknown_linux_gnueabihf;
mod aarch64_unknown_linux_gnu;
mod i686_apple_darwin;
mod i386_apple_ios;
mod i686_pc_windows_gnu;
mod i686_unknown_dragonfly;
mod i686_unknown_linux_gnu;
Expand Down Expand Up @@ -346,8 +349,10 @@ impl Target {

x86_64_apple_darwin,
i686_apple_darwin,

i386_apple_ios,
arm_apple_ios,
armv7_apple_ios,
armv7s_apple_ios,

x86_64_pc_windows_gnu,
i686_pc_windows_gnu
Expand Down

0 comments on commit 1fb91dc

Please sign in to comment.