Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert built-in targets to JSON #34980

Merged
merged 5 commits into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/librustc_back/target/aarch64_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

pub fn target() -> Target {
Target {
pub fn target() -> TargetResult {
let base = try!(opts(Arch::Arm64));
Ok(Target {
llvm_target: "arm64-apple-ios".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
Expand All @@ -25,7 +26,7 @@ pub fn target() -> Target {
features: "+neon,+fp-armv8,+cyclone".to_string(),
eliminate_frame_pointer: false,
max_atomic_width: 128,
.. opts(Arch::Arm64)
.. base
},
}
})
}
8 changes: 4 additions & 4 deletions src/librustc_back/target/aarch64_linux_android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::Target;
use target::{Target, TargetResult};

pub fn target() -> Target {
pub fn target() -> TargetResult {
let mut base = super::android_base::opts();
base.max_atomic_width = 128;
// As documented in http://developer.android.com/ndk/guides/cpu-features.html
// the neon (ASIMD) and FP must exist on all android aarch64 targets.
base.features = "+neon,+fp-armv8".to_string();
Target {
Ok(Target {
llvm_target: "aarch64-linux-android".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
Expand All @@ -26,5 +26,5 @@ pub fn target() -> Target {
target_env: "".to_string(),
target_vendor: "unknown".to_string(),
options: base,
}
})
}
8 changes: 4 additions & 4 deletions src/librustc_back/target/aarch64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::Target;
use target::{Target, TargetResult};

pub fn target() -> Target {
pub fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.max_atomic_width = 128;
Target {
Ok(Target {
llvm_target: "aarch64-unknown-linux-gnu".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
Expand All @@ -23,5 +23,5 @@ pub fn target() -> Target {
target_os: "linux".to_string(),
target_vendor: "unknown".to_string(),
options: base,
}
})
}
23 changes: 13 additions & 10 deletions src/librustc_back/target/apple_ios_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Arch {
}
}

pub fn get_sdk_root(sdk_name: &str) -> String {
pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
let res = Command::new("xcrun")
.arg("--show-sdk-path")
.arg("-sdk")
Expand All @@ -55,21 +55,23 @@ pub fn get_sdk_root(sdk_name: &str) -> String {
});

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

fn pre_link_args(arch: Arch) -> Vec<String> {
fn build_pre_link_args(arch: Arch) -> Result<Vec<String>, 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)]
let sdk_root = try!(get_sdk_root(sdk_name));

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

fn target_cpu(arch: Arch) -> String {
Expand All @@ -82,13 +84,14 @@ fn target_cpu(arch: Arch) -> String {
}.to_string()
}

pub fn opts(arch: Arch) -> TargetOptions {
TargetOptions {
pub fn opts(arch: Arch) -> Result<TargetOptions, String> {
let pre_link_args = try!(build_pre_link_args(arch));
Ok(TargetOptions {
cpu: target_cpu(arch),
dynamic_linking: false,
executables: true,
pre_link_args: pre_link_args(arch),
pre_link_args: pre_link_args,
has_elf_tls: false,
.. super::apple_base::opts()
}
})
}
8 changes: 4 additions & 4 deletions src/librustc_back/target/arm_linux_androideabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::Target;
use target::{Target, TargetResult};

pub fn target() -> Target {
pub fn target() -> TargetResult {
let mut base = super::android_base::opts();
base.features = "+v7,+vfp3,+d16".to_string();
base.max_atomic_width = 64;

Target {
Ok(Target {
llvm_target: "arm-linux-androideabi".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
Expand All @@ -25,5 +25,5 @@ pub fn target() -> Target {
target_env: "".to_string(),
target_vendor: "unknown".to_string(),
options: base,
}
})
}
8 changes: 4 additions & 4 deletions src/librustc_back/target/arm_unknown_linux_gnueabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::{Target, TargetOptions};
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> Target {
pub fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.max_atomic_width = 64;
Target {
Ok(Target {
llvm_target: "arm-unknown-linux-gnueabi".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
Expand All @@ -27,5 +27,5 @@ pub fn target() -> Target {
features: "+v6".to_string(),
.. base
},
}
})
}
8 changes: 4 additions & 4 deletions src/librustc_back/target/arm_unknown_linux_gnueabihf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::{Target, TargetOptions};
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> Target {
pub fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.max_atomic_width = 64;
Target {
Ok(Target {
llvm_target: "arm-unknown-linux-gnueabihf".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
Expand All @@ -27,5 +27,5 @@ pub fn target() -> Target {
features: "+v6,+vfp2".to_string(),
.. base
}
}
})
}
11 changes: 6 additions & 5 deletions src/librustc_back/target/armv7_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

pub fn target() -> Target {
Target {
pub fn target() -> TargetResult {
let base = try!(opts(Arch::Armv7));
Ok(Target {
llvm_target: "armv7-apple-ios".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
Expand All @@ -24,7 +25,7 @@ pub fn target() -> Target {
options: TargetOptions {
features: "+v7,+vfp3,+neon".to_string(),
max_atomic_width: 64,
.. opts(Arch::Armv7)
.. base
}
}
})
}
8 changes: 4 additions & 4 deletions src/librustc_back/target/armv7_linux_androideabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::Target;
use target::{Target, TargetResult};

pub fn target() -> Target {
pub fn target() -> TargetResult {
let mut base = super::android_base::opts();
base.features = "+v7,+thumb2,+vfp3,+d16".to_string();
base.max_atomic_width = 64;

Target {
Ok(Target {
llvm_target: "armv7-none-linux-android".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
Expand All @@ -25,5 +25,5 @@ pub fn target() -> Target {
target_env: "".to_string(),
target_vendor: "unknown".to_string(),
options: base,
}
})
}
8 changes: 4 additions & 4 deletions src/librustc_back/target/armv7_unknown_linux_gnueabihf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::{Target, TargetOptions};
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> Target {
pub fn target() -> TargetResult {
let base = super::linux_base::opts();
Target {
Ok(Target {
llvm_target: "armv7-unknown-linux-gnueabihf".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
Expand All @@ -28,6 +28,6 @@ pub fn target() -> Target {
max_atomic_width: 64,
.. base
}
}
})
}

11 changes: 6 additions & 5 deletions src/librustc_back/target/armv7s_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

pub fn target() -> Target {
Target {
pub fn target() -> TargetResult {
let base = try!(opts(Arch::Armv7s));
Ok(Target {
llvm_target: "armv7s-apple-ios".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
Expand All @@ -24,7 +25,7 @@ pub fn target() -> Target {
options: TargetOptions {
features: "+v7,+vfp4,+neon".to_string(),
max_atomic_width: 64,
.. opts(Arch::Armv7s)
.. base
}
}
})
}
6 changes: 3 additions & 3 deletions src/librustc_back/target/asmjs_unknown_emscripten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use super::{Target, TargetOptions};

pub fn target() -> Target {
pub fn target() -> Result<Target, String> {
let opts = TargetOptions {
linker: "emcc".to_string(),
ar: "emar".to_string(),
Expand All @@ -25,7 +25,7 @@ pub fn target() -> Target {
max_atomic_width: 32,
.. Default::default()
};
Target {
Ok(Target {
llvm_target: "asmjs-unknown-emscripten".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
Expand All @@ -35,5 +35,5 @@ pub fn target() -> Target {
data_layout: "e-p:32:32-i64:64-v128:32:128-n32-S128".to_string(),
arch: "asmjs".to_string(),
options: opts,
}
})
}
11 changes: 6 additions & 5 deletions src/librustc_back/target/i386_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

pub fn target() -> Target {
Target {
pub fn target() -> TargetResult {
let base = try!(opts(Arch::I386));
Ok(Target {
llvm_target: "i386-apple-ios".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
Expand All @@ -23,7 +24,7 @@ pub fn target() -> Target {
target_vendor: "apple".to_string(),
options: TargetOptions {
max_atomic_width: 64,
.. opts(Arch::I386)
.. base
}
}
})
}
8 changes: 4 additions & 4 deletions src/librustc_back/target/i586_pc_windows_msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::Target;
use target::TargetResult;

pub fn target() -> Target {
let mut base = super::i686_pc_windows_msvc::target();
pub fn target() -> TargetResult {
let mut base = try!(super::i686_pc_windows_msvc::target());
base.options.cpu = "pentium".to_string();
base.llvm_target = "i586-pc-windows-msvc".to_string();
return base
Ok(base)
}
8 changes: 4 additions & 4 deletions src/librustc_back/target/i586_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::Target;
use target::TargetResult;

pub fn target() -> Target {
let mut base = super::i686_unknown_linux_gnu::target();
pub fn target() -> TargetResult {
let mut base = try!(super::i686_unknown_linux_gnu::target());
base.options.cpu = "pentium".to_string();
base.llvm_target = "i586-unknown-linux-gnu".to_string();
return base
Ok(base)
}
Loading