Skip to content

Commit 78ce46f

Browse files
committed
Auto merge of #28612 - gandro:targetvendor, r=alexcrichton
This adds a new target property, `target_vendor`. It is to be be used as a matcher for conditional compilation. The vendor is part of the [autoconf target triple](http://llvm.org/docs/doxygen/html/classllvm_1_1Triple.html#details): `<arch><sub>-<vendor>-<os>-<env>`. `arch`, `target_os` and `target_env` are already supported by Rust. This change was suggested in PR #28593. It enables conditional compilation based on the vendor. This is needed for the rumprun target, which needs to match against both, target_os and target_vendor. The default value for `target_vendor` is "unknown", "apple" and "pc" are other common values. Matching against the `target_vendor` is introduced behind the feature gate `#![feature(cfg_target_vendor)]`. This is the first time I messed around with rustc internals. I just added the my code where I found the existing `target_*` variables, hopefully I haven't missed anything. Please review with care. :) r? @alexcrichton
2 parents 69f27c8 + abfedb7 commit 78ce46f

36 files changed

+95
-3
lines changed

src/doc/reference.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,8 @@ The following configurations must be defined by the implementation:
20932093
* `target_pointer_width = "..."` - Target pointer width in bits. This is set
20942094
to `"32"` for targets with 32-bit pointers, and likewise set to `"64"` for
20952095
64-bit pointers.
2096+
* `target_vendor = "..."` - Vendor of the target, for example `apple`, `pc`, or
2097+
simply `"unknown"`.
20962098
* `test` - Enabled when compiling the test harness (using the `--test` flag).
20972099
* `unix` - See `target_family`.
20982100
* `windows` - See `target_family`.
@@ -2269,7 +2271,7 @@ The currently implemented features of the reference compiler are:
22692271
* `advanced_slice_patterns` - See the [match expressions](#match-expressions)
22702272
section for discussion; the exact semantics of
22712273
slice patterns are subject to change, so some types
2272-
are still unstable.
2274+
are still unstable.
22732275

22742276
* `slice_patterns` - OK, actually, slice patterns are just scary and
22752277
completely unstable.
@@ -2290,6 +2292,9 @@ The currently implemented features of the reference compiler are:
22902292
* `box_syntax` - Allows use of `box` expressions, the exact semantics of which
22912293
is subject to change.
22922294

2295+
* `cfg_target_vendor` - Allows conditional compilation using the `target_vendor`
2296+
matcher which is subject to change.
2297+
22932298
* `concat_idents` - Allows use of the `concat_idents` macro, which is in many
22942299
ways insufficient for concatenating identifiers, and may be
22952300
removed entirely for something more wholesome.

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
617617
let wordsz = &sess.target.target.target_pointer_width;
618618
let os = &sess.target.target.target_os;
619619
let env = &sess.target.target.target_env;
620+
let vendor = &sess.target.target.target_vendor;
620621

621622
let fam = match sess.target.target.options.is_like_windows {
622623
true => InternedString::new("windows"),
@@ -632,6 +633,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
632633
mk(InternedString::new("target_endian"), intern(end)),
633634
mk(InternedString::new("target_pointer_width"), intern(wordsz)),
634635
mk(InternedString::new("target_env"), intern(env)),
636+
mk(InternedString::new("target_vendor"), intern(vendor)),
635637
];
636638
if sess.opts.debug_assertions {
637639
ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));

src/librustc_back/target/aarch64_apple_ios.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn target() -> Target {
1919
arch: "aarch64".to_string(),
2020
target_os: "ios".to_string(),
2121
target_env: "".to_string(),
22+
target_vendor: "apple".to_string(),
2223
options: TargetOptions {
2324
features: "+neon,+fp-armv8,+cyclone".to_string(),
2425
eliminate_frame_pointer: false,

src/librustc_back/target/aarch64_linux_android.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub fn target() -> Target {
1818
arch: "aarch64".to_string(),
1919
target_os: "android".to_string(),
2020
target_env: "".to_string(),
21+
target_vendor: "unknown".to_string(),
2122
options: super::android_base::opts(),
2223
}
2324
}

src/librustc_back/target/aarch64_unknown_linux_gnu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn target() -> Target {
1919
target_env: "gnu".to_string(),
2020
arch: "aarch64".to_string(),
2121
target_os: "linux".to_string(),
22+
target_vendor: "unknown".to_string(),
2223
options: base,
2324
}
2425
}

src/librustc_back/target/arm_linux_androideabi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub fn target() -> Target {
2121
arch: "arm".to_string(),
2222
target_os: "android".to_string(),
2323
target_env: "gnu".to_string(),
24+
target_vendor: "unknown".to_string(),
2425
options: base,
2526
}
2627
}

src/librustc_back/target/arm_unknown_linux_gnueabi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn target() -> Target {
1919
arch: "arm".to_string(),
2020
target_os: "linux".to_string(),
2121
target_env: "gnueabi".to_string(),
22+
target_vendor: "unknown".to_string(),
2223

2324
options: TargetOptions {
2425
features: "+v6".to_string(),

src/librustc_back/target/arm_unknown_linux_gnueabihf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn target() -> Target {
1919
arch: "arm".to_string(),
2020
target_os: "linux".to_string(),
2121
target_env: "gnueabihf".to_string(),
22+
target_vendor: "unknown".to_string(),
2223

2324
options: TargetOptions {
2425
features: "+v6,+vfp2".to_string(),

src/librustc_back/target/armv7_apple_ios.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn target() -> Target {
1919
arch: "arm".to_string(),
2020
target_os: "ios".to_string(),
2121
target_env: "".to_string(),
22+
target_vendor: "apple".to_string(),
2223
options: TargetOptions {
2324
features: "+v7,+vfp3,+neon".to_string(),
2425
.. opts(Arch::Armv7)

src/librustc_back/target/armv7s_apple_ios.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn target() -> Target {
1919
arch: "arm".to_string(),
2020
target_os: "ios".to_string(),
2121
target_env: "".to_string(),
22+
target_vendor: "apple".to_string(),
2223
options: TargetOptions {
2324
features: "+v7,+vfp4,+neon".to_string(),
2425
.. opts(Arch::Armv7s)

0 commit comments

Comments
 (0)