From af68cdfea1e7a9121122d89d2baa70d64f340d54 Mon Sep 17 00:00:00 2001 From: Sebastian Wicki Date: Thu, 24 Sep 2015 01:20:43 +0200 Subject: [PATCH 1/2] rustc: Add target_vendor for target triples This adds a new target property, `target_vendor` which can be used as a matcher for conditional compilation. The vendor is part of the autoconf target triple: --- The default value for `target_vendor` is "unknown". Matching against the `target_vendor` with `#[cfg]` is currently feature gated as `cfg_target_vendor`. --- src/doc/reference.md | 7 ++++++- src/librustc/session/config.rs | 2 ++ src/librustc_back/target/aarch64_apple_ios.rs | 1 + .../target/aarch64_linux_android.rs | 1 + .../target/aarch64_unknown_linux_gnu.rs | 1 + .../target/arm_linux_androideabi.rs | 1 + .../target/arm_unknown_linux_gnueabi.rs | 1 + .../target/arm_unknown_linux_gnueabihf.rs | 1 + src/librustc_back/target/armv7_apple_ios.rs | 1 + src/librustc_back/target/armv7s_apple_ios.rs | 1 + src/librustc_back/target/i386_apple_ios.rs | 1 + src/librustc_back/target/i686_apple_darwin.rs | 1 + .../target/i686_linux_android.rs | 1 + .../target/i686_pc_windows_gnu.rs | 1 + .../target/i686_pc_windows_msvc.rs | 1 + .../target/i686_unknown_dragonfly.rs | 1 + .../target/i686_unknown_freebsd.rs | 1 + .../target/i686_unknown_linux_gnu.rs | 1 + .../target/mips_unknown_linux_gnu.rs | 1 + .../target/mipsel_unknown_linux_gnu.rs | 1 + src/librustc_back/target/mod.rs | 12 +++++++++-- .../target/powerpc_unknown_linux_gnu.rs | 1 + .../target/x86_64_apple_darwin.rs | 1 + src/librustc_back/target/x86_64_apple_ios.rs | 1 + .../target/x86_64_pc_windows_gnu.rs | 1 + .../target/x86_64_pc_windows_msvc.rs | 1 + .../target/x86_64_unknown_bitrig.rs | 1 + .../target/x86_64_unknown_dragonfly.rs | 1 + .../target/x86_64_unknown_freebsd.rs | 1 + .../target/x86_64_unknown_linux_gnu.rs | 1 + .../target/x86_64_unknown_linux_musl.rs | 1 + .../target/x86_64_unknown_netbsd.rs | 1 + .../target/x86_64_unknown_openbsd.rs | 1 + src/libsyntax/feature_gate.rs | 7 +++++++ .../feature-gate-cfg-target-vendor.rs | 21 +++++++++++++++++++ src/test/run-pass/cfg-target-vendor.rs | 19 +++++++++++++++++ 36 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/feature-gate-cfg-target-vendor.rs create mode 100644 src/test/run-pass/cfg-target-vendor.rs diff --git a/src/doc/reference.md b/src/doc/reference.md index 83849574260e1..a4983570e13db 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2092,6 +2092,8 @@ The following configurations must be defined by the implementation: * `target_pointer_width = "..."` - Target pointer width in bits. This is set to `"32"` for targets with 32-bit pointers, and likewise set to `"64"` for 64-bit pointers. +* `target_vendor = "..."` - Vendor of the target, for example `apple`, `pc`, or + simply `"unknown"`. * `test` - Enabled when compiling the test harness (using the `--test` flag). * `unix` - See `target_family`. * `windows` - See `target_family`. @@ -2268,7 +2270,7 @@ The currently implemented features of the reference compiler are: * `advanced_slice_patterns` - See the [match expressions](#match-expressions) section for discussion; the exact semantics of slice patterns are subject to change, so some types - are still unstable. + are still unstable. * `slice_patterns` - OK, actually, slice patterns are just scary and completely unstable. @@ -2289,6 +2291,9 @@ The currently implemented features of the reference compiler are: * `box_syntax` - Allows use of `box` expressions, the exact semantics of which is subject to change. +* `cfg_target_vendor` - Allows conditional compilation using the `target_vendor` + matcher which is subject to change. + * `concat_idents` - Allows use of the `concat_idents` macro, which is in many ways insufficient for concatenating identifiers, and may be removed entirely for something more wholesome. diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 30f43baabba2f..dcc4ca137ead9 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -617,6 +617,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { let wordsz = &sess.target.target.target_pointer_width; let os = &sess.target.target.target_os; let env = &sess.target.target.target_env; + let vendor = &sess.target.target.target_vendor; let fam = match sess.target.target.options.is_like_windows { true => InternedString::new("windows"), @@ -632,6 +633,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { mk(InternedString::new("target_endian"), intern(end)), mk(InternedString::new("target_pointer_width"), intern(wordsz)), mk(InternedString::new("target_env"), intern(env)), + mk(InternedString::new("target_vendor"), intern(vendor)), ]; if sess.opts.debug_assertions { ret.push(attr::mk_word_item(InternedString::new("debug_assertions"))); diff --git a/src/librustc_back/target/aarch64_apple_ios.rs b/src/librustc_back/target/aarch64_apple_ios.rs index e87cb43128d24..e1242560e62c7 100644 --- a/src/librustc_back/target/aarch64_apple_ios.rs +++ b/src/librustc_back/target/aarch64_apple_ios.rs @@ -19,6 +19,7 @@ pub fn target() -> Target { arch: "aarch64".to_string(), target_os: "ios".to_string(), target_env: "".to_string(), + target_vendor: "apple".to_string(), options: TargetOptions { features: "+neon,+fp-armv8,+cyclone".to_string(), eliminate_frame_pointer: false, diff --git a/src/librustc_back/target/aarch64_linux_android.rs b/src/librustc_back/target/aarch64_linux_android.rs index 8c350e8b28750..d5247bed00874 100644 --- a/src/librustc_back/target/aarch64_linux_android.rs +++ b/src/librustc_back/target/aarch64_linux_android.rs @@ -18,6 +18,7 @@ pub fn target() -> Target { arch: "aarch64".to_string(), target_os: "android".to_string(), target_env: "".to_string(), + target_vendor: "linux".to_string(), options: super::android_base::opts(), } } diff --git a/src/librustc_back/target/aarch64_unknown_linux_gnu.rs b/src/librustc_back/target/aarch64_unknown_linux_gnu.rs index ed79caf486942..51abab6609a86 100644 --- a/src/librustc_back/target/aarch64_unknown_linux_gnu.rs +++ b/src/librustc_back/target/aarch64_unknown_linux_gnu.rs @@ -19,6 +19,7 @@ pub fn target() -> Target { target_env: "gnu".to_string(), arch: "aarch64".to_string(), target_os: "linux".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/arm_linux_androideabi.rs b/src/librustc_back/target/arm_linux_androideabi.rs index 0770fe70e8a57..c21b6b75a62d9 100644 --- a/src/librustc_back/target/arm_linux_androideabi.rs +++ b/src/librustc_back/target/arm_linux_androideabi.rs @@ -21,6 +21,7 @@ pub fn target() -> Target { arch: "arm".to_string(), target_os: "android".to_string(), target_env: "gnu".to_string(), + target_vendor: "linux".to_string(), options: base, } } diff --git a/src/librustc_back/target/arm_unknown_linux_gnueabi.rs b/src/librustc_back/target/arm_unknown_linux_gnueabi.rs index 084f989277f31..7c35b43fd4b75 100644 --- a/src/librustc_back/target/arm_unknown_linux_gnueabi.rs +++ b/src/librustc_back/target/arm_unknown_linux_gnueabi.rs @@ -19,6 +19,7 @@ pub fn target() -> Target { arch: "arm".to_string(), target_os: "linux".to_string(), target_env: "gnueabi".to_string(), + target_vendor: "unknown".to_string(), options: TargetOptions { features: "+v6".to_string(), diff --git a/src/librustc_back/target/arm_unknown_linux_gnueabihf.rs b/src/librustc_back/target/arm_unknown_linux_gnueabihf.rs index 08f1aa5ade848..a99ec45996c2e 100644 --- a/src/librustc_back/target/arm_unknown_linux_gnueabihf.rs +++ b/src/librustc_back/target/arm_unknown_linux_gnueabihf.rs @@ -19,6 +19,7 @@ pub fn target() -> Target { arch: "arm".to_string(), target_os: "linux".to_string(), target_env: "gnueabihf".to_string(), + target_vendor: "unknown".to_string(), options: TargetOptions { features: "+v6,+vfp2".to_string(), diff --git a/src/librustc_back/target/armv7_apple_ios.rs b/src/librustc_back/target/armv7_apple_ios.rs index a6d649ea162f9..d30648002912e 100644 --- a/src/librustc_back/target/armv7_apple_ios.rs +++ b/src/librustc_back/target/armv7_apple_ios.rs @@ -19,6 +19,7 @@ pub fn target() -> Target { arch: "arm".to_string(), target_os: "ios".to_string(), target_env: "".to_string(), + target_vendor: "apple".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 index 264385512adde..66ec6efca0e67 100644 --- a/src/librustc_back/target/armv7s_apple_ios.rs +++ b/src/librustc_back/target/armv7s_apple_ios.rs @@ -19,6 +19,7 @@ pub fn target() -> Target { arch: "arm".to_string(), target_os: "ios".to_string(), target_env: "".to_string(), + target_vendor: "apple".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 d17aa915461df..52b5901192c65 100644 --- a/src/librustc_back/target/i386_apple_ios.rs +++ b/src/librustc_back/target/i386_apple_ios.rs @@ -19,6 +19,7 @@ pub fn target() -> Target { arch: "x86".to_string(), target_os: "ios".to_string(), target_env: "".to_string(), + target_vendor: "apple".to_string(), options: opts(Arch::I386) } } diff --git a/src/librustc_back/target/i686_apple_darwin.rs b/src/librustc_back/target/i686_apple_darwin.rs index 9fe15e7694286..98f4654ecab41 100644 --- a/src/librustc_back/target/i686_apple_darwin.rs +++ b/src/librustc_back/target/i686_apple_darwin.rs @@ -22,6 +22,7 @@ pub fn target() -> Target { arch: "x86".to_string(), target_os: "macos".to_string(), target_env: "".to_string(), + target_vendor: "apple".to_string(), options: base, } } diff --git a/src/librustc_back/target/i686_linux_android.rs b/src/librustc_back/target/i686_linux_android.rs index 708e7756b94bd..34ce967cb9882 100644 --- a/src/librustc_back/target/i686_linux_android.rs +++ b/src/librustc_back/target/i686_linux_android.rs @@ -21,6 +21,7 @@ pub fn target() -> Target { arch: "x86".to_string(), target_os: "android".to_string(), target_env: "gnu".to_string(), + target_vendor: "linux".to_string(), options: base, } } diff --git a/src/librustc_back/target/i686_pc_windows_gnu.rs b/src/librustc_back/target/i686_pc_windows_gnu.rs index ae1b4d450a58e..c825f6043d27b 100644 --- a/src/librustc_back/target/i686_pc_windows_gnu.rs +++ b/src/librustc_back/target/i686_pc_windows_gnu.rs @@ -30,6 +30,7 @@ pub fn target() -> Target { arch: "x86".to_string(), target_os: "windows".to_string(), target_env: "gnu".to_string(), + target_vendor: "pc".to_string(), options: options, } } diff --git a/src/librustc_back/target/i686_pc_windows_msvc.rs b/src/librustc_back/target/i686_pc_windows_msvc.rs index d8c1c79b47fcd..96b2d37ab2088 100644 --- a/src/librustc_back/target/i686_pc_windows_msvc.rs +++ b/src/librustc_back/target/i686_pc_windows_msvc.rs @@ -21,6 +21,7 @@ pub fn target() -> Target { arch: "x86".to_string(), target_os: "windows".to_string(), target_env: "msvc".to_string(), + target_vendor: "pc".to_string(), options: base, } } diff --git a/src/librustc_back/target/i686_unknown_dragonfly.rs b/src/librustc_back/target/i686_unknown_dragonfly.rs index f2478e6d0dbfe..32a15b9f2d4d1 100644 --- a/src/librustc_back/target/i686_unknown_dragonfly.rs +++ b/src/librustc_back/target/i686_unknown_dragonfly.rs @@ -22,6 +22,7 @@ pub fn target() -> Target { arch: "x86".to_string(), target_os: "dragonfly".to_string(), target_env: "".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/i686_unknown_freebsd.rs b/src/librustc_back/target/i686_unknown_freebsd.rs index 6b2d9b5053c4a..812ba11cd796b 100644 --- a/src/librustc_back/target/i686_unknown_freebsd.rs +++ b/src/librustc_back/target/i686_unknown_freebsd.rs @@ -22,6 +22,7 @@ pub fn target() -> Target { arch: "x86".to_string(), target_os: "freebsd".to_string(), target_env: "".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/i686_unknown_linux_gnu.rs b/src/librustc_back/target/i686_unknown_linux_gnu.rs index 074d5b2b9ed22..ac2af0c64fd6a 100644 --- a/src/librustc_back/target/i686_unknown_linux_gnu.rs +++ b/src/librustc_back/target/i686_unknown_linux_gnu.rs @@ -22,6 +22,7 @@ pub fn target() -> Target { arch: "x86".to_string(), target_os: "linux".to_string(), target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/mips_unknown_linux_gnu.rs b/src/librustc_back/target/mips_unknown_linux_gnu.rs index 3f3da6d6c9136..357499c48ec7a 100644 --- a/src/librustc_back/target/mips_unknown_linux_gnu.rs +++ b/src/librustc_back/target/mips_unknown_linux_gnu.rs @@ -18,6 +18,7 @@ pub fn target() -> Target { arch: "mips".to_string(), target_os: "linux".to_string(), target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), options: super::linux_base::opts() } } diff --git a/src/librustc_back/target/mipsel_unknown_linux_gnu.rs b/src/librustc_back/target/mipsel_unknown_linux_gnu.rs index d7f286c8aa408..3d0088add0d53 100644 --- a/src/librustc_back/target/mipsel_unknown_linux_gnu.rs +++ b/src/librustc_back/target/mipsel_unknown_linux_gnu.rs @@ -18,6 +18,7 @@ pub fn target() -> Target { arch: "mips".to_string(), target_os: "linux".to_string(), target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), options: super::linux_base::opts() } diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index e7c1c3fb258ad..b5847b98af1f6 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -77,6 +77,8 @@ pub struct Target { pub target_os: String, /// Environment name to use for conditional compilation. pub target_env: String, + /// Vendor name to use for conditional compilation. + pub target_vendor: String, /// Architecture to use for ABI considerations. Valid options: "x86", "x86_64", "arm", /// "aarch64", "mips", and "powerpc". "mips" includes "mipsel". pub arch: String, @@ -260,14 +262,20 @@ impl Target { } }; + let get_opt_field = |name: &str, default: &str| { + obj.find(name).and_then(|s| s.as_string()) + .map(|s| s.to_string()) + .unwrap_or(default.to_string()) + }; + let mut base = Target { llvm_target: get_req_field("llvm-target"), target_endian: get_req_field("target-endian"), target_pointer_width: get_req_field("target-pointer-width"), arch: get_req_field("arch"), target_os: get_req_field("os"), - target_env: obj.find("env").and_then(|s| s.as_string()) - .map(|s| s.to_string()).unwrap_or(String::new()), + target_env: get_opt_field("env", ""), + target_vendor: get_opt_field("vendor", "unknown"), options: Default::default(), }; diff --git a/src/librustc_back/target/powerpc_unknown_linux_gnu.rs b/src/librustc_back/target/powerpc_unknown_linux_gnu.rs index 896824eba0e56..6664abf5458b7 100644 --- a/src/librustc_back/target/powerpc_unknown_linux_gnu.rs +++ b/src/librustc_back/target/powerpc_unknown_linux_gnu.rs @@ -21,6 +21,7 @@ pub fn target() -> Target { arch: "powerpc".to_string(), target_os: "linux".to_string(), target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_apple_darwin.rs b/src/librustc_back/target/x86_64_apple_darwin.rs index ef40c2f2006e1..3e19e1482909e 100644 --- a/src/librustc_back/target/x86_64_apple_darwin.rs +++ b/src/librustc_back/target/x86_64_apple_darwin.rs @@ -23,6 +23,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "macos".to_string(), target_env: "".to_string(), + target_vendor: "apple".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_apple_ios.rs b/src/librustc_back/target/x86_64_apple_ios.rs index 7aca8c554dab6..63234c0baee8c 100644 --- a/src/librustc_back/target/x86_64_apple_ios.rs +++ b/src/librustc_back/target/x86_64_apple_ios.rs @@ -19,6 +19,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "ios".to_string(), target_env: "".to_string(), + target_vendor: "apple".to_string(), options: opts(Arch::X86_64) } } diff --git a/src/librustc_back/target/x86_64_pc_windows_gnu.rs b/src/librustc_back/target/x86_64_pc_windows_gnu.rs index aef1d7471b85b..2bd363e46bb1c 100644 --- a/src/librustc_back/target/x86_64_pc_windows_gnu.rs +++ b/src/librustc_back/target/x86_64_pc_windows_gnu.rs @@ -25,6 +25,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "windows".to_string(), target_env: "gnu".to_string(), + target_vendor: "pc".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_pc_windows_msvc.rs b/src/librustc_back/target/x86_64_pc_windows_msvc.rs index 85756db96061f..5030a1ff4483b 100644 --- a/src/librustc_back/target/x86_64_pc_windows_msvc.rs +++ b/src/librustc_back/target/x86_64_pc_windows_msvc.rs @@ -22,6 +22,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "windows".to_string(), target_env: "msvc".to_string(), + target_vendor: "pc".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_unknown_bitrig.rs b/src/librustc_back/target/x86_64_unknown_bitrig.rs index 6ecf885aba38e..04456b1b2714a 100644 --- a/src/librustc_back/target/x86_64_unknown_bitrig.rs +++ b/src/librustc_back/target/x86_64_unknown_bitrig.rs @@ -21,6 +21,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "bitrig".to_string(), target_env: "".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_unknown_dragonfly.rs b/src/librustc_back/target/x86_64_unknown_dragonfly.rs index f0e665967ec6f..62654176aa486 100644 --- a/src/librustc_back/target/x86_64_unknown_dragonfly.rs +++ b/src/librustc_back/target/x86_64_unknown_dragonfly.rs @@ -22,6 +22,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "dragonfly".to_string(), target_env: "".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_unknown_freebsd.rs b/src/librustc_back/target/x86_64_unknown_freebsd.rs index f742ebfde1d2c..888b7f58bffca 100644 --- a/src/librustc_back/target/x86_64_unknown_freebsd.rs +++ b/src/librustc_back/target/x86_64_unknown_freebsd.rs @@ -22,6 +22,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "freebsd".to_string(), target_env: "".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_unknown_linux_gnu.rs b/src/librustc_back/target/x86_64_unknown_linux_gnu.rs index 4749e481fd855..e3ccd9c4c7e7d 100644 --- a/src/librustc_back/target/x86_64_unknown_linux_gnu.rs +++ b/src/librustc_back/target/x86_64_unknown_linux_gnu.rs @@ -22,6 +22,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "linux".to_string(), target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_unknown_linux_musl.rs b/src/librustc_back/target/x86_64_unknown_linux_musl.rs index c66192c28b13d..a5ac78cd5b608 100644 --- a/src/librustc_back/target/x86_64_unknown_linux_musl.rs +++ b/src/librustc_back/target/x86_64_unknown_linux_musl.rs @@ -76,6 +76,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "linux".to_string(), target_env: "musl".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_unknown_netbsd.rs b/src/librustc_back/target/x86_64_unknown_netbsd.rs index e13e58e3a186d..4101fabe73480 100644 --- a/src/librustc_back/target/x86_64_unknown_netbsd.rs +++ b/src/librustc_back/target/x86_64_unknown_netbsd.rs @@ -21,6 +21,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "netbsd".to_string(), target_env: "".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/x86_64_unknown_openbsd.rs b/src/librustc_back/target/x86_64_unknown_openbsd.rs index a404db48b22bb..07a1e137b4196 100644 --- a/src/librustc_back/target/x86_64_unknown_openbsd.rs +++ b/src/librustc_back/target/x86_64_unknown_openbsd.rs @@ -21,6 +21,7 @@ pub fn target() -> Target { arch: "x86_64".to_string(), target_os: "openbsd".to_string(), target_env: "".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index be95b58bf881e..ce3c4a15e1e00 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -203,6 +203,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option, Status // allow `#[omit_gdb_pretty_printer_section]` ("omit_gdb_pretty_printer_section", "1.5.0", None, Active), + + // Allows cfg(target_vendor = "..."). + ("cfg_target_vendor", "1.5.0", None, Active), ]; // (changing above list without updating src/doc/reference.md makes @cmr sad) @@ -377,6 +380,7 @@ macro_rules! cfg_fn { const GATED_CFGS: &'static [(&'static str, &'static str, fn(&Features) -> bool)] = &[ // (name in cfg, feature, function to check if the feature is enabled) ("target_feature", "cfg_target_feature", cfg_fn!(|x| x.cfg_target_feature)), + ("target_vendor", "cfg_target_vendor", cfg_fn!(|x| x.cfg_target_vendor)), ]; #[derive(Debug, Eq, PartialEq)] @@ -471,6 +475,7 @@ pub struct Features { pub default_type_parameter_fallback: bool, pub type_macros: bool, pub cfg_target_feature: bool, + pub cfg_target_vendor: bool, pub augmented_assignments: bool, } @@ -500,6 +505,7 @@ impl Features { default_type_parameter_fallback: false, type_macros: false, cfg_target_feature: false, + cfg_target_vendor: false, augmented_assignments: false, } } @@ -1069,6 +1075,7 @@ fn check_crate_inner(cm: &CodeMap, span_handler: &SpanHandler, default_type_parameter_fallback: cx.has_feature("default_type_parameter_fallback"), type_macros: cx.has_feature("type_macros"), cfg_target_feature: cx.has_feature("cfg_target_feature"), + cfg_target_vendor: cx.has_feature("cfg_target_vendor"), augmented_assignments: cx.has_feature("augmented_assignments"), } } diff --git a/src/test/compile-fail/feature-gate-cfg-target-vendor.rs b/src/test/compile-fail/feature-gate-cfg-target-vendor.rs new file mode 100644 index 0000000000000..e68a84d35534f --- /dev/null +++ b/src/test/compile-fail/feature-gate-cfg-target-vendor.rs @@ -0,0 +1,21 @@ +// Copyright 2015 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. + +#[cfg(target_vendor = "x")] //~ ERROR `cfg(target_vendor)` is experimental +#[cfg_attr(target_vendor = "x", x)] //~ ERROR `cfg(target_vendor)` is experimental +struct Foo(u64, u64); + +#[cfg(not(any(all(target_vendor = "x"))))] //~ ERROR `cfg(target_vendor)` is experimental +fn foo() {} + +fn main() { + cfg!(target_vendor = "x"); + //~^ ERROR `cfg(target_vendor)` is experimental and subject to change +} diff --git a/src/test/run-pass/cfg-target-vendor.rs b/src/test/run-pass/cfg-target-vendor.rs new file mode 100644 index 0000000000000..787ae5289dd58 --- /dev/null +++ b/src/test/run-pass/cfg-target-vendor.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +#![feature(cfg_target_vendor)] + +#[cfg(target_vendor = "unknown")] +pub fn main() { +} + +#[cfg(not(target_vendor = "unknown"))] +pub fn main() { +} From abfedb7d16fc536e85e271f945195335ca0ba9e0 Mon Sep 17 00:00:00 2001 From: Sebastian Wicki Date: Thu, 24 Sep 2015 19:44:27 +0200 Subject: [PATCH 2/2] Fix `target_vendor` for Android --- src/librustc_back/target/aarch64_linux_android.rs | 2 +- src/librustc_back/target/arm_linux_androideabi.rs | 2 +- src/librustc_back/target/i686_linux_android.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_back/target/aarch64_linux_android.rs b/src/librustc_back/target/aarch64_linux_android.rs index d5247bed00874..c6901a4cc4270 100644 --- a/src/librustc_back/target/aarch64_linux_android.rs +++ b/src/librustc_back/target/aarch64_linux_android.rs @@ -18,7 +18,7 @@ pub fn target() -> Target { arch: "aarch64".to_string(), target_os: "android".to_string(), target_env: "".to_string(), - target_vendor: "linux".to_string(), + target_vendor: "unknown".to_string(), options: super::android_base::opts(), } } diff --git a/src/librustc_back/target/arm_linux_androideabi.rs b/src/librustc_back/target/arm_linux_androideabi.rs index c21b6b75a62d9..732f1a353a8bd 100644 --- a/src/librustc_back/target/arm_linux_androideabi.rs +++ b/src/librustc_back/target/arm_linux_androideabi.rs @@ -21,7 +21,7 @@ pub fn target() -> Target { arch: "arm".to_string(), target_os: "android".to_string(), target_env: "gnu".to_string(), - target_vendor: "linux".to_string(), + target_vendor: "unknown".to_string(), options: base, } } diff --git a/src/librustc_back/target/i686_linux_android.rs b/src/librustc_back/target/i686_linux_android.rs index 34ce967cb9882..f548fdad3cbed 100644 --- a/src/librustc_back/target/i686_linux_android.rs +++ b/src/librustc_back/target/i686_linux_android.rs @@ -21,7 +21,7 @@ pub fn target() -> Target { arch: "x86".to_string(), target_os: "android".to_string(), target_env: "gnu".to_string(), - target_vendor: "linux".to_string(), + target_vendor: "unknown".to_string(), options: base, } }