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

rustc: Add target_vendor for target triples #28612

Merged
merged 2 commits into from
Sep 26, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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")));
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/aarch64_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/aarch64_linux_android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure what the correct value is. "linux" is part of the triple, however it is not an official vendor name in this list: http://llvm.org/docs/doxygen/html/classllvm_1_1Triple.html#a96fe35195867c94aef1adf2ad0e20eec

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like LLVM normalize arm-linux-androideabi to arm--linux-androideabi which in theory means that target_os should be "linux" and target_env should be "androideabi", but we can't really change that now! Regardless though it looks like "unknown" is the right vendor for the android triples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking it up! I changed it to "unknown".

options: super::android_base::opts(),
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/aarch64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/arm_linux_androideabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/arm_unknown_linux_gnueabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/arm_unknown_linux_gnueabihf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/armv7_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/armv7s_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/i386_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_linux_android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_pc_windows_msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_unknown_dragonfly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_unknown_freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/mips_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/mipsel_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
12 changes: 10 additions & 2 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
};

Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/powerpc_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_pc_windows_msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_unknown_bitrig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_unknown_dragonfly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_unknown_freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_unknown_linux_musl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_unknown_netbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_unknown_openbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
7 changes: 7 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, 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)

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -1069,6 +1075,7 @@ fn check_crate_inner<F>(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"),
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/compile-fail/feature-gate-cfg-target-vendor.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
}
19 changes: 19 additions & 0 deletions src/test/run-pass/cfg-target-vendor.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {
}