From 1fb91dc1c2a34e5cbe384493616254253c821e41 Mon Sep 17 00:00:00 2001 From: Valerii Hiora Date: Thu, 8 Jan 2015 10:19:52 +0200 Subject: [PATCH] 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 --- src/librustc_back/target/apple_ios_base.rs | 88 ++++++++++++++++++++ src/librustc_back/target/arm_apple_ios.rs | 37 -------- src/librustc_back/target/armv7_apple_ios.rs | 27 ++++++ src/librustc_back/target/armv7s_apple_ios.rs | 27 ++++++ src/librustc_back/target/i386_apple_ios.rs | 4 +- src/librustc_back/target/mod.rs | 11 ++- 6 files changed, 152 insertions(+), 42 deletions(-) create mode 100644 src/librustc_back/target/apple_ios_base.rs delete mode 100644 src/librustc_back/target/arm_apple_ios.rs create mode 100644 src/librustc_back/target/armv7_apple_ios.rs create mode 100644 src/librustc_back/target/armv7s_apple_ios.rs diff --git a/src/librustc_back/target/apple_ios_base.rs b/src/librustc_back/target/apple_ios_base.rs new file mode 100644 index 000000000000..f9dcb4fb8123 --- /dev/null +++ b/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 or the MIT license +// , 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 { + 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() + } +} diff --git a/src/librustc_back/target/arm_apple_ios.rs b/src/librustc_back/target/arm_apple_ios.rs deleted file mode 100644 index e0afef6e3904..000000000000 --- a/src/librustc_back/target/arm_apple_ios.rs +++ /dev/null @@ -1,37 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use target::{Target, TargetOptions}; - -pub fn target() -> Target { - Target { - data_layout: "e-p:32:32:32\ - -i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64\ - -f32:32:32-f64:64:64\ - -v64:64:64-v128:64:128\ - -a:0:64-n32".to_string(), - llvm_target: "arm-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,+thumb2,+vfp3,+neon".to_string(), - executables: false, - dynamic_linking: false, - // 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. - morestack: false, - .. super::apple_base::opts() - } - } -} diff --git a/src/librustc_back/target/armv7_apple_ios.rs b/src/librustc_back/target/armv7_apple_ios.rs new file mode 100644 index 000000000000..413764218869 --- /dev/null +++ b/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 or the MIT license +// , 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) + } + } +} diff --git a/src/librustc_back/target/armv7s_apple_ios.rs b/src/librustc_back/target/armv7s_apple_ios.rs new file mode 100644 index 000000000000..ef16aefdbd9d --- /dev/null +++ b/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 or the MIT license +// , 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) + } + } +} diff --git a/src/librustc_back/target/i386_apple_ios.rs b/src/librustc_back/target/i386_apple_ios.rs index a1fcc9ac53fb..afe63d006cf1 100644 --- a/src/librustc_back/target/i386_apple_ios.rs +++ b/src/librustc_back/target/i386_apple_ios.rs @@ -9,6 +9,7 @@ // except according to those terms. use target::Target; +use super::apple_ios_base::{opts, Arch}; pub fn target() -> Target { Target { @@ -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) } } diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 069e798887b9..b4a9a3c5f41b 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -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; @@ -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