build_target/target.rs
1use crate::{Arch, Endian, Env, Family, Os, PointerWidth, Vendor, target_triple};
2
3/// Combined information about a build target.
4#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
5pub struct Target {
6 /// The architecture of the target, such as `x86_64`, `aarch64`, or `i686`.
7 pub arch: Arch,
8 /// The endianness of the target architecture, such as `little` or `big`.
9 pub endian: Endian,
10 /// The environment of the target, such as `gnu`, `msvc`, or `none`.
11 pub env: Option<Env>,
12 /// The operating system of the target, such as `linux`, `windows`, or `macos`.
13 pub os: Os,
14 /// The pointer width of the target, such as `32` or `64`.
15 pub pointer_width: PointerWidth,
16 /// The family of the target, such as `unix`, `windows`, or `wasm`.
17 pub family: Vec<Family>,
18 /// The vendor of the target, such as `apple`, `unknown`, or `pc`.
19 pub vendor: Vendor,
20 /// The target triple, which is a string that uniquely identifies the target.
21 pub triple: String,
22}
23
24impl Target {
25 /// Gets the current build target as a [`Target`].
26 #[must_use]
27 pub fn current() -> Self {
28 Self {
29 arch: Arch::target(),
30 endian: Endian::target(),
31 env: Env::target(),
32 os: Os::target(),
33 pointer_width: PointerWidth::target(),
34 family: Family::target(),
35 vendor: Vendor::target(),
36 triple: target_triple(),
37 }
38 }
39}