Target structv0.1.0
pub struct Target {
pub os: OperatingSystem;
pub arch: Architecture;
pub abi: ApplicationBinaryInterface;
pub endian: Endianness;
pub pointerBits: uint;
pub dataModel: DataModel;
pub objectFormat: ObjectFormat;
pub triple: char8[..];
}
Every field is fixed when compiling begins. Reading one produces no runtime code, so a branch on a field is decided while compiling and the untaken side is not emitted.
Fields
| Name | Type | Description |
|---|---|---|
os | OperatingSystem | The operating system. |
arch | Architecture | The processor architecture. |
abi | ApplicationBinaryInterface | The calling and layout conventions the target's code follows. |
endian | Endianness | The order the target stores a multi-byte value's bytes in. |
pointerBits | uint | How many bits a pointer occupies. |
dataModel | DataModel | The widths the target's C environment assigns to long and to a pointer. |
objectFormat | ObjectFormat | The object-file format compiled code is emitted in. |
triple | char8[..] | The canonical target name, spelled <os>-<arch>, which is what --target accepts. |
Methods
HasFeature
pub func HasFeature(
self: &Target,
feature: TargetFeature
) -> bool
Whether the build enables feature on this target.
self is borrowed and feature is read by value. Answered while compiling, so a branch on it emits only the
side that applies and a body using an instruction the feature provides is never emitted without it.
Cannot fail: a feature the target does not have is absent rather than an error. Costs nothing in the built
program.
| Name | Type | Description |
|---|---|---|
feature | TargetFeature | the target feature to ask about |
Returns: whether the target being built for has it
Related
OperatingSystem
pub enum OperatingSystem: uint8 {
Unknown = 0,
FreeBSD = 1,
Linux = 2,
macOS = 3,
Windows = 4
}
An operating system a build can target. Named per system rather than per family, so a package can tell FreeBSD from Linux where their interfaces differ.
Cases
| Name | Value | Description |
|---|---|---|
Unknown | 0 | A target the compiler has no name for, which no supported build produces. |
FreeBSD | 1 | FreeBSD. Told apart from the other BSDs, which this enumeration also names. |
Linux | 2 | Linux, any distribution. |
macOS | 3 | Apple macOS. |
Windows | 4 | Microsoft Windows. |
Architecture
pub enum Architecture: uint8 {
Unknown = 0,
AArch64 = 1,
X86_64 = 2
}
A processor architecture a build can target.
Cases
| Name | Value | Description |
|---|---|---|
Unknown | 0 | An architecture the compiler has no name for, which no supported build produces. |
AArch64 | 1 | The 64-bit Arm architecture. |
X86_64 | 2 | The 64-bit x86 architecture. |
ApplicationBinaryInterface
pub enum ApplicationBinaryInterface: uint8 {
Unknown = 0,
AAPCS64 = 1,
SystemV = 2,
WindowsX64 = 3
}
The calling and layout conventions a target's code follows. This is what decides how arguments are passed and how aggregates are laid out, so a declaration that has to match a foreign interface branches on it rather than on the operating system.
Cases
| Name | Value | Description |
|---|---|---|
Unknown | 0 | An ABI the compiler has no name for, which no supported build produces. |
AAPCS64 | 1 | The AArch64 procedure call standard. |
SystemV | 2 | The System V AMD64 ABI, used by Linux, FreeBSD, and macOS on x86-64. |
WindowsX64 | 3 | The Windows x64 calling convention. |
TargetFeature
pub enum TargetFeature: uint8 {
AVX = 0,
AVX2 = 1,
AVX512 = 2,
NEON = 3,
SSE2 = 4,
SSE3 = 5,
SSE41 = 6,
SSE42 = 7,
SSSE3 = 8,
SVE = 9
}
A processor feature a target may be built with.
Presence is asked about with Target::HasFeature rather than read as a field, because a build enables a set
rather than a single one.
Cases
| Name | Value | Description |
|---|---|---|
AVX | 0 | x86 Advanced Vector Extensions. |
AVX2 | 1 | x86 Advanced Vector Extensions 2. |
AVX512 | 2 | x86 Advanced Vector Extensions 512. |
NEON | 3 | Arm Advanced SIMD. |
SSE2 | 4 | x86 Streaming SIMD Extensions 2. |
SSE3 | 5 | x86 Streaming SIMD Extensions 3. |
SSE41 | 6 | x86 Streaming SIMD Extensions 4.1. |
SSE42 | 7 | x86 Streaming SIMD Extensions 4.2. |
SSSE3 | 8 | x86 Supplemental Streaming SIMD Extensions 3. |
SVE | 9 | Arm Scalable Vector Extension. |
Endianness
pub enum Endianness: uint8 {
Big = 0,
Little = 1
}
The order a target stores a multi-byte value's bytes in.
Cases
| Name | Value | Description |
|---|---|---|
Big | 0 | Most significant byte first, which is network byte order. |
Little | 1 | Least significant byte first, which every currently supported target uses. |
DataModel
pub enum DataModel: uint8 {
Unknown = 0,
LLP64 = 1,
LP64 = 2
}
The widths a target's C environment assigns to long and to a pointer.
This is what a raw C declaration needs to get long right, since the two models disagree about it.
Cases
| Name | Value | Description |
|---|---|---|
Unknown | 0 | A model the compiler has no name for, which no supported build produces. |
LLP64 | 1 | 32-bit long, 64-bit pointer. Windows. |
LP64 | 2 | 64-bit long, 64-bit pointer. Every supported Unix target. |
ObjectFormat
pub enum ObjectFormat: uint8 {
Unknown = 0,
COFF = 1,
ELF = 2,
MachO = 3
}
The object-file format a target's compiled code is emitted in.
Cases
| Name | Value | Description |
|---|---|---|
Unknown | 0 | A format the compiler has no name for, which no supported build produces. |
COFF | 1 | The format Windows links, carried in a PE image. |
ELF | 2 | The format Linux and FreeBSD link. |
MachO | 3 | The format macOS links. |
#target
pub const #target: Target;
The machine being compiled for, as a compile-time value.
Reading a field produces no runtime code. A when on one keeps only the branch that applies, so the untaken side
is never resolved or type-checked and may name declarations this target does not have.