Skip to main content

target_info/
lib.rs

1//! Get information concerning the build target.
2
3macro_rules! return_cfg {
4	($i:ident : $s:expr) => ( if cfg!($i = $s) { return $s; } );
5	($i:ident : $s:expr, $($t:expr),+) => ( return_cfg!($i: $s); return_cfg!($i: $($t),+) );
6}
7
8/// Collection of functions to give information on the build target.
9pub struct Target;
10impl Target {
11	/// Architecture; given by `target_arch`.
12	pub fn arch() -> &'static str {
13		return_cfg!(target_arch: "x86", "x86_64", "mips", "powerpc", "arm", "aarch64");
14		"unknown"
15	}
16
17	/// Endianness; given by `target_endian`.
18	pub fn endian() -> &'static str {
19		return_cfg!(target_endian: "little", "big");
20		""
21	}
22
23	/// Toolchain environment; given by `target_environment`.
24	pub fn env() -> &'static str {
25		return_cfg!(target_env: "musl", "msvc", "gnu");
26		""
27	}
28
29	/// OS familt; given by `target_family`.
30	pub fn family() -> &'static str {
31		return_cfg!(target_family: "unix", "windows");
32		"unknown"
33	}
34
35	/// Operating system; given by `target_os`.
36	pub fn os() -> &'static str {
37		return_cfg!(target_os: "windows", "macos", "ios", "linux", "android", "freebsd", "dragonfly", "bitrig", "openbsd", "netbsd");
38		"unknown"
39	}
40
41	/// Pointer width; given by `target_pointer_width`.
42	pub fn pointer_width() -> &'static str {
43		return_cfg!(target_pointer_width: "32", "64");
44		"unknown"
45	}
46
47	// TODO: enable once it's not experimental API.
48	// 	pub fn vendor() -> &'static str {
49	// return_cfg!(target_vendor: "apple", "pc");
50	// "unknown"
51	// }
52}
53