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
impl TargetTuple
Sourcepub fn new(arch: Arch, os: Os) -> Result<Self, Error>
pub fn new(arch: Arch, os: Os) -> Result<Self, 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.
Sourcepub const fn builder(arch: Arch, os: Os) -> TupleBuilder
pub const fn builder(arch: Arch, os: Os) -> TupleBuilder
Start a builder for a target that needs more than an architecture and an OS.
Sourcepub const fn data_model(self) -> DataModel
pub const fn data_model(self) -> DataModel
The widths of int, long and a pointer.
Sourcepub const fn os_version(self) -> Option<Version>
pub const fn os_version(self) -> Option<Version>
The OS version, which is a deployment target on Darwin and a preview number on WASI.
Sourcepub const fn env(self) -> Env
pub const fn env(self) -> Env
The environment, which is the C library on Linux and the ABI variant elsewhere.
Sourcepub const fn env_version(self) -> Option<Version>
pub const fn env_version(self) -> Option<Version>
The environment version, which is a glibc version or an Android API level.
Sourcepub const fn abi(self) -> Abi
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.
Sourcepub const fn resolved_abi(self) -> Abi
pub const fn resolved_abi(self) -> Abi
The float ABI with the target’s default filled in.
Sourcepub const fn object_format(self) -> ObjectFormat
pub const fn object_format(self) -> ObjectFormat
The container the compiler writes for this target.
Sourcepub const fn pointer_width(self) -> u32
pub const fn pointer_width(self) -> u32
The width of a pointer in bits, read from the data model rather than from the architecture.
Sourcepub const fn is_little_endian(self) -> bool
pub const fn is_little_endian(self) -> bool
Whether bytes are stored least significant first.
Sourcepub const fn char_is_signed(self) -> bool
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.
Sourcepub const fn leading_underscore(self) -> bool
pub const fn leading_underscore(self) -> bool
Whether symbols carry a leading underscore.
Sourcepub fn arch_component(self) -> String
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.
Sourcepub fn os_component(self) -> String
pub fn os_component(self) -> String
The OS component of the canonical spelling, with its version.
Sourcepub fn env_component(self) -> String
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.
Sourcepub fn to_canonical_string(self) -> String
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.
Sourcepub fn to_llvm_string(self) -> String
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
impl Clone for TargetTuple
Source§fn clone(&self) -> TargetTuple
fn clone(&self) -> TargetTuple
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more