Browse the docs

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#

silk
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#

silk
pub enum Arch

The instruction set architectures that the compiler supports.

Details#

Read the target value with Target.arch.

Aarch64#

silk
Aarch64

64-bit Arm (AArch64).

Wasm32#

silk
Wasm32

32-bit WebAssembly.

X86_64#

silk
X86_64

64-bit x86 (x86-64).

OperatingSystem#

silk
pub enum OperatingSystem

The operating systems that the compiler supports.

Details#

Read the target value with Target.operatingSystem.

Darwin#

silk
Darwin

Darwin (macOS).

Linux#

silk
Linux

Linux.

Freestanding#

silk
Freestanding

No operating system, such as WebAssembly without a host interface.

Wasi#

silk
Wasi

The WebAssembly System Interface (WASI).

Abi#

silk
pub enum Abi

The platform calling conventions that the compiler supports.

Details#

Read the target value with Target.abi.

Apple#

silk
Apple

The Apple calling convention.

Gnu#

silk
Gnu

The GNU calling convention.

Wasm#

silk
Wasm

The WebAssembly calling convention.

ObjectFormat#

silk
pub enum ObjectFormat

The object file formats that the compiler supports.

Details#

Read the target value with Target.objectFormat.

MachO#

silk
MachO

Mach-O, the format of Darwin.

Elf#

silk
Elf

ELF, the format of Linux.

Wasm#

silk
Wasm

The WebAssembly binary format.

Endianness#

silk
pub enum Endianness

The byte orders that the compiler supports.

Details#

Read the target value with Target.endianness.

Little#

silk
Little

Little-endian. The least significant byte is at the lowest address.

pointerBits#

silk
pub const pointerBits: u32

The width of a pointer on the target, in bits: 32 or 64.

usizeMax#

silk
pub const usizeMax: usize

The maximum usize value on the target: 2^32 - 1 or 2^64 - 1.

isizeMax#

silk
pub const isizeMax: isize

The maximum isize value on the target: 2^31 - 1 or 2^63 - 1.

isizeMin#

silk
pub const isizeMin: isize

The minimum isize value on the target: -2^31 or -2^63.

pointerAlignment#

silk
pub const pointerAlignment: u32

The alignment of a data pointer on the target, in bytes.

Target#

silk
pub struct Target

The 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#

silk
impl Target

Associated function arch#

silk
pub static fn arch() -> Arch

Returns the instruction set architecture of the target.

Associated function operatingSystem#

silk
pub static fn operatingSystem() -> OperatingSystem

Returns the operating system of the target.

Associated function abi#

silk
pub static fn abi() -> Abi

Returns the calling convention of the target.

Associated function objectFormat#

silk
pub static fn objectFormat() -> ObjectFormat

Returns the object file format of the target.

Associated function endianness#

silk
pub static fn endianness() -> Endianness

Returns the byte order of the target.

Associated function cpu#

silk
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#

silk
pub static fn deployment() -> string<'static>

Returns the minimum platform version that the build selects, as written in the compilation profile.

Associated function hasCpuFeature#

silk
pub static fn hasCpuFeature(value: string<'static>) -> bool

Returns 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.

View the source of this page