[][src]Struct cargo_rustc_cfg::Target

pub struct Target { /* fields omitted */ }

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.