Skip to content

Commit 1523a54

Browse files
authored
Auto merge of #34980 - cardoe:expose-target-options, r=alexcrichton
Convert built-in targets to JSON Convert the built-in targets to JSON to ensure that the JSON parser is always fully featured. This follows on #32988 and #32847. The PR includes a number of extra commits that are just intermediate changes necessary for bisectibility and the ability to prove correctness of the change.
2 parents d9a911d + 54c61ff commit 1523a54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+368
-218
lines changed

src/librustc_back/target/aarch64_apple_ios.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::{Target, TargetOptions};
11+
use target::{Target, TargetOptions, TargetResult};
1212
use super::apple_ios_base::{opts, Arch};
1313

14-
pub fn target() -> Target {
15-
Target {
14+
pub fn target() -> TargetResult {
15+
let base = try!(opts(Arch::Arm64));
16+
Ok(Target {
1617
llvm_target: "arm64-apple-ios".to_string(),
1718
target_endian: "little".to_string(),
1819
target_pointer_width: "64".to_string(),
@@ -25,7 +26,7 @@ pub fn target() -> Target {
2526
features: "+neon,+fp-armv8,+cyclone".to_string(),
2627
eliminate_frame_pointer: false,
2728
max_atomic_width: 128,
28-
.. opts(Arch::Arm64)
29+
.. base
2930
},
30-
}
31+
})
3132
}

src/librustc_back/target/aarch64_linux_android.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::Target;
11+
use target::{Target, TargetResult};
1212

13-
pub fn target() -> Target {
13+
pub fn target() -> TargetResult {
1414
let mut base = super::android_base::opts();
1515
base.max_atomic_width = 128;
1616
// As documented in http://developer.android.com/ndk/guides/cpu-features.html
1717
// the neon (ASIMD) and FP must exist on all android aarch64 targets.
1818
base.features = "+neon,+fp-armv8".to_string();
19-
Target {
19+
Ok(Target {
2020
llvm_target: "aarch64-linux-android".to_string(),
2121
target_endian: "little".to_string(),
2222
target_pointer_width: "64".to_string(),
@@ -26,5 +26,5 @@ pub fn target() -> Target {
2626
target_env: "".to_string(),
2727
target_vendor: "unknown".to_string(),
2828
options: base,
29-
}
29+
})
3030
}

src/librustc_back/target/aarch64_unknown_linux_gnu.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::Target;
11+
use target::{Target, TargetResult};
1212

13-
pub fn target() -> Target {
13+
pub fn target() -> TargetResult {
1414
let mut base = super::linux_base::opts();
1515
base.max_atomic_width = 128;
16-
Target {
16+
Ok(Target {
1717
llvm_target: "aarch64-unknown-linux-gnu".to_string(),
1818
target_endian: "little".to_string(),
1919
target_pointer_width: "64".to_string(),
@@ -23,5 +23,5 @@ pub fn target() -> Target {
2323
target_os: "linux".to_string(),
2424
target_vendor: "unknown".to_string(),
2525
options: base,
26-
}
26+
})
2727
}

src/librustc_back/target/apple_ios_base.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Arch {
3636
}
3737
}
3838

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

5757
match res {
58-
Ok(output) => output.trim().to_string(),
59-
Err(e) => panic!("failed to get {} SDK path: {}", sdk_name, e)
58+
Ok(output) => Ok(output.trim().to_string()),
59+
Err(e) => Err(format!("failed to get {} SDK path: {}", sdk_name, e))
6060
}
6161
}
6262

63-
fn pre_link_args(arch: Arch) -> Vec<String> {
63+
fn build_pre_link_args(arch: Arch) -> Result<Vec<String>, String> {
6464
let sdk_name = match arch {
6565
Armv7 | Armv7s | Arm64 => "iphoneos",
6666
I386 | X86_64 => "iphonesimulator"
6767
};
6868

6969
let arch_name = arch.to_string();
7070

71-
vec!["-arch".to_string(), arch_name.to_string(),
72-
"-Wl,-syslibroot".to_string(), get_sdk_root(sdk_name)]
71+
let sdk_root = try!(get_sdk_root(sdk_name));
72+
73+
Ok(vec!["-arch".to_string(), arch_name.to_string(),
74+
"-Wl,-syslibroot".to_string(), sdk_root])
7375
}
7476

7577
fn target_cpu(arch: Arch) -> String {
@@ -82,13 +84,14 @@ fn target_cpu(arch: Arch) -> String {
8284
}.to_string()
8385
}
8486

85-
pub fn opts(arch: Arch) -> TargetOptions {
86-
TargetOptions {
87+
pub fn opts(arch: Arch) -> Result<TargetOptions, String> {
88+
let pre_link_args = try!(build_pre_link_args(arch));
89+
Ok(TargetOptions {
8790
cpu: target_cpu(arch),
8891
dynamic_linking: false,
8992
executables: true,
90-
pre_link_args: pre_link_args(arch),
93+
pre_link_args: pre_link_args,
9194
has_elf_tls: false,
9295
.. super::apple_base::opts()
93-
}
96+
})
9497
}

src/librustc_back/target/arm_linux_androideabi.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::Target;
11+
use target::{Target, TargetResult};
1212

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

18-
Target {
18+
Ok(Target {
1919
llvm_target: "arm-linux-androideabi".to_string(),
2020
target_endian: "little".to_string(),
2121
target_pointer_width: "32".to_string(),
@@ -25,5 +25,5 @@ pub fn target() -> Target {
2525
target_env: "".to_string(),
2626
target_vendor: "unknown".to_string(),
2727
options: base,
28-
}
28+
})
2929
}

src/librustc_back/target/arm_unknown_linux_gnueabi.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::{Target, TargetOptions};
11+
use target::{Target, TargetOptions, TargetResult};
1212

13-
pub fn target() -> Target {
13+
pub fn target() -> TargetResult {
1414
let mut base = super::linux_base::opts();
1515
base.max_atomic_width = 64;
16-
Target {
16+
Ok(Target {
1717
llvm_target: "arm-unknown-linux-gnueabi".to_string(),
1818
target_endian: "little".to_string(),
1919
target_pointer_width: "32".to_string(),
@@ -27,5 +27,5 @@ pub fn target() -> Target {
2727
features: "+v6".to_string(),
2828
.. base
2929
},
30-
}
30+
})
3131
}

src/librustc_back/target/arm_unknown_linux_gnueabihf.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::{Target, TargetOptions};
11+
use target::{Target, TargetOptions, TargetResult};
1212

13-
pub fn target() -> Target {
13+
pub fn target() -> TargetResult {
1414
let mut base = super::linux_base::opts();
1515
base.max_atomic_width = 64;
16-
Target {
16+
Ok(Target {
1717
llvm_target: "arm-unknown-linux-gnueabihf".to_string(),
1818
target_endian: "little".to_string(),
1919
target_pointer_width: "32".to_string(),
@@ -27,5 +27,5 @@ pub fn target() -> Target {
2727
features: "+v6,+vfp2".to_string(),
2828
.. base
2929
}
30-
}
30+
})
3131
}

src/librustc_back/target/armv7_apple_ios.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::{Target, TargetOptions};
11+
use target::{Target, TargetOptions, TargetResult};
1212
use super::apple_ios_base::{opts, Arch};
1313

14-
pub fn target() -> Target {
15-
Target {
14+
pub fn target() -> TargetResult {
15+
let base = try!(opts(Arch::Armv7));
16+
Ok(Target {
1617
llvm_target: "armv7-apple-ios".to_string(),
1718
target_endian: "little".to_string(),
1819
target_pointer_width: "32".to_string(),
@@ -24,7 +25,7 @@ pub fn target() -> Target {
2425
options: TargetOptions {
2526
features: "+v7,+vfp3,+neon".to_string(),
2627
max_atomic_width: 64,
27-
.. opts(Arch::Armv7)
28+
.. base
2829
}
29-
}
30+
})
3031
}

src/librustc_back/target/armv7_linux_androideabi.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::Target;
11+
use target::{Target, TargetResult};
1212

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

18-
Target {
18+
Ok(Target {
1919
llvm_target: "armv7-none-linux-android".to_string(),
2020
target_endian: "little".to_string(),
2121
target_pointer_width: "32".to_string(),
@@ -25,5 +25,5 @@ pub fn target() -> Target {
2525
target_env: "".to_string(),
2626
target_vendor: "unknown".to_string(),
2727
options: base,
28-
}
28+
})
2929
}

src/librustc_back/target/armv7_unknown_linux_gnueabihf.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::{Target, TargetOptions};
11+
use target::{Target, TargetOptions, TargetResult};
1212

13-
pub fn target() -> Target {
13+
pub fn target() -> TargetResult {
1414
let base = super::linux_base::opts();
15-
Target {
15+
Ok(Target {
1616
llvm_target: "armv7-unknown-linux-gnueabihf".to_string(),
1717
target_endian: "little".to_string(),
1818
target_pointer_width: "32".to_string(),
@@ -28,6 +28,6 @@ pub fn target() -> Target {
2828
max_atomic_width: 64,
2929
.. base
3030
}
31-
}
31+
})
3232
}
3333

src/librustc_back/target/armv7s_apple_ios.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::{Target, TargetOptions};
11+
use target::{Target, TargetOptions, TargetResult};
1212
use super::apple_ios_base::{opts, Arch};
1313

14-
pub fn target() -> Target {
15-
Target {
14+
pub fn target() -> TargetResult {
15+
let base = try!(opts(Arch::Armv7s));
16+
Ok(Target {
1617
llvm_target: "armv7s-apple-ios".to_string(),
1718
target_endian: "little".to_string(),
1819
target_pointer_width: "32".to_string(),
@@ -24,7 +25,7 @@ pub fn target() -> Target {
2425
options: TargetOptions {
2526
features: "+v7,+vfp4,+neon".to_string(),
2627
max_atomic_width: 64,
27-
.. opts(Arch::Armv7s)
28+
.. base
2829
}
29-
}
30+
})
3031
}

src/librustc_back/target/asmjs_unknown_emscripten.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use super::{Target, TargetOptions};
1212

13-
pub fn target() -> Target {
13+
pub fn target() -> Result<Target, String> {
1414
let opts = TargetOptions {
1515
linker: "emcc".to_string(),
1616
ar: "emar".to_string(),
@@ -25,7 +25,7 @@ pub fn target() -> Target {
2525
max_atomic_width: 32,
2626
.. Default::default()
2727
};
28-
Target {
28+
Ok(Target {
2929
llvm_target: "asmjs-unknown-emscripten".to_string(),
3030
target_endian: "little".to_string(),
3131
target_pointer_width: "32".to_string(),
@@ -35,5 +35,5 @@ pub fn target() -> Target {
3535
data_layout: "e-p:32:32-i64:64-v128:32:128-n32-S128".to_string(),
3636
arch: "asmjs".to_string(),
3737
options: opts,
38-
}
38+
})
3939
}

src/librustc_back/target/i386_apple_ios.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::{Target, TargetOptions};
11+
use target::{Target, TargetOptions, TargetResult};
1212
use super::apple_ios_base::{opts, Arch};
1313

14-
pub fn target() -> Target {
15-
Target {
14+
pub fn target() -> TargetResult {
15+
let base = try!(opts(Arch::I386));
16+
Ok(Target {
1617
llvm_target: "i386-apple-ios".to_string(),
1718
target_endian: "little".to_string(),
1819
target_pointer_width: "32".to_string(),
@@ -23,7 +24,7 @@ pub fn target() -> Target {
2324
target_vendor: "apple".to_string(),
2425
options: TargetOptions {
2526
max_atomic_width: 64,
26-
.. opts(Arch::I386)
27+
.. base
2728
}
28-
}
29+
})
2930
}

src/librustc_back/target/i586_pc_windows_msvc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::Target;
11+
use target::TargetResult;
1212

13-
pub fn target() -> Target {
14-
let mut base = super::i686_pc_windows_msvc::target();
13+
pub fn target() -> TargetResult {
14+
let mut base = try!(super::i686_pc_windows_msvc::target());
1515
base.options.cpu = "pentium".to_string();
1616
base.llvm_target = "i586-pc-windows-msvc".to_string();
17-
return base
17+
Ok(base)
1818
}

src/librustc_back/target/i586_unknown_linux_gnu.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use target::Target;
11+
use target::TargetResult;
1212

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

0 commit comments

Comments
 (0)