pub struct TargetInfo { /* private fields */ }
Implementations§
Source§impl TargetInfo
impl TargetInfo
Sourcepub fn new() -> Result<TargetInfo, Error>
pub fn new() -> Result<TargetInfo, Error>
Parse the target info from TARGET
environment variable
TARGET
environment variable is usually set for you in build.rs scripts, therefore this
function is all that’s necessary in majority of cases.
§Example
use target_build_utils::TargetInfo;
let target = TargetInfo::new().expect("could not get target");
Sourcepub fn from_str(s: &str) -> Result<TargetInfo, Error>
pub fn from_str(s: &str) -> Result<TargetInfo, Error>
Calculate the target info from the provided target value
String may contain a triple or path to the json file.
§Example
use target_build_utils::TargetInfo;
let target = TargetInfo::from_str("x86_64-unknown-linux-gnu")
.expect("could not get target");
Source§impl TargetInfo
impl TargetInfo
Sourcepub fn target_arch(&self) -> &str
pub fn target_arch(&self) -> &str
Architecture of the targeted machine
Corresponds to the #[cfg(target_arch = {})]
in Rust code.
Sourcepub fn target_os(&self) -> &str
pub fn target_os(&self) -> &str
OS of the targeted machine
Corresponds to the #[cfg(target_os = {})]
in Rust code.
Sourcepub fn target_env(&self) -> &str
pub fn target_env(&self) -> &str
Environment (ABI) of the targeted machine
Corresponds to the #[cfg(target_env = {})]
in Rust code.
Sourcepub fn target_endian(&self) -> &str
pub fn target_endian(&self) -> &str
Endianess of the targeted machine
Valid values are: little
and big
.
Corresponds to the #[cfg(target_endian = {})]
in Rust code.
Sourcepub fn target_pointer_width(&self) -> &str
pub fn target_pointer_width(&self) -> &str
Pointer width of the targeted machine
Corresponds to the #[cfg(target_pointer_width = {})]
in Rust code.
Sourcepub fn target_vendor(&self) -> Option<&str>
pub fn target_vendor(&self) -> Option<&str>
Vendor of the targeted machine
Corresponds to the #[cfg(target_vendor = {})]
in Rust code.
This currently returns Some
only when when targetting nightly rustc version as well as
for custom JSON targets.
Sourcepub fn target_cfg(&self, key: &str) -> bool
pub fn target_cfg(&self, key: &str) -> bool
Check if the configuration switch is set for target
Corresponds to the #[cfg({key} = {})]
in Rust code.
This function behaves specially in regard to custom JSON targets and will always return
false
for them currently.
§Examples
use target_build_utils::TargetInfo;
let info = TargetInfo::new().expect("target info");
let is_unix = info.target_cfg("unix");
Sourcepub fn target_cfg_value<'a>(&'a self, key: &str) -> Option<&'a str>
pub fn target_cfg_value<'a>(&'a self, key: &str) -> Option<&'a str>
Return the value of an arbitrary configuration key
This function behaves specially in regard to custom JSON targets and will rarely return any extra target information.
§Examples
use target_build_utils::TargetInfo;
let info = TargetInfo::new().expect("target info");
assert_eq!(info.target_cfg_value("target_os"), Some(info.target_os()));
assert_eq!(info.target_cfg_value("target_banana"), None);
Trait Implementations§
Source§impl Clone for TargetInfo
impl Clone for TargetInfo
Source§fn clone(&self) -> TargetInfo
fn clone(&self) -> TargetInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more