Skip to main content

TargetTuple

Struct TargetTuple 

Source
pub struct TargetTuple { /* private fields */ }
Expand description

Everything about a target that changes the bytes the compiler emits.

The membership rule, from spec/cross-compile/03-target-model.md section 3.2: a fact belongs here if it changes how a function is called or how a struct is laid out. Everything else, the CPU model, the optimization level, the instruction set extensions, is a flag and lives outside. The rule is what makes the tuple usable as a cache key, and the cache is what makes the distribution in spec/cross-compile/13-distribution.md fit in the size budget, so this is load bearing rather than tidy.

Construct with TargetTuple::new or by parsing. The fields are private because six of the ten are derived from the other four, and a struct literal would let a caller build a combination that does not exist, such as Windows with an ELF object format.

Implementations§

Source§

impl TargetTuple

Source

pub fn new(arch: Arch, os: Os) -> Result<TargetTuple, Error>

The common case: an architecture, an OS, and the OS’s default environment.

§Errors

Returns the mismatch if the pair does not describe a machine.

Source

pub const fn builder(arch: Arch, os: Os) -> TupleBuilder

Start a builder for a target that needs more than an architecture and an OS.

Source

pub const fn arch(self) -> Arch

The instruction set family.

Source

pub const fn sub_arch(self) -> SubArch

The baseline within the family.

Source

pub const fn endian(self) -> Endian

The byte order.

Source

pub const fn data_model(self) -> DataModel

The widths of int, long and a pointer.

Source

pub const fn os(self) -> Os

The operating system.

Source

pub const fn os_version(self) -> Option<Version>

The OS version, which is a deployment target on Darwin and a preview number on WASI.

Source

pub const fn env(self) -> Env

The environment, which is the C library on Linux and the ABI variant elsewhere.

Source

pub const fn env_version(self) -> Option<Version>

The environment version, which is a glibc version or an Android API level.

Source

pub const fn abi(self) -> Abi

The float ABI as the tuple named it, which is Abi::Default unless the user was explicit. Call TargetTuple::resolved_abi to get the one code generation uses.

Source

pub const fn resolved_abi(self) -> Abi

The float ABI with the target’s default filled in.

Source

pub const fn object_format(self) -> ObjectFormat

The container the compiler writes for this target.

Source

pub const fn pointer_width(self) -> u32

The width of a pointer in bits, read from the data model rather than from the architecture.

Source

pub const fn is_little_endian(self) -> bool

Whether bytes are stored least significant first.

Source

pub const fn char_is_signed(self) -> bool

Whether plain char is signed.

Signed on x86 and wasm, unsigned on ARM, AArch64, RISC-V, LoongArch, PowerPC and s390x. This is the classic first cross compilation bug, because a corpus written and tested on x86-64 contains code that assumes char holds negative values and it passes until the day it runs on ARM.

s390x is the row worth naming, because the obvious guess is wrong. It is a big-endian mainframe architecture with a signed everything else, and its char is unsigned, which the ELF ABI supplement says and which __CHAR_UNSIGNED__ from a cross compiler confirms.

The operating system overrides the architecture twice. Windows says signed everywhere because the Microsoft ABI does, and Darwin says signed on AArch64 because Apple kept it that way for source compatibility with the Intel Macs, against what AAPCS64 says. So aarch64-macos and aarch64-linux-gnu are the same architecture with opposite answers, which is the pair most likely to catch a corpus out.

Source

pub const fn leading_underscore(self) -> bool

Whether symbols carry a leading underscore.

Source

pub fn arch_component(self) -> String

The leading component of the canonical spelling, which is the architecture with its baseline and byte order folded in.

The folding is not decoration. powerpc64le and armv7 and aarch64_be are what every other toolchain writes, and a tuple that spelled them as separate components would not paste into anybody’s build script.

Source

pub fn os_component(self) -> String

The OS component of the canonical spelling, with its version.

Source

pub fn env_component(self) -> String

The environment component of the canonical spelling, with its version and with the suffixes GCC fuses into it put back.

Empty when there is nothing to say, and the caller drops the separator in that case, so x86_64-none has two components and armv7m-none-eabi has three.

Source

pub fn to_canonical_string(self) -> String

The canonical spelling. This is what --print-target-triple answers and what the cache is keyed on.

It has no vendor component. The vendor field in a GNU triple has carried no information since the last vendor that mattered stopped shipping a Unix, and every tool that reads one has to special case unknown, pc, none and w64 to get past it. The parser accepts a vendor so that pasted triples work; the canonical form does not write one.

Source

pub fn to_llvm_string(self) -> String

The LLVM spelling, with a vendor and with a three component OS version.

This exists because the tuple has to leave the building. A .ll file, an object file’s target metadata, a --target handed to an external tool and a user pasting from a Clang invocation all speak LLVM’s dialect, and --print-llvm-triple is the flag that says what it would be. spec/cross-compile/12-driver.md section 12.3 keeps the two flags separate rather than picking one spelling and making half the users translate.

Trait Implementations§

Source§

impl Clone for TargetTuple

Source§

fn clone(&self) -> TargetTuple

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TargetTuple

Source§

impl Debug for TargetTuple

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for TargetTuple

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for TargetTuple

Source§

impl FromStr for TargetTuple

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<TargetTuple, <TargetTuple as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for TargetTuple

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TargetTuple

Source§

fn eq(&self, other: &TargetTuple) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TargetTuple

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.