Target structv0.1.0

Source
Properties of the machine the build targets.
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

NameTypeDescription
osOperatingSystemThe operating system.
archArchitectureThe processor architecture.
abiApplicationBinaryInterfaceThe calling and layout conventions the target's code follows.
endianEndiannessThe order the target stores a multi-byte value's bytes in.
pointerBitsuintHow many bits a pointer occupies.
dataModelDataModelThe widths the target's C environment assigns to long and to a pointer.
objectFormatObjectFormatThe object-file format compiled code is emitted in.
triplechar8[..]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.

NameTypeDescription
featureTargetFeaturethe target feature to ask about

Returns: whether the target being built for has it

Source

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.

Source

Cases

NameValueDescription
Unknown0A target the compiler has no name for, which no supported build produces.
FreeBSD1FreeBSD. Told apart from the other BSDs, which this enumeration also names.
Linux2Linux, any distribution.
macOS3Apple macOS.
Windows4Microsoft Windows.

Architecture

pub enum Architecture: uint8 {
    Unknown = 0,
    AArch64 = 1,
    X86_64 = 2
}

A processor architecture a build can target.

Source

Cases

NameValueDescription
Unknown0An architecture the compiler has no name for, which no supported build produces.
AArch641The 64-bit Arm architecture.
X86_642The 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.

Source

Cases

NameValueDescription
Unknown0An ABI the compiler has no name for, which no supported build produces.
AAPCS641The AArch64 procedure call standard.
SystemV2The System V AMD64 ABI, used by Linux, FreeBSD, and macOS on x86-64.
WindowsX643The 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.

Source

Cases

NameValueDescription
AVX0x86 Advanced Vector Extensions.
AVX21x86 Advanced Vector Extensions 2.
AVX5122x86 Advanced Vector Extensions 512.
NEON3Arm Advanced SIMD.
SSE24x86 Streaming SIMD Extensions 2.
SSE35x86 Streaming SIMD Extensions 3.
SSE416x86 Streaming SIMD Extensions 4.1.
SSE427x86 Streaming SIMD Extensions 4.2.
SSSE38x86 Supplemental Streaming SIMD Extensions 3.
SVE9Arm Scalable Vector Extension.

Endianness

pub enum Endianness: uint8 {
    Big = 0,
    Little = 1
}

The order a target stores a multi-byte value's bytes in.

Source

Cases

NameValueDescription
Big0Most significant byte first, which is network byte order.
Little1Least 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.

Source

Cases

NameValueDescription
Unknown0A model the compiler has no name for, which no supported build produces.
LLP64132-bit long, 64-bit pointer. Windows.
LP64264-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.

Source

Cases

NameValueDescription
Unknown0A format the compiler has no name for, which no supported build produces.
COFF1The format Windows links, carried in a PE image.
ELF2The format Linux and FreeBSD link.
MachO3The 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.

Source