silk.core.target.
Facts about the target machine of the current compilation: architecture, operating system, ABI, and pointer width.
When to use#
Use Target with static if to select code for a machine, such as a system call for Linux or
Darwin. Use pointerBits, usizeMax, and the other constants for pointer-sized arithmetic.
Use silk.core.compilation for build choices, such as the artifact kind or the safety policy.
Details#
The compiler fixes these facts before static evaluation, from the selected target. They do not depend on the host machine. They have no runtime storage, so a selection adds no runtime cost.
Examples#
Select a value for the pointer width#
import silk.core.target { Target, Arch }
fn wordBytes() -> i32 {
static if Target.arch() == Arch.Wasm32 {
return 4
}
return 8
}
pub fn main() -> i32 {
let bytes = wordBytes()
if bytes != 4 && bytes != 8 {
return 1
}
return 0
}Import as Target with import silk.core.target { Target }.
Public declarations: 11.
Arch#
pub enum ArchThe instruction set architectures that the compiler supports.
Details#
Read the target value with Target.arch.
Aarch64#
Aarch6464-bit Arm (AArch64).
Wasm32#
Wasm3232-bit WebAssembly.
X86_64#
X86_6464-bit x86 (x86-64).
OperatingSystem#
pub enum OperatingSystemThe operating systems that the compiler supports.
Details#
Read the target value with Target.operatingSystem.
Darwin#
DarwinDarwin (macOS).
Linux#
LinuxLinux.
Freestanding#
FreestandingNo operating system, such as WebAssembly without a host interface.
Wasi#
WasiThe WebAssembly System Interface (WASI).
Abi#
pub enum AbiThe platform calling conventions that the compiler supports.
Details#
Read the target value with Target.abi.
Apple#
AppleThe Apple calling convention.
Gnu#
GnuThe GNU calling convention.
Wasm#
WasmThe WebAssembly calling convention.
ObjectFormat#
pub enum ObjectFormatThe object file formats that the compiler supports.
Details#
Read the target value with Target.objectFormat.
MachO#
MachOMach-O, the format of Darwin.
Elf#
ElfELF, the format of Linux.
Wasm#
WasmThe WebAssembly binary format.
Endianness#
pub enum EndiannessThe byte orders that the compiler supports.
Details#
Read the target value with Target.endianness.
Little#
LittleLittle-endian. The least significant byte is at the lowest address.
pointerBits#
pub const pointerBits: u32The width of a pointer on the target, in bits: 32 or 64.
usizeMax#
pub const usizeMax: usizeThe maximum usize value on the target: 2^32 - 1 or 2^64 - 1.
isizeMax#
pub const isizeMax: isizeThe maximum isize value on the target: 2^31 - 1 or 2^63 - 1.
isizeMin#
pub const isizeMin: isizeThe minimum isize value on the target: -2^31 or -2^63.
pointerAlignment#
pub const pointerAlignment: u32The alignment of a data pointer on the target, in bytes.
Target#
pub struct TargetThe owner type of the target queries. It has no fields and is never constructed.
Details#
Each operation is static. Use it in a static if, a static fn, or a const initializer.
Implementation Target#
impl TargetAssociated function arch#
pub static fn arch() -> ArchReturns the instruction set architecture of the target.
Associated function operatingSystem#
pub static fn operatingSystem() -> OperatingSystemReturns the operating system of the target.
Associated function abi#
pub static fn abi() -> AbiReturns the calling convention of the target.
Associated function objectFormat#
pub static fn objectFormat() -> ObjectFormatReturns the object file format of the target.
Associated function endianness#
pub static fn endianness() -> EndiannessReturns the byte order of the target.
Associated function cpu#
pub static fn cpu() -> string<'static>Returns the name of the CPU model that the build selects, as written in the compilation profile.
Associated function deployment#
pub static fn deployment() -> string<'static>Returns the minimum platform version that the build selects, as written in the compilation profile.
Associated function hasCpuFeature#
pub static fn hasCpuFeature(value: string<'static>) -> boolReturns true if the build enables the CPU feature value.
Details#
value is a canonical feature name of the target, as written in the compilation profile.
Category: Core.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.