[−][src]Struct cargo_rustc_cfg::Target
A container for all lines from the output that are prefixed with the
target_
string.
For more information about possible values and recognized key-value pairs, see the Rust Reference book on Conditional Compilation.
Implementations
impl Target
[src]
pub fn arch(&self) -> &str
[src]
The target's CPU architecture.
This is the target_arch
line in the output. See the target_arch
section on Conditional Compilation in the Rust Reference book for
example values. The surrounding double quotes, "
, of the raw output of
the cargo rustc -- --print cfg
command are removed.
Examples
For a 32-bit Intel x86 target:
let cfg = Cfg::rustc_target("i686-pc-windows-msvc")?; assert_eq!(cfg.target().arch(), "x86");
For a 64-bit Intel x86 target:
let cfg = Cfg::rustc_target("x86_64-pc-windows-msvc")?; assert_eq!(cfg.target().arch(), "x86_64");
For a 32-bit ARM target:
let cfg = Cfg::rustc_target("thumbv7a-pc-windows-msvc")?; assert_eq!(cfg.target().arch(), "arm");
For a 64-bit ARM target:
let cfg = Cfg::rustc_target("aarch64-pc-windows-msvc")?; assert_eq!(cfg.target().arch(), "aarch64");
pub fn endian(&self) -> &str
[src]
The target's CPU endianness.
This is the target_endian
line in the output. See the
target_endian
section on Conditional Compilation in the Rust
Reference book for example values. The surrounding double quotes, "
,
of the raw output of the cargo rustc -- --print cfg
command are
removed.
Examples
For a little endian target:
let cfg = Cfg::rustc_target("x86_64-pc-windows-msvc")?; assert_eq!(cfg.target().endian(), "little");
For a big endian target:
let cfg = Cfg::rustc_target("sparc64-unknown-linux-gnu")?; assert_eq!(cfg.target().endian(), "big");
pub fn env(&self) -> Option<&str>
[src]
The Application Binary Interface (ABI) or libc
used by the target.
This is the target_env
line in the output. See the
target_env
section on Conditional Compilation in the Rust
Reference book for example values. The surrounding double quotes, "
,
of the raw output of the cargo rustc -- --print cfg
command are
removed.
This will return None
if the target_env
line is missing from the
output or the value is the empty string, ""
.
Examples
let cfg = Cfg::rustc_target("x86_64-pc-windows-gnu")?; assert_eq!(cfg.target().env(), Some("gnu"));
pub fn family(&self) -> Option<&str>
[src]
The target's operating system family.
This is the target_family
line in the output. See the
target_family
section on Conditional Compilation in the Rust
Reference book for example values. The surrounding double quotes, "
,
of the raw output of the cargo rustc -- --print cfg
command are
removed.
This will return None
if the target_family
key-value pair was missing
from the output or the value was the empty string, ""
.
Examples
For a Windows target:
let cfg = Cfg::rustc_target("x86_64-pc-windows-msvc")?; assert_eq!(cfg.target().family(), Some("windows"));
For a Linux target:
let cfg = Cfg::rustc_target("x86_64-unknown-linux-gnu")?; assert_eq!(cfg.target().family(), Some("unix"));
For an Apple target:
let cfg = Cfg::rustc_target("x86_64-apple-darwin")?; assert_eq!(cfg.target().family(), Some("unix"));
pub fn features(&self) -> Vec<&str>
[src]
The features enabled for a target's compilation.
This is any target_feature
line in the output. See the
target_feature
section on Conditional Compilation in the Rust
Reference book for example values. The surrounding double quotes, "
,
of the raw output of the cargo rustc -- --print cfg
command are
removed.
Compiler features are enabled and disabled using either the Rust
compiler's (rustc) -C/--codegen
command line option, the Cargo
rustflags
key-value configuration, or the RUSTFLAGS
environment
variable supported by Cargo but not rustc.
Examples
Using the RUSTFLAGS
environment variable to add the static linking
feature to the target's compiler configuration:
std::env::set_var("RUSTFLAGS", "-C target-feature=+crt-static"); let cfg = Cfg::rustc_target("x86_64-pc-windows-msvc")?; std::env::set_var("RUSTFLAGS", ""); assert!(cfg.target().features().contains(&"crt-static"));
Using the -C/--codegen
command line option to add the static linking
feature to the target's compiler configuration:
let cfg = CargoRustcPrintCfg::default() .rustc_target("x86_64-pc-windows-msvc") .rustc_args(&["-C", "target-feature=+crt-static"]) .execute()?; assert!(cfg.target().features().contains(&"crt-static"));
pub fn os(&self) -> &str
[src]
The target's operating system.
This is the target_os
line in the output. See the
[target_os
] section on Conditional Compilation in the Rust
Reference book for example values. The surrounding double quotes, "
,
of the raw output of the cargo rustc -- --print cfg
command are
removed.
Examples
For a Windows target:
let cfg = Cfg::rustc_target("x86_64-pc-windows-msvc")?; assert_eq!(cfg.target().os(), "windows");
For a Linux target:
let cfg = Cfg::rustc_target("x86_64-unknown-linux-gnu")?; assert_eq!(cfg.target().os(), "linux");
For an Apple target:
let cfg = Cfg::rustc_target("x86_64-apple-darwin")?; assert_eq!(cfg.target().os(), "macos");
Note, the target's OS is different from the target's family for Apple targets.
pub fn pointer_width(&self) -> &str
[src]
The target's pointer width in bits, but as string.
This is the target_pointer_width
line in the output. See the
target_pointer_width
section on Conditional Compilation in the
Rust Reference book for example values. The surrounding double quotes,
"
, of the raw output of the cargo rustc -- --print cfg
command are
removed.
Examples
For a 64-bit target:
let cfg = Cfg::rustc_target("x86_64-pc-windows-msvc")?; assert_eq!(cfg.target().pointer_width(), "64");
For a 32-bit target:
let cfg = Cfg::rustc_target("i686-pc-windows-msvc")?; assert_eq!(cfg.target().pointer_width(), "32");
pub fn vendor(&self) -> Option<&str>
[src]
The target's vendor.
This is the target_vendor
line in the output. See the
target_vendor
section on Conditional Compilation in the Rust
Reference book for example values. The surrounding double quotes, "
,
of the raw output of the cargo rustc -- --print cfg
command are
removed.
This will return None
if the target_vendor
line is missing or the
value is the empty string, ""
.
Examples
For a Windows target:
let cfg = Cfg::rustc_target("x86_64-pc-windows-msvc")?; assert_eq!(cfg.target().vendor(), Some("pc"));
For a Linux target:
let cfg = Cfg::rustc_target("x86_64-unknown-linux-gnu")?; assert_eq!(cfg.target().vendor(), Some("unknown"));
For an Apple target:
let cfg = Cfg::rustc_target("x86_64-apple-darwin")?; assert_eq!(cfg.target().vendor(), Some("apple"));
Trait Implementations
impl Clone for Target
[src]
impl Debug for Target
[src]
impl PartialEq<Target> for Target
[src]
impl StructuralPartialEq for Target
[src]
Auto Trait Implementations
impl RefUnwindSafe for Target
impl Send for Target
impl Sync for Target
impl Unpin for Target
impl UnwindSafe for Target
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,