Skip to content
Standard libraryZig 0.17.0Official documentation
Sourcestd/Target.zig

Source line 1

All the details about the machine that will be executing code. Unlike Query which might leave some things as "default" or "host", this data is fully resolved into a concrete set of OS versions, CPU features, etc.

Fields

cpu: Cpu
os: Os
abi: Abi
ofmt: ObjectFormat
dynamic_linker: DynamicLinker = DynamicLinker.none

std.Target.aarch64

alias

Source line 770

Alias of std.Target.aarch64

std.Target.Abi

container

Source line 806

Fields

none
gnu
gnuabin32
gnuabi64
gnueabi
gnueabihf
gnuf32
gnusf
gnux32
eabi
eabihf
abin32
x32
ilp32
android
androideabi
musl
muslabin32
muslabi64
musleabi
musleabihf
muslf32
muslsf
muslx32
msvc
itanium
simulator
ohos
ohoseabi
call0

std.Target.Abi.default

function

Source line 838

pub fn default(arch: Cpu.Arch, os_tag: Os.Tag) Abi

Parameters

arch: Cpu.Arch
os_tag: Os.Tag

std.Target.Abi.float

function

Source line 1032

pub inline fn float(abi: Abi) Float

Parameters

abi: Abi

std.Target.Abi.Float

container

Source line 1027

Fields

hard
soft

std.Target.Abi.isAndroid

function

Source line 1020

pub inline fn isAndroid(abi: Abi) bool

Parameters

abi: Abi

std.Target.Abi.isGnu

function

Source line 983

pub inline fn isGnu(abi: Abi) bool

Parameters

abi: Abi

std.Target.Abi.isMusl

function

Source line 998

pub inline fn isMusl(abi: Abi) bool

Parameters

abi: Abi

std.Target.Abi.isOpenHarmony

function

Source line 1013

pub inline fn isOpenHarmony(abi: Abi) bool

Parameters

abi: Abi

std.Target.AddressSpaceContext

container

Source line 2355

The places where a user can specify an address space attribute

Fields

function

A function is specified to be placed in a certain address space.

variable

A (global) variable is specified to be placed in a certain address space. In contrast to .constant, these values (and thus the address space they will be placed in) are required to be mutable.

constant

A (global) constant value is specified to be placed in a certain address space. In contrast to .variable, values placed in this address space are not required to be mutable.

pointer

A pointer is ascripted to point into a certain address space.

std.Target.Allocator

alias

Source line 3834

Alias of std.mem.Allocator

std.Target.alpha

alias

Source line 771

Alias of std.Target.alpha

std.Target.amdgcn

alias

Source line 772

Alias of std.Target.amdgcn

std.Target.arc

alias

Source line 773

Alias of std.Target.arc

std.Target.arm

alias

Source line 774

Alias of std.Target.arm

std.Target.assert

alias

Source line 3835

Alias of std.debug.assert

std.Target.avr

alias

Source line 775

Alias of std.Target.avr

std.Target.bpf

alias

Source line 776

Alias of std.Target.bpf

std.Target.builtin

constant

Source line 3833

std.Target.cCallingConvention

function

Source line 3756

pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention

Parameters

target: *const Target

std.Target.cCharSignedness

function

Source line 3145

Default signedness of char for the native C compiler for this target Note that char signedness is implementation-defined and many compilers provide an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char Returns null if no C ABI is defined for this target.

pub fn cCharSignedness(target: *const Target) ?std.builtin.Signedness

Parameters

target: *const Target

std.Target.cMaxIntAlignment

function

Source line 3677

pub fn cMaxIntAlignment(target: *const Target) u16

Parameters

target: *const Target

std.Target.Cpu

container

Source line 1210

Fields

arch: Arch

Architecture

model: *const Model

The CPU model to target. It has a set of features which are overridden with the features field.

features: Feature.Set

An explicit list of the entire CPU feature set. It may differ from the specific CPU model's features.

std.Target.Cpu.Arch

container

Source line 1362

Fields

aarch64
aarch64_be
alpha
amdgcn
arc
arceb
arm
armeb
avr
bpfeb
bpfel
csky
ez80
hexagon
hppa
hppa64
kalimba
kvx
lanai
loongarch32
loongarch64
m68k
m88k
microblaze
microblazeel
mips
mipsel
mips64
mips64el
msp430
nvptx
nvptx64
or1k
powerpc
powerpcle
powerpc64
powerpc64le
propeller
riscv32
riscv32be
riscv64
riscv64be
s390x
sh
sheb
sparc
sparc64
spork8
spirv32
spirv64
thumb
thumbeb
ve
wasm32
wasm64
x86_16
x86
x86_64
xcore
xtensa
xtensaeb

std.Target.Cpu.Arch.allCpuModels

function

Source line 1788

All processors Zig is aware of, sorted lexicographically by name.

pub fn allCpuModels(arch: Arch) []const *const Cpu.Model

Parameters

arch: Arch

std.Target.Cpu.Arch.allCpusFromDecls

function

Source line 1794

fn allCpusFromDecls(comptime cpus: type) []const *const Cpu.Model

Parameters

cpus: type

std.Target.Cpu.Arch.allFeaturesList

function

Source line 1781

All CPU features Zig is aware of, sorted lexicographically by name.

pub fn allFeaturesList(arch: Arch) []const Cpu.Feature

Parameters

arch: Arch

std.Target.Cpu.Arch.endian

function

Source line 1708

pub fn endian(arch: Arch) std.builtin.Endian

Parameters

arch: Arch

std.Target.Cpu.Arch.family

function

Source line 1466

pub inline fn family(arch: Arch) Family

Parameters

arch: Arch

std.Target.Cpu.Arch.Family

container

Source line 1428

An architecture family can encompass multiple architectures as represented by Arch. For a given family tag, it is guaranteed that an std.Target.<tag> namespace exists containing CPU model and feature data.

Fields

std.Target.Cpu.Arch.fromCallingConvention

function

Source line 1831

Returns the array of Arch to which a specific std.builtin.CallingConvention applies. Asserts that cc is not .auto, .@"async", .naked, or .@"inline".

pub fn fromCallingConvention(cc: std.builtin.CallingConvention.Tag) []const Arch

Parameters

std.Target.Cpu.Arch.isAarch64

function

Source line 1531

pub inline fn isAarch64(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isAARCH64

alias

Source line 1529

Deprecated; to be removed in 0.18.0. Use isAarch64 instead.

Alias of std.Target.Cpu.Arch.isAarch64

std.Target.Cpu.Arch.isArc

function

Source line 1538

pub inline fn isArc(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isArm

function

Source line 1514

Note that this includes Thumb.

pub inline fn isArm(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isBpf

function

Source line 1678

pub inline fn isBpf(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isHppa

function

Source line 1545

pub inline fn isHppa(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isLoongarch

function

Source line 1562

pub inline fn isLoongarch(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isLoongArch

alias

Source line 1560

Deprecated; to be removed in 0.18.0. Use isLoongarch instead.

Alias of std.Target.Cpu.Arch.isLoongarch

std.Target.Cpu.Arch.isMicroblaze

function

Source line 1590

pub inline fn isMicroblaze(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isMips

function

Source line 1600

pub inline fn isMips(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isMIPS

alias

Source line 1598

Deprecated; to be removed in 0.18.0. Use isMips instead.

Alias of std.Target.Cpu.Arch.isMips

std.Target.Cpu.Arch.isMips32

function

Source line 1607

pub inline fn isMips32(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isMIPS32

alias

Source line 1605

Deprecated; to be removed in 0.18.0. Use isMips32 instead.

Alias of std.Target.Cpu.Arch.isMips32

std.Target.Cpu.Arch.isMips64

function

Source line 1617

pub inline fn isMips64(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isMIPS64

alias

Source line 1615

Deprecated; to be removed in 0.18.0. Use isMips64 instead.

Alias of std.Target.Cpu.Arch.isMips64

std.Target.Cpu.Arch.isNvptx

function

Source line 1685

pub inline fn isNvptx(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isPowerpc

function

Source line 1627

pub inline fn isPowerpc(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isPowerPC

alias

Source line 1625

Deprecated; to be removed in 0.18.0. Use isPowerpc instead.

Alias of std.Target.Cpu.Arch.isPowerpc

std.Target.Cpu.Arch.isPowerpc32

function

Source line 1634

pub inline fn isPowerpc32(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isPowerPC32

alias

Source line 1632

Deprecated; to be removed in 0.18.0. Use isPowerpc32 instead.

Alias of std.Target.Cpu.Arch.isPowerpc32

std.Target.Cpu.Arch.isPowerpc64

function

Source line 1644

pub inline fn isPowerpc64(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isPowerPC64

alias

Source line 1642

Deprecated; to be removed in 0.18.0. Use isPowerpc64 instead.

Alias of std.Target.Cpu.Arch.isPowerpc64

std.Target.Cpu.Arch.isRiscv

function

Source line 1572

pub inline fn isRiscv(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isRISCV

alias

Source line 1570

Deprecated; to be removed in 0.18.0. Use isRiscv instead.

Alias of std.Target.Cpu.Arch.isRiscv

std.Target.Cpu.Arch.isRiscv32

function

Source line 1576

pub inline fn isRiscv32(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isRiscv64

function

Source line 1583

pub inline fn isRiscv64(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isSh

function

Source line 1671

pub inline fn isSh(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isSparc

function

Source line 1654

pub inline fn isSparc(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isSPARC

alias

Source line 1652

Deprecated; to be removed in 0.18.0. Use isSparc instead.

Alias of std.Target.Cpu.Arch.isSparc

std.Target.Cpu.Arch.isSpirv

function

Source line 1664

pub inline fn isSpirv(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isSpirV

alias

Source line 1662

Deprecated; to be removed in 0.18.0. Use isSpirv instead.

Alias of std.Target.Cpu.Arch.isSpirv

std.Target.Cpu.Arch.isThumb

function

Source line 1521

pub inline fn isThumb(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isWasm

function

Source line 1552

pub inline fn isWasm(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isX86

function

Source line 1506

pub inline fn isX86(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.isXtensa

function

Source line 1692

pub inline fn isXtensa(arch: Arch) bool

Parameters

arch: Arch

std.Target.Cpu.Arch.parseCpuModel

function

Source line 1699

pub fn parseCpuModel(arch: Arch, cpu_name: []const u8) ?*const Cpu.Model

Parameters

arch: Arch
cpu_name: []const u8

std.Target.Cpu.Arch.plan9Ext

function

Source line 1815

0c spim little-endian MIPS 3000 family 1c 68000 Motorola MC68000 2c 68020 Motorola MC68020 5c arm little-endian ARM 6c amd64 AMD64 and compatibles (e.g., Intel EM64T) 7c arm64 ARM64 (ARMv8) 8c 386 Intel x86, i486, Pentium, etc. kc sparc Sun SPARC qc power Power PC vc mips big-endian MIPS 3000 family

pub fn plan9Ext(arch: Cpu.Arch) [:0]const u8

Parameters

arch: Cpu.Arch

std.Target.Cpu.baseline

function

Source line 2171

The "default" set of CPU features for cross-compiling. A conservative set of features that is expected to be supported on most available hardware.

pub fn baseline(arch: Arch, os: Os) Cpu

Parameters

arch: Arch
os: Os

std.Target.Cpu.Feature

container

Source line 1221

Fields

index: Set.Index = undefined

The bit index into Set. Has a default value of undefined because the canonical structures are populated via comptime logic.

name: []const u8 = undefined

Has a default value of undefined because the canonical structures are populated via comptime logic.

llvm_name: ?[:0]const u8

If this corresponds to an LLVM-recognized feature, this will be populated; otherwise null.

description: []const u8

Human-friendly UTF-8 text.

dependencies: Set

Sparse Set of features this depends on.

std.Target.Cpu.Feature.FeatureSetFns

type-function

Source line 1327

pub fn FeatureSetFns(comptime F: type) type

Parameters

F: type

std.Target.Cpu.Feature.FeatureSetFns.featureSet

function

Source line 1330

Populates only the feature bits specified.

pub fn featureSet(features: []const F) Set

Parameters

features: []const F

std.Target.Cpu.Feature.FeatureSetFns.featureSetHas

function

Source line 1339

Returns true if the specified feature is enabled.

pub fn featureSetHas(set: Set, feature: F) bool

Parameters

set: Set
feature: F

std.Target.Cpu.Feature.FeatureSetFns.featureSetHasAll

function

Source line 1352

Returns true if every specified feature is enabled.

pub fn featureSetHasAll(set: Set, features: anytype) bool

Parameters

set: Set

std.Target.Cpu.Feature.FeatureSetFns.featureSetHasAny

function

Source line 1344

Returns true if any specified feature is enabled.

pub fn featureSetHasAny(set: Set, features: anytype) bool

Parameters

set: Set

std.Target.Cpu.Feature.Set

container

Source line 1241

A bit set of all the features.

Fields

ints: [usize_count]usize

std.Target.Cpu.Feature.Set.addFeature

function

Source line 1271

Adds the specified feature but not its dependencies.

pub fn addFeature(set: *Set, arch_feature_index: Index) void

Parameters

set: *Set
arch_feature_index: Index

std.Target.Cpu.Feature.Set.addFeatureSet

function

Source line 1278

Adds the specified feature set but not its dependencies.

pub fn addFeatureSet(set: *Set, other_set: Set) void

Parameters

set: *Set
other_set: Set

std.Target.Cpu.Feature.Set.asBytes

function

Source line 1311

pub fn asBytes(set: *const Set) *const [byte_count]u8

Parameters

set: *const Set

std.Target.Cpu.Feature.Set.byte_count

constant

Source line 1245

std.Target.Cpu.Feature.Set.count

function

Source line 1258

pub fn count(set: Set) std.math.IntFittingRange(0, needed_bit_count)

Parameters

set: Set

std.Target.Cpu.Feature.Set.empty

constant

Source line 1250

Set

std.Target.Cpu.Feature.Set.eql

function

Source line 1315

pub fn eql(set: Set, other_set: Set) bool

Parameters

set: Set
other_set: Set

std.Target.Cpu.Feature.Set.Index

type

Source line 1247

std.Target.Cpu.Feature.Set.isEmpty

function

Source line 1252

pub fn isEmpty(set: Set) bool

Parameters

set: Set

std.Target.Cpu.Feature.Set.isEnabled

function

Source line 1264

pub fn isEnabled(set: Set, arch_feature_index: Index) bool

Parameters

set: Set
arch_feature_index: Index

std.Target.Cpu.Feature.Set.isSuperSetOf

function

Source line 1319

pub fn isSuperSetOf(set: Set, other_set: Set) bool

Parameters

set: Set
other_set: Set

std.Target.Cpu.Feature.Set.needed_bit_count

constant

Source line 1244

std.Target.Cpu.Feature.Set.populateDependencies

function

Source line 1294

pub fn populateDependencies(set: *Set, all_features_list: []const Cpu.Feature) void

Parameters

set: *Set
all_features_list: []const Cpu.Feature

std.Target.Cpu.Feature.Set.removeFeature

function

Source line 1283

Removes the specified feature but not its dependents.

pub fn removeFeature(set: *Set, arch_feature_index: Index) void

Parameters

set: *Set
arch_feature_index: Index

std.Target.Cpu.Feature.Set.removeFeatureSet

function

Source line 1290

Removes the specified feature but not its dependents.

pub fn removeFeatureSet(set: *Set, other_set: Set) void

Parameters

set: *Set
other_set: Set

std.Target.Cpu.Feature.Set.ShiftInt

type

Source line 1248

std.Target.Cpu.Feature.Set.usize_count

constant

Source line 1246

std.Target.Cpu.has

function

Source line 2176

Returns true if feature is enabled.

pub fn has(cpu: Cpu, comptime family: Arch.Family, feature: @field(Target, @tagName(family)).Feature) bool

Parameters

cpu: Cpu
family: Arch.Family
feature: @field(Target, @tagName(family)).Feature

std.Target.Cpu.hasAll

function

Source line 2191

Returns true if all features in features are enabled.

pub fn hasAll(cpu: Cpu, comptime family: Arch.Family, features: []const @field(Target, @tagName(family)).Feature) bool

Parameters

cpu: Cpu
family: Arch.Family
features: []const @field(Target, @tagName(family)).Feature

std.Target.Cpu.hasAny

function

Source line 2182

Returns true if any feature in features is enabled.

pub fn hasAny(cpu: Cpu, comptime family: Arch.Family, features: []const @field(Target, @tagName(family)).Feature) bool

Parameters

cpu: Cpu
family: Arch.Family
features: []const @field(Target, @tagName(family)).Feature

std.Target.Cpu.Model

container

Source line 2033

Fields

name: []const u8
llvm_name: ?[:0]const u8
features: Feature.Set

std.Target.Cpu.Model.baseline

function

Source line 2086

Returns a conservative CPU model for arch that is expected to be compatible with the vast majority of hardware available. This function is guaranteed to return CPU models that are understood by both LLVM and Clang, unlike generic.

For certain os values, this function will additionally bump the baseline higher than the baseline would be for arch in isolation; for example, for aarch64-macos, the baseline is considered to be apple_m1. To avoid this behavior entirely, pass Os.Tag.freestanding.

pub fn baseline(arch: Arch, os: Os) *const Model

Parameters

arch: Arch
os: Os

std.Target.Cpu.Model.generic

function

Source line 2051

Returns the most bare-bones CPU model that is valid for arch. Note that this function can return CPU models that are understood by LLVM, but not understood by Clang. If Clang compatibility is important, consider using baseline instead.

pub fn generic(arch: Arch) *const Model

Parameters

arch: Arch

std.Target.Cpu.Model.toCpu

function

Source line 2038

pub fn toCpu(model: *const Model, arch: Arch) Cpu

Parameters

model: *const Model
arch: Arch

std.Target.csky

alias

Source line 777

Alias of std.Target.csky

std.Target.CType

container

Source line 3181

Fields

char
short
ushort
int
uint
long
ulong
longlong
ulonglong
float
double
longdouble

std.Target.cTypeAlignment

function

Source line 3567

Returns null if no C ABI is defined for this target.

pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16

Parameters

target: *const Target
c_type: CType

std.Target.cTypeBitSize

function

Source line 3222

Returns null if no C ABI is defined for this target.

pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16

Parameters

target: *const Target
c_type: CType

std.Target.cTypeByteSize

function

Source line 3197

Returns null if no C ABI is defined for this target.

pub fn cTypeByteSize(t: *const Target, c_type: CType) ?u16

Parameters

t: *const Target
c_type: CType

std.Target.dynamicLibSuffix

function

Source line 2232

pub fn dynamicLibSuffix(target: *const Target) [:0]const u8

Parameters

target: *const Target

std.Target.DynamicLinker

container

Source line 2405

Fields

buffer: [255]u8

Contains the memory used to store the dynamic linker path. This field should not be used directly. See get and set. This field exists so that this API requires no allocator.

len: u8

Used to construct the dynamic linker path. This field should not be used directly. See get and set.

std.Target.DynamicLinker.eql

function

Source line 2447

pub fn eql(lhs: DynamicLinker, rhs: DynamicLinker) bool

Parameters

std.Target.DynamicLinker.get

function

Source line 2431

The returned memory has the same lifetime as the DynamicLinker.

pub fn get(dl: *const DynamicLinker) ?[]const u8

Parameters

dl: *const DynamicLinker

std.Target.DynamicLinker.init

function

Source line 2418

Asserts that the length is less than or equal to 255 bytes.

pub fn init(maybe_path: ?[]const u8) DynamicLinker

Parameters

maybe_path: ?[]const u8

std.Target.DynamicLinker.initFmt

function

Source line 2424

pub fn initFmt(comptime fmt_str: []const u8, args: anytype) !DynamicLinker

Parameters

fmt_str: []const u8

std.Target.DynamicLinker.kind

function

Source line 2460

pub fn kind(os: Os.Tag) Kind

Parameters

os: Os.Tag

std.Target.DynamicLinker.Kind

container

Source line 2451

Fields

none

No dynamic linker.

arch_os

Dynamic linker path is determined by the arch/OS components.

arch_os_abi

Dynamic linker path is determined by the arch/OS/ABI components.

std.Target.DynamicLinker.none

constant

Source line 2415

DynamicLinker

std.Target.DynamicLinker.set

function

Source line 2436

Asserts that the length is less than or equal to 255 bytes.

pub fn set(dl: *DynamicLinker, maybe_path: ?[]const u8) void

Parameters

dl: *DynamicLinker
maybe_path: ?[]const u8

std.Target.DynamicLinker.setFmt

function

Source line 2443

Asserts that the length is less than or equal to 255 bytes.

pub fn setFmt(dl: *DynamicLinker, comptime fmt_str: []const u8, args: anytype) !void

Parameters

dl: *DynamicLinker
fmt_str: []const u8

std.Target.DynamicLinker.standard

function

Source line 2539

The strictness of this function depends on the value of kind(os.tag):

  • .none: Ignores all arguments and just returns none.
  • .arch_os: Ignores abi and returns the dynamic linker matching cpu and os.
  • .arch_os_abi: Returns the dynamic linker matching cpu, os, and abi.

In the case of .arch_os in particular, callers should be aware that a valid dynamic linker being returned only means that the cpu + os combination represents a platform that actually exists and which has an established dynamic linker path that does not change with the ABI; it does not necessarily mean that abi makes any sense at all for that platform. The responsibility for determining whether abi is valid in this case rests with the caller. Abi.default() can be used to pick a best-effort default ABI for such platforms.

pub fn standard(cpu: Cpu, os: Os.Tag, abi: Abi) DynamicLinker

Parameters

cpu: Cpu
os: Os.Tag
abi: Abi

std.Target.exeFileExt

function

Source line 2224

pub fn exeFileExt(target: *const Target) [:0]const u8

Parameters

target: *const Target

std.Target.hexagon

alias

Source line 778

Alias of std.Target.hexagon

std.Target.hppa

alias

Source line 779

Alias of std.Target.hppa

std.Target.hurdTuple

function

Source line 2210

Deprecated; to be removed in 0.18.0. Use std.zig.target.hurdTuple instead.

pub fn hurdTuple(target: *const Target, allocator: Allocator) ![]u8

Parameters

target: *const Target
allocator: Allocator

std.Target.hurdTupleSimple

function

Source line 2205

Deprecated; to be removed in 0.18.0. Use std.zig.target.hurdTupleSimple instead.

pub fn hurdTupleSimple(allocator: Allocator, arch: Cpu.Arch, abi: Abi) ![]u8

Parameters

allocator: Allocator
arch: Cpu.Arch
abi: Abi

std.Target.isBionicLibC

function

Source line 2255

pub inline fn isBionicLibC(target: *const Target) bool

Parameters

target: *const Target

std.Target.isDarwinLibC

function

Source line 2259

pub inline fn isDarwinLibC(target: *const Target) bool

Parameters

target: *const Target

std.Target.isFreeBSDLibC

function

Source line 2266

pub inline fn isFreeBSDLibC(target: *const Target) bool

Parameters

target: *const Target

std.Target.isGnuLibC

function

Source line 2244

pub inline fn isGnuLibC(target: *const Target) bool

Parameters

target: *const Target

std.Target.isMinGW

function

Source line 2240

pub inline fn isMinGW(target: *const Target) bool

Parameters

target: *const Target

std.Target.isMuslLibC

function

Source line 2251

pub inline fn isMuslLibC(target: *const Target) bool

Parameters

target: *const Target

std.Target.isNetBSDLibC

function

Source line 2273

pub inline fn isNetBSDLibC(target: *const Target) bool

Parameters

target: *const Target

std.Target.isOpenBSDLibC

function

Source line 2280

pub inline fn isOpenBSDLibC(target: *const Target) bool

Parameters

target: *const Target

std.Target.isWasiLibC

function

Source line 2287

pub inline fn isWasiLibC(target: *const Target) bool

Parameters

target: *const Target

std.Target.kalimba

alias

Source line 780

Alias of std.Target.generic

std.Target.kvx

alias

Source line 781

Alias of std.Target.kvx

std.Target.lanai

alias

Source line 782

Alias of std.Target.lanai

std.Target.libPrefix

function

Source line 2236

pub fn libPrefix(target: *const Target) [:0]const u8

Parameters

target: *const Target

std.Target.linuxTriple

function

Source line 2220

Deprecated; to be removed in 0.18.0. Use std.zig.target.linuxTriple instead.

pub fn linuxTriple(target: *const Target, allocator: Allocator) ![]u8

Parameters

target: *const Target
allocator: Allocator

std.Target.linuxTripleSimple

function

Source line 2215

Deprecated; to be removed in 0.18.0. Use std.zig.target.linuxTripleSimple instead.

pub fn linuxTripleSimple(allocator: Allocator, arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8

Parameters

allocator: Allocator
arch: Cpu.Arch
os_tag: Os.Tag
abi: Abi

std.Target.loongarch

alias

Source line 783

Alias of std.Target.loongarch

std.Target.m68k

alias

Source line 784

Alias of std.Target.m68k

std.Target.m88k

alias

Source line 785

Alias of std.Target.generic

std.Target.microblaze

alias

Source line 786

Alias of std.Target.generic

std.Target.mips

alias

Source line 787

Alias of std.Target.mips

std.Target.msp430

alias

Source line 788

Alias of std.Target.msp430

std.Target.nvptx

alias

Source line 789

Alias of std.Target.nvptx

std.Target.ObjectFormat

container

Source line 1047

Fields

c

C source code.

coff

The Common Object File Format used by Windows and UEFI.

elf

The Executable and Linkable Format used by many Unixes.

hex

The Intel HEX format for storing binary code in ASCII text.

macho

The Mach object format used by macOS and other Apple platforms.

plan9

The a.out format used by Plan 9 from Bell Labs.

raw

Machine code with no metadata.

spirv

The Khronos Group's Standard Portable Intermediate Representation V.

wasm

The WebAssembly binary format.

std.Target.ObjectFormat.default

function

Source line 1079

pub fn default(os_tag: Os.Tag, arch: Cpu.Arch) ObjectFormat

Parameters

os_tag: Os.Tag
arch: Cpu.Arch

std.Target.ObjectFormat.fileExt

function

Source line 1067

pub fn fileExt(of: ObjectFormat, arch: Cpu.Arch) [:0]const u8

Parameters

of: ObjectFormat
arch: Cpu.Arch

std.Target.or1k

alias

Source line 790

Alias of std.Target.generic

std.Target.Os

container

Source line 14

Fields

tag: Tag
version_range: VersionRange

std.Target.Os.HurdVersionRange

container

Source line 332

Fields

std.Target.Os.HurdVersionRange.includesVersion

function

Source line 336

pub inline fn includesVersion(range: HurdVersionRange, ver: std.SemanticVersion) bool

Parameters

std.Target.Os.HurdVersionRange.isAtLeast

function

Source line 342

Checks if system is guaranteed to be at least version or older than version. Returns null if a runtime check is required.

pub inline fn isAtLeast(range: HurdVersionRange, ver: std.SemanticVersion) ?bool

Parameters

std.Target.Os.isAtLeast

function

Source line 754

Checks if system is guaranteed to be at least version or older than version. Returns null if a runtime check is required.

pub inline fn isAtLeast(os: Os, comptime tag: Tag, ver: switch (tag.versionRangeTag()) { .none => void, .semver, .hurd, .linux => std.SemanticVersion, .windows => WindowsVersion, }) ?bool

Parameters

os: Os
tag: Tag
ver: switch (tag.versionRangeTag()) {
    .none => void,
    .semver, .hurd, .linux => std.SemanticVersion,
    .windows => WindowsVersion,
}

std.Target.Os.LinuxVersionRange

container

Source line 347

Fields

range: std.SemanticVersion.Range
glibc: std.SemanticVersion
android: u32

Android API level.

std.Target.Os.LinuxVersionRange.includesVersion

function

Source line 353

pub inline fn includesVersion(range: LinuxVersionRange, ver: std.SemanticVersion) bool

Parameters

std.Target.Os.LinuxVersionRange.isAtLeast

function

Source line 359

Checks if system is guaranteed to be at least version or older than version. Returns null if a runtime check is required.

pub inline fn isAtLeast(range: LinuxVersionRange, ver: std.SemanticVersion) ?bool

Parameters

std.Target.Os.Tag

container

Source line 18

Fields

freestanding
other
contiki
fuchsia
hermit
managarm
haiku
hurd
illumos
linux
plan9
rtems
serenity
dragonfly
freebsd
netbsd
openbsd
driverkit
ios
maccatalyst
macos
tvos
visionos
watchos
windows
uefi
@"3ds"
wiiu
@"switch"
gba
psx
ps3
ps4
ps5
psp
vita
emscripten
wasi
amdhsa
amdpal
cuda
mesa3d
nvcl
opencl
opengl
vulkan
tios
ashetos

std.Target.Os.Tag.defaultVersionRange

function

Source line 149

pub fn defaultVersionRange(tag: Tag, arch: Cpu.Arch, abi: Abi) Os

Parameters

tag: Tag
arch: Cpu.Arch
abi: Abi

std.Target.Os.Tag.dynamicLibSuffix

function

Source line 124

pub fn dynamicLibSuffix(tag: Tag) [:0]const u8

Parameters

tag: Tag

std.Target.Os.Tag.exeFileExt

function

Source line 101

pub fn exeFileExt(tag: Tag, arch: Cpu.Arch) [:0]const u8

Parameters

tag: Tag
arch: Cpu.Arch

std.Target.Os.Tag.isBSD

function

Source line 94

Deprecated; to be removed in 0.18.0. Check for relevant tags instead.

pub inline fn isBSD(tag: Tag) bool

Parameters

tag: Tag

std.Target.Os.Tag.isDarwin

function

Source line 79

pub inline fn isDarwin(tag: Tag) bool

Parameters

tag: Tag

std.Target.Os.Tag.libPrefix

function

Source line 139

pub fn libPrefix(tag: Os.Tag, abi: Abi) [:0]const u8

Parameters

tag: Os.Tag
abi: Abi

std.Target.Os.Tag.staticLibSuffix

function

Source line 114

pub fn staticLibSuffix(tag: Tag, abi: Abi) [:0]const u8

Parameters

tag: Tag
abi: Abi

std.Target.Os.Tag.versionRangeTag

function

Source line 156

pub inline fn versionRangeTag(tag: Tag) @typeInfo(TaggedVersionRange).@"union".tag_type.?

Parameters

tag: Tag

std.Target.Os.TaggedVersionRange

container

Source line 724

Fields

std.Target.Os.TaggedVersionRange.gnuLibCVersion

function

Source line 731

pub fn gnuLibCVersion(range: TaggedVersionRange) ?std.SemanticVersion

Parameters

std.Target.Os.versionRange

function

Source line 742

Provides a tagged union. Target does not store the tag because it is redundant with the OS tag; this function abstracts that part away.

pub inline fn versionRange(os: Os) TaggedVersionRange

Parameters

os: Os

std.Target.Os.VersionRange

container

Source line 388

The version ranges here represent the minimum OS version to be supported and the maximum OS version to be supported. The default values represent the range that the Zig Standard Library bases its abstractions on.

The minimum version of the range is the main setting to tweak for a target. Usually, the maximum target OS version will remain the default, which is the latest released version of the OS.

To test at compile time if the target is guaranteed to support a given OS feature, one should check that the minimum version of the range is greater than or equal to the version the feature was introduced in.

To test at compile time if the target certainly will not support a given OS feature, one should check that the maximum version of the range is less than the version the feature was introduced in.

If neither of these cases apply, a runtime check should be used to determine if the target supports a given OS feature.

Binaries built with a given maximum version will continue to function on newer operating system versions. However, such a binary may not take full advantage of the newer operating system APIs.

See Os.isAtLeast.

Fields

std.Target.Os.VersionRange.default

function

Source line 397

The default VersionRange represents the range that the Zig Standard Library bases its abstractions on.

pub fn default(arch: Cpu.Arch, tag: Tag, abi: Abi) VersionRange

Parameters

arch: Cpu.Arch
tag: Tag
abi: Abi

std.Target.Os.WindowsVersion

container

Source line 232

Fields

nt4 = 0x04000000
win2k = 0x05000000
xp = 0x05010000
ws2003 = 0x05020000
vista = 0x06000000
win7 = 0x06010000
win8 = 0x06020000
win8_1 = 0x06030000
win10 = 0x0A000000
win10_th2 = 0x0A000001
win10_rs1 = 0x0A000002
win10_rs2 = 0x0A000003
win10_rs3 = 0x0A000004
win10_rs4 = 0x0A000005
win10_rs5 = 0x0A000006
win10_19h1 = 0x0A000007
win10_vb = 0x0A000008
win10_mn = 0x0A000009
win10_fe = 0x0A00000A
win10_co = 0x0A00000B
win10_ni = 0x0A00000C
win10_cu = 0x0A00000D
win11_zn = 0x0A00000E
win11_ga = 0x0A00000F
win11_ge = 0x0A000010
win11_dt = 0x0A000011
win11_br = 0x0A000012
win11_kr = 0x0A000013
_

std.Target.Os.WindowsVersion.format

function

Source line 322

This function is defined to serialize a Zig source code representation of this type, that, when parsed, will deserialize into the same data.

pub fn format(wv: WindowsVersion, w: *std.Io.Writer) std.Io.Writer.Error!void

Parameters

Errors

WriteFailed

See the Writer implementation for detailed diagnostics.

std.Target.Os.WindowsVersion.isAtLeast

function

Source line 292

Returns whether the first version ver is newer (greater) than or equal to the second version ver.

pub inline fn isAtLeast(ver: WindowsVersion, min_ver: WindowsVersion) bool

Parameters

std.Target.Os.WindowsVersion.known_win10_build_numbers

constant

Source line 268

Compared against build numbers reported by the runtime to distinguish win10 versions, where 0x0A000000 + index corresponds to the WindowsVersion u32 value.

std.Target.Os.WindowsVersion.latest

constant

Source line 264

Latest Windows version that the Zig Standard Library is aware of

std.Target.Os.WindowsVersion.parse

function

Source line 314

pub fn parse(str: []const u8) !WindowsVersion

Parameters

str: []const u8

std.Target.Os.WindowsVersion.Range

container

Source line 296

Fields

std.Target.Os.WindowsVersion.Range.includesVersion

function

Source line 300

pub inline fn includesVersion(range: Range, ver: WindowsVersion) bool

Parameters

range: Range
ver: WindowsVersion

std.Target.Os.WindowsVersion.Range.isAtLeast

function

Source line 307

Checks if system is guaranteed to be at least version or older than version. Returns null if a runtime check is required.

pub inline fn isAtLeast(range: Range, min_ver: WindowsVersion) ?bool

Parameters

range: Range
min_ver: WindowsVersion

std.Target.powerpc

alias

Source line 791

Alias of std.Target.powerpc

std.Target.propeller

alias

Source line 792

Alias of std.Target.propeller

std.Target.ptrBitWidth

function

Source line 3057

pub fn ptrBitWidth(target: *const Target) u16

Parameters

target: *const Target

std.Target.ptrBitWidth_arch_abi

function

Source line 2972

pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16

Parameters

cpu_arch: Cpu.Arch
abi: Abi

std.Target.ptrBitWidth_cpu_abi

function

Source line 2968

pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16

Parameters

cpu: Cpu
abi: Abi

std.Target.Query

alias

Source line 12

Alias of std.Target.Query

std.Target.requiresLibC

function

Source line 2293

Does this target require linking libc? This may be the case if the target has an unstable syscall interface, for example.

pub fn requiresLibC(target: *const Target) bool

Parameters

target: *const Target

std.Target.riscv

alias

Source line 793

Alias of std.Target.riscv

std.Target.s390x

alias

Source line 794

Alias of std.Target.s390x

std.Target.sh

alias

Source line 795

Alias of std.Target.generic

std.Target.sparc

alias

Source line 796

Alias of std.Target.sparc

std.Target.spirv

alias

Source line 797

Alias of std.Target.spirv

std.Target.spork8

alias

Source line 798

Alias of std.Target.generic

std.Target.stackAlignment

function

Source line 3061

pub fn stackAlignment(target: *const Target) u16

Parameters

target: *const Target

std.Target.stackGrowth

function

Source line 3127

pub fn stackGrowth(target: *const Target) StackGrowth

Parameters

target: *const Target

std.Target.StackGrowth

container

Source line 3122

Fields

down
up

std.Target.standardDynamicLinkerPath

function

Source line 2964

pub fn standardDynamicLinkerPath(target: *const Target) DynamicLinker

Parameters

target: *const Target

std.Target.staticLibSuffix

function

Source line 2228

pub fn staticLibSuffix(target: *const Target) [:0]const u8

Parameters

target: *const Target

std.Target.std

alias

Source line 3832

Alias of std

std.Target.supportsAddressSpace

function

Source line 2373

Returns whether this target supports address_space. If context is null, this function simply answers the general question of whether the target has any concept of address_space; if non-null, the function additionally checks whether address_space is valid in that context.

pub fn supportsAddressSpace( target: Target, address_space: std.builtin.AddressSpace, context: ?AddressSpaceContext, ) bool

Parameters

target: Target
address_space: std.builtin.AddressSpace
context: ?AddressSpaceContext

std.Target.Target

alias

Source line 3831

Alias of std.Target

std.Target.toCoffMachine

function

Source line 1142

pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE

Parameters

target: *const Target

std.Target.toElfMachine

function

Source line 1094

pub fn toElfMachine(target: *const Target) std.elf.EM

Parameters

target: *const Target

std.Target.ve

alias

Source line 799

Alias of std.Target.ve

std.Target.wasm

alias

Source line 800

Alias of std.Target.wasm

std.Target.x86

alias

Source line 801

Alias of std.Target.x86

std.Target.xcore

alias

Source line 802

Alias of std.Target.xcore

std.Target.xtensa

alias

Source line 803

Alias of std.Target.xtensa

std.Target.z80

alias

Source line 804

Alias of std.Target.generic

std.Target.zigTriple

function

Source line 2200

pub fn zigTriple(target: *const Target, allocator: Allocator) Allocator.Error![]u8

Parameters

target: *const Target
allocator: Allocator

Errors

OutOfMemory
Source code

std/Target.zig

//! All the details about the machine that will be executing code.
//! Unlike `Query` which might leave some things as "default" or "host", this
//! data is fully resolved into a concrete set of OS versions, CPU features,
//! etc.

cpu: Cpu,
os: Os,
abi: Abi,
ofmt: ObjectFormat,
dynamic_linker: DynamicLinker = DynamicLinker.none,

pub const Query = @import("Target/Query.zig");

pub const Os = struct {
    tag: Tag,
    version_range: VersionRange,

    pub const Tag = enum {
        freestanding,
        other,

        contiki,
        fuchsia,
        hermit,
        managarm,

        haiku,
        hurd,
        illumos,
        linux,
        plan9,
        rtems,
        serenity,

        dragonfly,
        freebsd,
        netbsd,
        openbsd,

        driverkit,
        ios,
        maccatalyst,
        macos,
        tvos,
        visionos,
        watchos,

        windows,
        uefi,

        @"3ds",
        wiiu,
        @"switch",
        gba,

        psx,
        ps3,
        ps4,
        ps5,
        psp,
        vita,

        emscripten,
        wasi,

        amdhsa,
        amdpal,
        cuda,
        mesa3d,
        nvcl,
        opencl,
        opengl,
        vulkan,

        tios,

        ashetos,

        pub inline fn isDarwin(tag: Tag) bool {
            return switch (tag) {
                .driverkit,
                .ios,
                .maccatalyst,
                .macos,
                .tvos,
                .visionos,
                .watchos,
                => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Check for relevant tags instead.
        pub inline fn isBSD(tag: Tag) bool {
            return tag.isDarwin() or switch (tag) {
                .freebsd, .openbsd, .netbsd, .dragonfly => true,
                else => false,
            };
        }

        pub fn exeFileExt(tag: Tag, arch: Cpu.Arch) [:0]const u8 {
            return switch (tag) {
                .windows => ".exe",
                .uefi => ".efi",
                .plan9 => arch.plan9Ext(),
                else => switch (arch) {
                    .wasm32, .wasm64 => ".wasm",
                    .spork8 => ".bin",
                    else => "",
                },
            };
        }

        pub fn staticLibSuffix(tag: Tag, abi: Abi) [:0]const u8 {
            return switch (abi) {
                .msvc, .itanium => ".lib",
                else => switch (tag) {
                    .windows, .uefi => ".lib",
                    else => ".a",
                },
            };
        }

        pub fn dynamicLibSuffix(tag: Tag) [:0]const u8 {
            return switch (tag) {
                .windows, .uefi => ".dll",
                .driverkit,
                .ios,
                .maccatalyst,
                .macos,
                .tvos,
                .visionos,
                .watchos,
                => ".dylib",
                else => ".so",
            };
        }

        pub fn libPrefix(tag: Os.Tag, abi: Abi) [:0]const u8 {
            return switch (abi) {
                .msvc, .itanium => "",
                else => switch (tag) {
                    .windows, .uefi => "",
                    else => "lib",
                },
            };
        }

        pub fn defaultVersionRange(tag: Tag, arch: Cpu.Arch, abi: Abi) Os {
            return .{
                .tag = tag,
                .version_range = .default(arch, tag, abi),
            };
        }

        pub inline fn versionRangeTag(tag: Tag) @typeInfo(TaggedVersionRange).@"union".tag_type.? {
            return switch (tag) {
                .freestanding,
                .other,

                .managarm,

                .haiku,
                .illumos,
                .plan9,
                .serenity,

                .psx,
                .ps3,
                .ps4,
                .ps5,
                .gba,

                .emscripten,

                .mesa3d,

                .ashetos,
                => .none,

                .contiki,
                .fuchsia,
                .hermit,

                .rtems,

                .dragonfly,
                .freebsd,
                .netbsd,
                .openbsd,

                .driverkit,
                .ios,
                .maccatalyst,
                .macos,
                .tvos,
                .visionos,
                .watchos,

                .uefi,

                .@"3ds",
                .wiiu,
                .@"switch",

                .psp,
                .vita,

                .wasi,

                .amdhsa,
                .amdpal,
                .cuda,
                .nvcl,
                .opencl,
                .opengl,
                .vulkan,

                .tios,
                => .semver,

                .hurd => .hurd,
                .linux => .linux,

                .windows => .windows,
            };
        }
    };

    /// Based on NTDDI version constants from
    /// https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
    pub const WindowsVersion = enum(u32) {
        nt4 = 0x04000000,
        win2k = 0x05000000,
        xp = 0x05010000,
        ws2003 = 0x05020000,
        vista = 0x06000000,
        win7 = 0x06010000,
        win8 = 0x06020000,
        win8_1 = 0x06030000,
        win10 = 0x0A000000, //aka win10_th1
        win10_th2 = 0x0A000001,
        win10_rs1 = 0x0A000002,
        win10_rs2 = 0x0A000003,
        win10_rs3 = 0x0A000004,
        win10_rs4 = 0x0A000005,
        win10_rs5 = 0x0A000006,
        win10_19h1 = 0x0A000007,
        win10_vb = 0x0A000008, //aka win10_19h2
        win10_mn = 0x0A000009, //aka win10_20h1
        win10_fe = 0x0A00000A, //aka win10_20h2
        win10_co = 0x0A00000B, //aka win10_21h1
        win10_ni = 0x0A00000C, //aka win10_21h2
        win10_cu = 0x0A00000D, //aka win10_22h2
        win11_zn = 0x0A00000E, //aka win11_21h2
        win11_ga = 0x0A00000F, //aka win11_22h2
        win11_ge = 0x0A000010, //aka win11_23h2
        win11_dt = 0x0A000011, //aka win11_24h2
        win11_br = 0x0A000012, //aka win11_25h2
        win11_kr = 0x0A000013, //aka win11_26h1
        _,

        /// Latest Windows version that the Zig Standard Library is aware of
        pub const latest = WindowsVersion.win11_kr;

        /// Compared against build numbers reported by the runtime to distinguish win10 versions,
        /// where 0x0A000000 + index corresponds to the WindowsVersion u32 value.
        pub const known_win10_build_numbers = [_]u32{
            10240, //win10 aka win10_th1
            10586, //win10_th2
            14393, //win10_rs1
            15063, //win10_rs2
            16299, //win10_rs3
            17134, //win10_rs4
            17763, //win10_rs5
            18362, //win10_19h1
            18363, //win10_vb aka win10_19h2
            19041, //win10_mn aka win10_20h1
            19042, //win10_fe aka win10_20h2
            19043, //win10_co aka win10_21h1
            19044, //win10_ni aka win10_21h2
            19045, //win10_cu aka win10_22h2
            22000, //win11_zn aka win11_21h2
            22621, //win11_ga aka win11_22h2
            22631, //win11_ge aka win11_23h2
            26100, //win11_dt aka win11_24h2
            26200, //win11_br aka win11_25h2
            28000, //win11_kr aka win11_26h1
        };

        /// Returns whether the first version `ver` is newer (greater) than or equal to the second version `ver`.
        pub inline fn isAtLeast(ver: WindowsVersion, min_ver: WindowsVersion) bool {
            return @backingInt(ver) >= @backingInt(min_ver);
        }

        pub const Range = struct {
            min: WindowsVersion,
            max: WindowsVersion,

            pub inline fn includesVersion(range: Range, ver: WindowsVersion) bool {
                return @backingInt(ver) >= @backingInt(range.min) and
                    @backingInt(ver) <= @backingInt(range.max);
            }

            /// Checks if system is guaranteed to be at least `version` or older than `version`.
            /// Returns `null` if a runtime check is required.
            pub inline fn isAtLeast(range: Range, min_ver: WindowsVersion) ?bool {
                if (@backingInt(range.min) >= @backingInt(min_ver)) return true;
                if (@backingInt(range.max) < @backingInt(min_ver)) return false;
                return null;
            }
        };

        pub fn parse(str: []const u8) !WindowsVersion {
            return std.meta.stringToEnum(WindowsVersion, str) orelse
                @fromBackingInt(@intCast(std.fmt.parseInt(u32, str, 0) catch
                    return error.InvalidOperatingSystemVersion));
        }

        /// This function is defined to serialize a Zig source code representation of this
        /// type, that, when parsed, will deserialize into the same data.
        pub fn format(wv: WindowsVersion, w: *std.Io.Writer) std.Io.Writer.Error!void {
            if (std.enums.tagName(WindowsVersion, wv)) |name| {
                var vecs: [2][]const u8 = .{ ".", name };
                return w.writeVecAll(&vecs);
            } else {
                return w.print("@fromBackingInt(0x{X:0>8})", .{wv});
            }
        }
    };

    pub const HurdVersionRange = struct {
        range: std.SemanticVersion.Range,
        glibc: std.SemanticVersion,

        pub inline fn includesVersion(range: HurdVersionRange, ver: std.SemanticVersion) bool {
            return range.range.includesVersion(ver);
        }

        /// Checks if system is guaranteed to be at least `version` or older than `version`.
        /// Returns `null` if a runtime check is required.
        pub inline fn isAtLeast(range: HurdVersionRange, ver: std.SemanticVersion) ?bool {
            return range.range.isAtLeast(ver);
        }
    };

    pub const LinuxVersionRange = struct {
        range: std.SemanticVersion.Range,
        glibc: std.SemanticVersion,
        /// Android API level.
        android: u32,

        pub inline fn includesVersion(range: LinuxVersionRange, ver: std.SemanticVersion) bool {
            return range.range.includesVersion(ver);
        }

        /// Checks if system is guaranteed to be at least `version` or older than `version`.
        /// Returns `null` if a runtime check is required.
        pub inline fn isAtLeast(range: LinuxVersionRange, ver: std.SemanticVersion) ?bool {
            return range.range.isAtLeast(ver);
        }
    };

    /// The version ranges here represent the minimum OS version to be supported
    /// and the maximum OS version to be supported. The default values represent
    /// the range that the Zig Standard Library bases its abstractions on.
    ///
    /// The minimum version of the range is the main setting to tweak for a target.
    /// Usually, the maximum target OS version will remain the default, which is
    /// the latest released version of the OS.
    ///
    /// To test at compile time if the target is guaranteed to support a given OS feature,
    /// one should check that the minimum version of the range is greater than or equal to
    /// the version the feature was introduced in.
    ///
    /// To test at compile time if the target certainly will not support a given OS feature,
    /// one should check that the maximum version of the range is less than the version the
    /// feature was introduced in.
    ///
    /// If neither of these cases apply, a runtime check should be used to determine if the
    /// target supports a given OS feature.
    ///
    /// Binaries built with a given maximum version will continue to function on newer
    /// operating system versions. However, such a binary may not take full advantage of the
    /// newer operating system APIs.
    ///
    /// See `Os.isAtLeast`.
    pub const VersionRange = union {
        none: void,
        semver: std.SemanticVersion.Range,
        hurd: HurdVersionRange,
        linux: LinuxVersionRange,
        windows: WindowsVersion.Range,

        /// The default `VersionRange` represents the range that the Zig Standard Library
        /// bases its abstractions on.
        pub fn default(arch: Cpu.Arch, tag: Tag, abi: Abi) VersionRange {
            return switch (tag) {
                .freestanding,
                .other,

                .managarm,

                .haiku,
                .illumos,
                .plan9,
                .serenity,

                .psx,
                .ps3,
                .ps4,
                .ps5,
                .gba,

                .emscripten,

                .mesa3d,

                .ashetos,
                => .{ .none = {} },

                .contiki => .{
                    .semver = .{
                        .min = .{ .major = 5, .minor = 0, .patch = 0 },
                        .max = .{ .major = 5, .minor = 1, .patch = 0 },
                    },
                },
                .fuchsia => .{
                    .semver = .{
                        .min = .{ .major = 27, .minor = 0, .patch = 0 },
                        .max = .{ .major = 30, .minor = 0, .patch = 0 },
                    },
                },
                .hermit => .{
                    .semver = .{
                        .min = .{ .major = 0, .minor = 8, .patch = 0 },
                        .max = .{ .major = 0, .minor = 13, .patch = 2 },
                    },
                },

                .hurd => .{
                    .hurd = .{
                        .range = .{
                            .min = .{ .major = 0, .minor = 9, .patch = 0 },
                            .max = .{ .major = 0, .minor = 9, .patch = 0 },
                        },
                        .glibc = .{ .major = 2, .minor = 31, .patch = 0 },
                    },
                },
                .linux => .{
                    .linux = .{
                        .range = .{
                            .min = blk: {
                                const default_min: std.SemanticVersion = .{ .major = 5, .minor = 10, .patch = 0 };

                                for (std.zig.target.available_libcs) |libc| {
                                    if (libc.arch != arch or libc.os != tag or libc.abi != abi) continue;

                                    if (libc.os_ver) |min| {
                                        if (min.order(default_min) == .gt) break :blk min;
                                    }
                                }

                                break :blk default_min;
                            },
                            .max = .{ .major = 7, .minor = 2, .patch = 0 },
                        },
                        .glibc = blk: {
                            // For 32-bit targets that traditionally used 32-bit time, we require
                            // glibc 2.34 for full 64-bit time support. For everything else, we only
                            // require glibc 2.31.
                            const default_min: std.SemanticVersion = switch (arch) {
                                .arm,
                                .armeb,
                                .csky,
                                .m68k,
                                .mips,
                                .mipsel,
                                .powerpc,
                                .sparc,
                                .x86,
                                => .{ .major = 2, .minor = 34, .patch = 0 },
                                .mips64,
                                .mips64el,
                                => if (abi == .gnuabin32)
                                    .{ .major = 2, .minor = 34, .patch = 0 }
                                else
                                    .{ .major = 2, .minor = 31, .patch = 0 },
                                else => .{ .major = 2, .minor = 31, .patch = 0 },
                            };

                            for (std.zig.target.available_libcs) |libc| {
                                if (libc.os != tag or libc.arch != arch or libc.abi != abi) continue;

                                if (libc.glibc_min) |min| {
                                    if (min.order(default_min) == .gt) break :blk min;
                                }
                            }

                            break :blk default_min;
                        },
                        .android = switch (arch) {
                            .riscv64 => 35,
                            else => 29,
                        },
                    },
                },
                .rtems => .{
                    .semver = .{
                        .min = .{ .major = 5, .minor = 3, .patch = 0 },
                        .max = .{ .major = 6, .minor = 2, .patch = 0 },
                    },
                },

                .dragonfly => .{
                    .semver = .{
                        .min = .{ .major = 6, .minor = 4, .patch = 0 },
                        .max = .{ .major = 6, .minor = 4, .patch = 2 },
                    },
                },
                .freebsd => .{
                    .semver = .{
                        .min = blk: {
                            const default_min: std.SemanticVersion = .{ .major = 14, .minor = 0, .patch = 0 };

                            for (std.zig.target.available_libcs) |libc| {
                                if (libc.arch != arch or libc.os != tag or libc.abi != abi) continue;

                                if (libc.os_ver) |min| {
                                    if (min.order(default_min) == .gt) break :blk min;
                                }
                            }

                            break :blk default_min;
                        },
                        .max = .{ .major = 15, .minor = 1, .patch = 0 },
                    },
                },
                .netbsd => .{
                    .semver = .{
                        .min = blk: {
                            const default_min: std.SemanticVersion = .{ .major = 10, .minor = 1, .patch = 0 };

                            for (std.zig.target.available_libcs) |libc| {
                                if (libc.arch != arch or libc.os != tag or libc.abi != abi) continue;

                                if (libc.os_ver) |min| {
                                    if (min.order(default_min) == .gt) break :blk min;
                                }
                            }

                            break :blk default_min;
                        },
                        .max = .{ .major = 11, .minor = 0, .patch = 0 },
                    },
                },
                .openbsd => .{
                    .semver = .{
                        .min = blk: {
                            const default_min: std.SemanticVersion = .{ .major = 7, .minor = 8, .patch = 0 };

                            for (std.zig.target.available_libcs) |libc| {
                                if (libc.arch != arch or libc.os != tag or libc.abi != abi) continue;

                                if (libc.os_ver) |min| {
                                    if (min.order(default_min) == .gt) break :blk min;
                                }
                            }

                            break :blk default_min;
                        },
                        .max = .{ .major = 7, .minor = 9, .patch = 0 },
                    },
                },

                .driverkit => .{
                    .semver = .{
                        .min = .{ .major = 21, .minor = 0, .patch = 0 },
                        .max = .{ .major = 27, .minor = 0, .patch = 0 },
                    },
                },
                .macos => .{
                    .semver = .{
                        .min = .{ .major = 15, .minor = 0, .patch = 0 },
                        .max = .{ .major = 27, .minor = 0, .patch = 0 },
                    },
                },
                .ios, .maccatalyst => .{
                    .semver = .{
                        .min = .{ .major = 18, .minor = 0, .patch = 0 },
                        .max = .{ .major = 27, .minor = 0, .patch = 0 },
                    },
                },
                .tvos => .{
                    .semver = .{
                        .min = .{ .major = 26, .minor = 0, .patch = 0 },
                        .max = .{ .major = 27, .minor = 0, .patch = 0 },
                    },
                },
                .visionos => .{
                    .semver = .{
                        .min = .{ .major = 27, .minor = 0, .patch = 0 },
                        .max = .{ .major = 27, .minor = 0, .patch = 0 },
                    },
                },
                .watchos => .{
                    .semver = .{
                        .min = .{ .major = 11, .minor = 0, .patch = 0 },
                        .max = .{ .major = 27, .minor = 0, .patch = 0 },
                    },
                },

                .windows => .{
                    .windows = .{
                        .min = .win10,
                        .max = WindowsVersion.latest,
                    },
                },
                .uefi => .{
                    .semver = .{
                        .min = .{ .major = 2, .minor = 0, .patch = 0 },
                        .max = .{ .major = 2, .minor = 11, .patch = 0 },
                    },
                },

                .@"3ds" => .{
                    .semver = .{
                        // These signify release versions (https://www.3dbrew.org/wiki/NCCH/Extended_Header#ARM11_Kernel_Capabilities)
                        // which are different from user-facing system versions (https://www.3dbrew.org/wiki/Home_Menu#System_Versions_List).
                        //
                        // Multiple system versions could refer to the same release version.
                        // The comment indicates the system version that release version was introduced (for minimum) and the latest (for maximum).
                        .min = .{ .major = 2, .minor = 27, .patch = 0 }, // 1.0.0-0
                        .max = .{ .major = 2, .minor = 58, .patch = 0 }, // 11.17.0-50
                    },
                },

                .wiiu => .{
                    .semver = .{
                        .min = .{ .major = 5, .minor = 5, .patch = 5 }, // Latest global release
                        .max = .{ .major = 5, .minor = 5, .patch = 6 }, // Latest US only release
                    },
                },

                .@"switch" => .{
                    .semver = .{
                        .min = .{ .major = 1, .minor = 0, .patch = 0 },
                        .max = .{ .major = 22, .minor = 5, .patch = 0 },
                    },
                },

                .psp => .{
                    .semver = .{
                        // https://www.psdevwiki.com/psp/Official_Firmware_(OFW)#1.XX_Kernel
                        // It appears that the kernel started with semver for 1.XX before later changing to MAJ.MINPATCH in later releases (e.g. 3.60, 6.61)
                        .min = .{ .major = 1, .minor = 0, .patch = 3 },
                        .max = .{ .major = 6, .minor = 61, .patch = 0 },
                    },
                },

                .vita => .{
                    .semver = .{
                        // 1.3 is the first public release
                        .min = .{ .major = 1, .minor = 3, .patch = 0 },
                        .max = .{ .major = 3, .minor = 60, .patch = 0 },
                    },
                },

                .wasi => .{
                    .semver = .{
                        .min = .{ .major = 0, .minor = 1, .patch = 0 },
                        .max = .{ .major = 0, .minor = 3, .patch = 0 },
                    },
                },

                .amdhsa => .{
                    .semver = .{
                        .min = .{ .major = 6, .minor = 1, .patch = 0 },
                        .max = .{ .major = 7, .minor = 2, .patch = 3 },
                    },
                },
                .amdpal => .{
                    .semver = .{
                        .min = .{ .major = 1, .minor = 1, .patch = 0 },
                        .max = .{ .major = 3, .minor = 5, .patch = 0 },
                    },
                },
                .cuda => .{
                    .semver = .{
                        .min = .{ .major = 12, .minor = 5, .patch = 0 },
                        .max = .{ .major = 13, .minor = 2, .patch = 0 },
                    },
                },
                .nvcl,
                .opencl,
                => .{
                    .semver = .{
                        .min = .{ .major = 2, .minor = 2, .patch = 0 },
                        .max = .{ .major = 3, .minor = 0, .patch = 19 },
                    },
                },
                .opengl => .{
                    .semver = .{
                        .min = .{ .major = 4, .minor = 5, .patch = 0 },
                        .max = .{ .major = 4, .minor = 6, .patch = 0 },
                    },
                },
                .tios => .{
                    .semver = .{
                        .min = .{ .major = 5, .minor = 0, .patch = 0 },
                        .max = .{ .major = 5, .minor = 8, .patch = 4 },
                    },
                },
                .vulkan => .{
                    .semver = .{
                        .min = .{ .major = 1, .minor = 2, .patch = 0 },
                        .max = .{ .major = 1, .minor = 4, .patch = 352 },
                    },
                },
            };
        }
    };

    pub const TaggedVersionRange = union(enum) {
        none: void,
        semver: std.SemanticVersion.Range,
        hurd: HurdVersionRange,
        linux: LinuxVersionRange,
        windows: WindowsVersion.Range,

        pub fn gnuLibCVersion(range: TaggedVersionRange) ?std.SemanticVersion {
            return switch (range) {
                .none, .semver, .windows => null,
                .hurd => |h| h.glibc,
                .linux => |l| l.glibc,
            };
        }
    };

    /// Provides a tagged union. `Target` does not store the tag because it is
    /// redundant with the OS tag; this function abstracts that part away.
    pub inline fn versionRange(os: Os) TaggedVersionRange {
        return switch (os.tag.versionRangeTag()) {
            .none => .{ .none = {} },
            .semver => .{ .semver = os.version_range.semver },
            .hurd => .{ .hurd = os.version_range.hurd },
            .linux => .{ .linux = os.version_range.linux },
            .windows => .{ .windows = os.version_range.windows },
        };
    }

    /// Checks if system is guaranteed to be at least `version` or older than `version`.
    /// Returns `null` if a runtime check is required.
    pub inline fn isAtLeast(os: Os, comptime tag: Tag, ver: switch (tag.versionRangeTag()) {
        .none => void,
        .semver, .hurd, .linux => std.SemanticVersion,
        .windows => WindowsVersion,
    }) ?bool {
        return if (os.tag != tag) false else switch (tag.versionRangeTag()) {
            .none => true,
            inline .semver,
            .hurd,
            .linux,
            .windows,
            => |field| @field(os.version_range, @tagName(field)).isAtLeast(ver),
        };
    }
};

pub const aarch64 = @import("Target/aarch64.zig");
pub const alpha = @import("Target/alpha.zig");
pub const amdgcn = @import("Target/amdgcn.zig");
pub const arc = @import("Target/arc.zig");
pub const arm = @import("Target/arm.zig");
pub const avr = @import("Target/avr.zig");
pub const bpf = @import("Target/bpf.zig");
pub const csky = @import("Target/csky.zig");
pub const hexagon = @import("Target/hexagon.zig");
pub const hppa = @import("Target/hppa.zig");
pub const kalimba = @import("Target/generic.zig");
pub const kvx = @import("Target/kvx.zig");
pub const lanai = @import("Target/lanai.zig");
pub const loongarch = @import("Target/loongarch.zig");
pub const m68k = @import("Target/m68k.zig");
pub const m88k = @import("Target/generic.zig");
pub const microblaze = @import("Target/generic.zig");
pub const mips = @import("Target/mips.zig");
pub const msp430 = @import("Target/msp430.zig");
pub const nvptx = @import("Target/nvptx.zig");
pub const or1k = @import("Target/generic.zig");
pub const powerpc = @import("Target/powerpc.zig");
pub const propeller = @import("Target/propeller.zig");
pub const riscv = @import("Target/riscv.zig");
pub const s390x = @import("Target/s390x.zig");
pub const sh = @import("Target/generic.zig");
pub const sparc = @import("Target/sparc.zig");
pub const spirv = @import("Target/spirv.zig");
pub const spork8 = @import("Target/generic.zig");
pub const ve = @import("Target/ve.zig");
pub const wasm = @import("Target/wasm.zig");
pub const x86 = @import("Target/x86.zig");
pub const xcore = @import("Target/xcore.zig");
pub const xtensa = @import("Target/xtensa.zig");
pub const z80 = @import("Target/generic.zig");

pub const Abi = enum {
    none,
    gnu,
    gnuabin32,
    gnuabi64,
    gnueabi,
    gnueabihf,
    gnuf32,
    gnusf,
    gnux32,
    eabi,
    eabihf,
    abin32,
    x32,
    ilp32,
    android,
    androideabi,
    musl,
    muslabin32,
    muslabi64,
    musleabi,
    musleabihf,
    muslf32,
    muslsf,
    muslx32,
    msvc,
    itanium,
    simulator,
    ohos,
    ohoseabi,
    call0,

    pub fn default(arch: Cpu.Arch, os_tag: Os.Tag) Abi {
        return switch (os_tag) {
            .freestanding, .other => switch (arch) {
                // Soft float is usually a sane default for freestanding.
                .arm,
                .armeb,
                .csky,
                .hppa,
                .mips,
                .mipsel,
                .powerpc,
                .powerpcle,
                .sh,
                .sheb,
                .thumb,
                .thumbeb,
                => .eabi,
                else => .none,
            },
            .fuchsia => switch (arch) {
                .arm,
                .thumb,
                => .eabihf,
                else => .none,
            },
            .haiku => switch (arch) {
                .arm => .eabihf,
                else => .none,
            },
            .hurd => .gnu,
            .linux => switch (arch) {
                .arm,
                .armeb,
                .powerpc,
                .powerpcle,
                .thumb,
                .thumbeb,
                => .musleabihf,
                .mips,
                .mipsel,
                => .musleabi,
                .mips64,
                .mips64el,
                => .muslabi64,

                // No musl support.
                .alpha,
                .arc,
                .arceb,
                .or1k,
                .sparc,
                .sparc64,
                => .gnu,
                .csky,
                => .gnueabi,
                .hppa,
                .sh,
                .sheb,
                => .gnueabihf,

                // No glibc or musl support.
                .xtensa,
                .xtensaeb,
                => .none,

                else => .musl,
            },
            .rtems => switch (arch) {
                .arm,
                .armeb,
                .thumb,
                .thumbeb,
                .mips,
                .mipsel,
                => .eabi,
                .powerpc,
                => .eabihf,
                else => .none,
            },
            .freebsd => switch (arch) {
                .arm,
                => .eabihf,
                else => .none,
            },
            .netbsd => switch (arch) {
                .arm,
                .armeb,
                .powerpc,
                => .eabihf,
                // Soft float tends to be more common for MIPS.
                .mips,
                .mipsel,
                => .eabi,
                else => .none,
            },
            .openbsd => switch (arch) {
                .arm,
                => .eabi,
                .powerpc,
                => .eabihf,
                else => .none,
            },
            .windows => .gnu,
            .uefi => .msvc,
            .@"3ds" => .eabihf,
            .wiiu => .eabihf,
            .gba => .eabi,
            .psx => .eabi,
            .psp => .eabihf,
            .vita => .eabihf,
            .wasi, .emscripten => .musl,

            .ashetos => .eabi,

            .contiki,
            .hermit,
            .illumos,
            .managarm,
            .plan9,
            .serenity,
            .dragonfly,
            .driverkit,
            .ios,
            .maccatalyst,
            .macos,
            .tvos,
            .visionos,
            .watchos,
            .@"switch",
            .ps3,
            .ps4,
            .ps5,
            .amdhsa,
            .amdpal,
            .cuda,
            .mesa3d,
            .nvcl,
            .opencl,
            .opengl,
            .vulkan,
            .tios,
            => .none,
        };
    }

    pub inline fn isGnu(abi: Abi) bool {
        return switch (abi) {
            .gnu,
            .gnuabin32,
            .gnuabi64,
            .gnueabi,
            .gnueabihf,
            .gnuf32,
            .gnusf,
            .gnux32,
            => true,
            else => false,
        };
    }

    pub inline fn isMusl(abi: Abi) bool {
        return switch (abi) {
            .musl,
            .muslabin32,
            .muslabi64,
            .musleabi,
            .musleabihf,
            .muslf32,
            .muslsf,
            .muslx32,
            => true,
            else => abi.isOpenHarmony(),
        };
    }

    pub inline fn isOpenHarmony(abi: Abi) bool {
        return switch (abi) {
            .ohos, .ohoseabi => true,
            else => false,
        };
    }

    pub inline fn isAndroid(abi: Abi) bool {
        return switch (abi) {
            .android, .androideabi => true,
            else => false,
        };
    }

    pub const Float = enum {
        hard,
        soft,
    };

    pub inline fn float(abi: Abi) Float {
        return switch (abi) {
            .androideabi,
            .eabi,
            .gnueabi,
            .musleabi,
            .gnusf,
            .muslsf,
            .ohoseabi,
            => .soft,
            else => .hard,
        };
    }
};

pub const ObjectFormat = enum {
    /// C source code.
    c,
    /// The Common Object File Format used by Windows and UEFI.
    coff,
    /// The Executable and Linkable Format used by many Unixes.
    elf,
    /// The Intel HEX format for storing binary code in ASCII text.
    hex,
    /// The Mach object format used by macOS and other Apple platforms.
    macho,
    /// The a.out format used by Plan 9 from Bell Labs.
    plan9,
    /// Machine code with no metadata.
    raw,
    /// The Khronos Group's Standard Portable Intermediate Representation V.
    spirv,
    /// The WebAssembly binary format.
    wasm,

    pub fn fileExt(of: ObjectFormat, arch: Cpu.Arch) [:0]const u8 {
        return switch (of) {
            .c => ".c",
            .coff => ".obj",
            .elf, .macho, .wasm => ".o",
            .hex => ".ihex",
            .plan9 => arch.plan9Ext(),
            .raw => ".bin",
            .spirv => ".spv",
        };
    }

    pub fn default(os_tag: Os.Tag, arch: Cpu.Arch) ObjectFormat {
        return switch (os_tag) {
            .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => .macho,
            .plan9 => .plan9,
            .uefi, .windows => .coff,
            else => switch (arch) {
                .spirv32, .spirv64 => .spirv,
                .wasm32, .wasm64 => .wasm,
                .spork8 => .raw,
                else => .elf,
            },
        };
    }
};

pub fn toElfMachine(target: *const Target) std.elf.EM {
    return switch (target.cpu.arch) {
        .aarch64, .aarch64_be => .AARCH64,
        .alpha => .ALPHA,
        .amdgcn => .AMDGPU,
        .arc, .arceb => .ARC_COMPACT2,
        .arm, .armeb, .thumb, .thumbeb => .ARM,
        .avr => .AVR,
        .bpfeb, .bpfel => .BPF,
        .csky => .CSKY,
        .ez80 => .Z80,
        .hexagon => .QDSP6,
        .hppa, .hppa64 => .PARISC,
        .kalimba => .CSR_KALIMBA,
        .kvx => .KVX,
        .lanai => .LANAI,
        .loongarch32, .loongarch64 => .LOONGARCH,
        .m88k => .@"88K",
        .m68k => .@"68K",
        .microblaze, .microblazeel => .MICROBLAZE,
        .mips, .mips64, .mipsel, .mips64el => .MIPS,
        .msp430 => .MSP430,
        .or1k => .OR1K,
        .powerpc, .powerpcle => .PPC,
        .powerpc64, .powerpc64le => .PPC64,
        .propeller => .PROPELLER,
        .riscv32, .riscv32be, .riscv64, .riscv64be => .RISCV,
        .s390x => .S390,
        .sh, .sheb => .SH,
        .sparc => if (target.cpu.hasAny(.sparc, &.{ .v8plus, .v9 })) .SPARC32PLUS else .SPARC,
        .sparc64 => .SPARCV9,
        .ve => .VE,
        .x86_16, .x86 => .@"386",
        .x86_64 => .X86_64,
        .xcore => .XCORE,
        .xtensa, .xtensaeb => .XTENSA,

        .nvptx,
        .nvptx64,
        .spirv32,
        .spirv64,
        .wasm32,
        .wasm64,
        .spork8,
        => .NONE,
    };
}

pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE {
    return switch (target.cpu.arch) {
        .alpha => .ALPHA64,
        .arm => .ARM,
        .thumb => .ARMNT,
        .aarch64 => .ARM64,
        .loongarch32 => .LOONGARCH32,
        .loongarch64 => .LOONGARCH64,
        .mips => .R3000BE,
        .mipsel => .R3000,
        .mips64el => .R4000,
        .powerpcle => .POWERPC,
        .riscv32 => .RISCV32,
        .riscv64 => .RISCV64,
        .sh => .SH3,
        .x86 => .I386,
        .x86_64 => .AMD64,

        .aarch64_be,
        .amdgcn,
        .arc,
        .arceb,
        .armeb,
        .avr,
        .bpfeb,
        .bpfel,
        .csky,
        .ez80,
        .hexagon,
        .hppa,
        .hppa64,
        .kalimba,
        .kvx,
        .lanai,
        .m88k,
        .m68k,
        .microblaze,
        .microblazeel,
        .mips64,
        .msp430,
        .nvptx,
        .nvptx64,
        .or1k,
        .powerpc,
        .powerpc64,
        .powerpc64le,
        .propeller,
        .riscv32be,
        .riscv64be,
        .s390x,
        .sheb,
        .sparc,
        .sparc64,
        .spirv32,
        .spirv64,
        .thumbeb,
        .ve,
        .wasm32,
        .wasm64,
        .x86_16,
        .xcore,
        .xtensa,
        .xtensaeb,
        .spork8,
        => .UNKNOWN,
    };
}

pub const Cpu = struct {
    /// Architecture
    arch: Arch,

    /// The CPU model to target. It has a set of features
    /// which are overridden with the `features` field.
    model: *const Model,

    /// An explicit list of the entire CPU feature set. It may differ from the specific CPU model's features.
    features: Feature.Set,

    pub const Feature = struct {
        /// The bit index into `Set`. Has a default value of `undefined` because the canonical
        /// structures are populated via comptime logic.
        index: Set.Index = undefined,

        /// Has a default value of `undefined` because the canonical
        /// structures are populated via comptime logic.
        name: []const u8 = undefined,

        /// If this corresponds to an LLVM-recognized feature, this will be populated;
        /// otherwise null.
        llvm_name: ?[:0]const u8,

        /// Human-friendly UTF-8 text.
        description: []const u8,

        /// Sparse `Set` of features this depends on.
        dependencies: Set,

        /// A bit set of all the features.
        pub const Set = struct {
            ints: [usize_count]usize,

            pub const needed_bit_count = 347;
            pub const byte_count = @divCeil(needed_bit_count, 8);
            pub const usize_count = (byte_count + (@sizeOf(usize) - 1)) / @sizeOf(usize);
            pub const Index = std.math.Log2Int(@Int(.unsigned, usize_count * @bitSizeOf(usize)));
            pub const ShiftInt = std.math.Log2Int(usize);

            pub const empty: Set = .{ .ints = @splat(0) };

            pub fn isEmpty(set: Set) bool {
                return for (set.ints) |x| {
                    if (x != 0) break false;
                } else true;
            }

            pub fn count(set: Set) std.math.IntFittingRange(0, needed_bit_count) {
                var sum: usize = 0;
                for (set.ints) |x| sum += @popCount(x);
                return @intCast(sum);
            }

            pub fn isEnabled(set: Set, arch_feature_index: Index) bool {
                const usize_index = arch_feature_index / @bitSizeOf(usize);
                const bit_index: ShiftInt = @intCast(arch_feature_index % @bitSizeOf(usize));
                return (set.ints[usize_index] & (@as(usize, 1) << bit_index)) != 0;
            }

            /// Adds the specified feature but not its dependencies.
            pub fn addFeature(set: *Set, arch_feature_index: Index) void {
                const usize_index = arch_feature_index / @bitSizeOf(usize);
                const bit_index: ShiftInt = @intCast(arch_feature_index % @bitSizeOf(usize));
                set.ints[usize_index] |= @as(usize, 1) << bit_index;
            }

            /// Adds the specified feature set but not its dependencies.
            pub fn addFeatureSet(set: *Set, other_set: Set) void {
                set.ints = @as(@Vector(usize_count, usize), set.ints) | @as(@Vector(usize_count, usize), other_set.ints);
            }

            /// Removes the specified feature but not its dependents.
            pub fn removeFeature(set: *Set, arch_feature_index: Index) void {
                const usize_index = arch_feature_index / @bitSizeOf(usize);
                const bit_index: ShiftInt = @intCast(arch_feature_index % @bitSizeOf(usize));
                set.ints[usize_index] &= ~(@as(usize, 1) << bit_index);
            }

            /// Removes the specified feature but not its dependents.
            pub fn removeFeatureSet(set: *Set, other_set: Set) void {
                set.ints = @as(@Vector(usize_count, usize), set.ints) & ~@as(@Vector(usize_count, usize), other_set.ints);
            }

            pub fn populateDependencies(set: *Set, all_features_list: []const Cpu.Feature) void {
                @setEvalBranchQuota(1000000);

                var old = set.ints;
                while (true) {
                    for (all_features_list, 0..) |feature, index_usize| {
                        const index: Index = @intCast(index_usize);
                        if (set.isEnabled(index)) {
                            set.addFeatureSet(feature.dependencies);
                        }
                    }
                    const nothing_changed = std.mem.eql(usize, &old, &set.ints);
                    if (nothing_changed) return;
                    old = set.ints;
                }
            }

            pub fn asBytes(set: *const Set) *const [byte_count]u8 {
                return std.mem.sliceAsBytes(&set.ints)[0..byte_count];
            }

            pub fn eql(set: Set, other_set: Set) bool {
                return std.mem.eql(usize, &set.ints, &other_set.ints);
            }

            pub fn isSuperSetOf(set: Set, other_set: Set) bool {
                const V = @Vector(usize_count, usize);
                const set_v: V = set.ints;
                const other_v: V = other_set.ints;
                return @reduce(.And, (set_v & other_v) == other_v);
            }
        };

        pub fn FeatureSetFns(comptime F: type) type {
            return struct {
                /// Populates only the feature bits specified.
                pub fn featureSet(features: []const F) Set {
                    var x = Set.empty;
                    for (features) |feature| {
                        x.addFeature(@backingInt(feature));
                    }
                    return x;
                }

                /// Returns true if the specified feature is enabled.
                pub fn featureSetHas(set: Set, feature: F) bool {
                    return set.isEnabled(@backingInt(feature));
                }

                /// Returns true if any specified feature is enabled.
                pub fn featureSetHasAny(set: Set, features: anytype) bool {
                    inline for (features) |feature| {
                        if (set.isEnabled(@backingInt(@as(F, feature)))) return true;
                    }
                    return false;
                }

                /// Returns true if every specified feature is enabled.
                pub fn featureSetHasAll(set: Set, features: anytype) bool {
                    inline for (features) |feature| {
                        if (!set.isEnabled(@backingInt(@as(F, feature)))) return false;
                    }
                    return true;
                }
            };
        }
    };

    pub const Arch = enum {
        aarch64,
        aarch64_be,
        alpha,
        amdgcn,
        arc,
        arceb,
        arm,
        armeb,
        avr,
        bpfeb,
        bpfel,
        csky,
        ez80,
        hexagon,
        hppa,
        hppa64,
        kalimba,
        kvx,
        lanai,
        loongarch32,
        loongarch64,
        m68k,
        m88k,
        microblaze,
        microblazeel,
        mips,
        mipsel,
        mips64,
        mips64el,
        msp430,
        nvptx,
        nvptx64,
        or1k,
        powerpc,
        powerpcle,
        powerpc64,
        powerpc64le,
        propeller,
        riscv32,
        riscv32be,
        riscv64,
        riscv64be,
        s390x,
        sh,
        sheb,
        sparc,
        sparc64,
        spork8,
        spirv32,
        spirv64,
        thumb,
        thumbeb,
        ve,
        wasm32,
        wasm64,
        x86_16,
        x86,
        x86_64,
        xcore,
        xtensa,
        xtensaeb,

        /// An architecture family can encompass multiple architectures as represented by `Arch`.
        /// For a given family tag, it is guaranteed that an `std.Target.<tag>` namespace exists
        /// containing CPU model and feature data.
        pub const Family = enum {
            aarch64,
            alpha,
            amdgcn,
            arc,
            arm,
            avr,
            bpf,
            csky,
            hexagon,
            hppa,
            kalimba,
            kvx,
            lanai,
            loongarch,
            m68k,
            m88k,
            microblaze,
            mips,
            msp430,
            nvptx,
            or1k,
            powerpc,
            propeller,
            riscv,
            s390x,
            sh,
            sparc,
            spirv,
            ve,
            wasm,
            x86,
            xcore,
            xtensa,
            z80,
            spork8,
        };

        pub inline fn family(arch: Arch) Family {
            return switch (arch) {
                .aarch64, .aarch64_be => .aarch64,
                .alpha => .alpha,
                .amdgcn => .amdgcn,
                .arc, .arceb => .arc,
                .arm, .armeb, .thumb, .thumbeb => .arm,
                .avr => .avr,
                .bpfeb, .bpfel => .bpf,
                .csky => .csky,
                .ez80 => .z80,
                .hexagon => .hexagon,
                .hppa, .hppa64 => .hppa,
                .kalimba => .kalimba,
                .kvx => .kvx,
                .lanai => .lanai,
                .loongarch32, .loongarch64 => .loongarch,
                .m68k => .m68k,
                .m88k => .m88k,
                .microblaze, .microblazeel => .microblaze,
                .mips, .mipsel, .mips64, .mips64el => .mips,
                .msp430 => .msp430,
                .or1k => .or1k,
                .nvptx, .nvptx64 => .nvptx,
                .powerpc, .powerpcle, .powerpc64, .powerpc64le => .powerpc,
                .propeller => .propeller,
                .riscv32, .riscv32be, .riscv64, .riscv64be => .riscv,
                .s390x => .s390x,
                .sh, .sheb => .sh,
                .sparc, .sparc64 => .sparc,
                .spirv32, .spirv64 => .spirv,
                .ve => .ve,
                .wasm32, .wasm64 => .wasm,
                .x86_16, .x86, .x86_64 => .x86,
                .xcore => .xcore,
                .xtensa, .xtensaeb => .xtensa,
                .spork8 => .spork8,
            };
        }

        pub inline fn isX86(arch: Arch) bool {
            return switch (arch) {
                .x86_16, .x86, .x86_64 => true,
                else => false,
            };
        }

        /// Note that this includes Thumb.
        pub inline fn isArm(arch: Arch) bool {
            return switch (arch) {
                .arm, .armeb => true,
                else => arch.isThumb(),
            };
        }

        pub inline fn isThumb(arch: Arch) bool {
            return switch (arch) {
                .thumb, .thumbeb => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Use `isAarch64` instead.
        pub const isAARCH64 = isAarch64;

        pub inline fn isAarch64(arch: Arch) bool {
            return switch (arch) {
                .aarch64, .aarch64_be => true,
                else => false,
            };
        }

        pub inline fn isArc(arch: Arch) bool {
            return switch (arch) {
                .arc, .arceb => true,
                else => false,
            };
        }

        pub inline fn isHppa(arch: Arch) bool {
            return switch (arch) {
                .hppa, .hppa64 => true,
                else => false,
            };
        }

        pub inline fn isWasm(arch: Arch) bool {
            return switch (arch) {
                .wasm32, .wasm64 => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Use `isLoongarch` instead.
        pub const isLoongArch = isLoongarch;

        pub inline fn isLoongarch(arch: Arch) bool {
            return switch (arch) {
                .loongarch32, .loongarch64 => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Use `isRiscv` instead.
        pub const isRISCV = isRiscv;

        pub inline fn isRiscv(arch: Arch) bool {
            return arch.isRiscv32() or arch.isRiscv64();
        }

        pub inline fn isRiscv32(arch: Arch) bool {
            return switch (arch) {
                .riscv32, .riscv32be => true,
                else => false,
            };
        }

        pub inline fn isRiscv64(arch: Arch) bool {
            return switch (arch) {
                .riscv64, .riscv64be => true,
                else => false,
            };
        }

        pub inline fn isMicroblaze(arch: Arch) bool {
            return switch (arch) {
                .microblaze, .microblazeel => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Use `isMips` instead.
        pub const isMIPS = isMips;

        pub inline fn isMips(arch: Arch) bool {
            return arch.isMips32() or arch.isMips64();
        }

        /// Deprecated; to be removed in 0.18.0. Use `isMips32` instead.
        pub const isMIPS32 = isMips32;

        pub inline fn isMips32(arch: Arch) bool {
            return switch (arch) {
                .mips, .mipsel => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Use `isMips64` instead.
        pub const isMIPS64 = isMips64;

        pub inline fn isMips64(arch: Arch) bool {
            return switch (arch) {
                .mips64, .mips64el => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Use `isPowerpc` instead.
        pub const isPowerPC = isPowerpc;

        pub inline fn isPowerpc(arch: Arch) bool {
            return arch.isPowerpc32() or arch.isPowerpc64();
        }

        /// Deprecated; to be removed in 0.18.0. Use `isPowerpc32` instead.
        pub const isPowerPC32 = isPowerpc32;

        pub inline fn isPowerpc32(arch: Arch) bool {
            return switch (arch) {
                .powerpc, .powerpcle => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Use `isPowerpc64` instead.
        pub const isPowerPC64 = isPowerpc64;

        pub inline fn isPowerpc64(arch: Arch) bool {
            return switch (arch) {
                .powerpc64, .powerpc64le => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Use `isSparc` instead.
        pub const isSPARC = isSparc;

        pub inline fn isSparc(arch: Arch) bool {
            return switch (arch) {
                .sparc, .sparc64 => true,
                else => false,
            };
        }

        /// Deprecated; to be removed in 0.18.0. Use `isSpirv` instead.
        pub const isSpirV = isSpirv;

        pub inline fn isSpirv(arch: Arch) bool {
            return switch (arch) {
                .spirv32, .spirv64 => true,
                else => false,
            };
        }

        pub inline fn isSh(arch: Arch) bool {
            return switch (arch) {
                .sh, .sheb => true,
                else => false,
            };
        }

        pub inline fn isBpf(arch: Arch) bool {
            return switch (arch) {
                .bpfel, .bpfeb => true,
                else => false,
            };
        }

        pub inline fn isNvptx(arch: Arch) bool {
            return switch (arch) {
                .nvptx, .nvptx64 => true,
                else => false,
            };
        }

        pub inline fn isXtensa(arch: Arch) bool {
            return switch (arch) {
                .xtensa, .xtensaeb => true,
                else => false,
            };
        }

        pub fn parseCpuModel(arch: Arch, cpu_name: []const u8) ?*const Cpu.Model {
            for (arch.allCpuModels()) |cpu| {
                if (std.mem.eql(u8, cpu_name, cpu.name)) {
                    return cpu;
                }
            }
            return null;
        }

        pub fn endian(arch: Arch) std.builtin.Endian {
            return switch (arch) {
                .aarch64,
                .alpha,
                .arm,
                .arc,
                .avr,
                .bpfel,
                .csky,
                .hexagon,
                .kalimba,
                .kvx,
                .loongarch32,
                .loongarch64,
                .microblazeel,
                .mipsel,
                .mips64el,
                .msp430,
                .powerpcle,
                .powerpc64le,
                .propeller,
                .riscv32,
                .riscv64,
                .sh,
                .thumb,
                .ve,
                .wasm32,
                .wasm64,
                .x86_16,
                .x86,
                .x86_64,
                .xcore,
                .xtensa,
                .ez80,
                => .little,

                .aarch64_be,
                .arceb,
                .armeb,
                .bpfeb,
                .hppa,
                .hppa64,
                .lanai,
                .m68k,
                .m88k,
                .microblaze,
                .mips,
                .mips64,
                .or1k,
                .powerpc,
                .powerpc64,
                .riscv32be,
                .riscv64be,
                .s390x,
                .sheb,
                .thumbeb,
                .sparc,
                .sparc64,
                .xtensaeb,
                .spork8,
                => .big,

                // GPU endianness is opaque. For now, assume little endian.
                .amdgcn,
                .nvptx,
                .nvptx64,
                .spirv32,
                .spirv64,
                => .little,
            };
        }

        /// All CPU features Zig is aware of, sorted lexicographically by name.
        pub fn allFeaturesList(arch: Arch) []const Cpu.Feature {
            return switch (arch.family()) {
                inline else => |f| &@field(Target, @tagName(f)).all_features,
            };
        }

        /// All processors Zig is aware of, sorted lexicographically by name.
        pub fn allCpuModels(arch: Arch) []const *const Cpu.Model {
            return switch (arch.family()) {
                inline else => |f| comptime allCpusFromDecls(@field(Target, @tagName(f)).cpu),
            };
        }

        fn allCpusFromDecls(comptime cpus: type) []const *const Cpu.Model {
            @setEvalBranchQuota(2000);
            const decl_names = @typeInfo(cpus).@"struct".decl_names;
            var array: [decl_names.len]*const Cpu.Model = undefined;
            for (decl_names, 0..) |decl_name, i| {
                array[i] = &@field(cpus, decl_name);
            }
            const finalized = array;
            return &finalized;
        }

        /// 0c spim    little-endian MIPS 3000 family
        /// 1c 68000   Motorola MC68000
        /// 2c 68020   Motorola MC68020
        /// 5c arm     little-endian ARM
        /// 6c amd64   AMD64 and compatibles (e.g., Intel EM64T)
        /// 7c arm64   ARM64 (ARMv8)
        /// 8c 386     Intel x86, i486, Pentium, etc.
        /// kc sparc   Sun SPARC
        /// qc power   Power PC
        /// vc mips    big-endian MIPS 3000 family
        pub fn plan9Ext(arch: Cpu.Arch) [:0]const u8 {
            return switch (arch) {
                .arm => ".5",
                .x86_64 => ".6",
                .aarch64 => ".7",
                .x86 => ".8",
                .sparc => ".k",
                .powerpc, .powerpcle => ".q",
                .mips, .mipsel => ".v",
                // ISAs without designated characters get 'X' for lack of a better option.
                else => ".X",
            };
        }

        /// Returns the array of `Arch` to which a specific `std.builtin.CallingConvention` applies.
        /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
        pub fn fromCallingConvention(cc: std.builtin.CallingConvention.Tag) []const Arch {
            return switch (cc) {
                .auto,
                .async,
                .naked,
                .@"inline",
                => unreachable,

                .x86_64_sysv,
                .x86_64_x32,
                .x86_64_win,
                .x86_64_regcall_v3_sysv,
                .x86_64_regcall_v4_win,
                .x86_64_vectorcall,
                .x86_64_interrupt,
                .x86_64_preserve_none,
                => &.{.x86_64},

                .x86_sysv,
                .x86_win,
                .x86_mingw,
                .x86_stdcall,
                .x86_fastcall,
                .x86_thiscall,
                .x86_thiscall_mingw,
                .x86_regcall_v3,
                .x86_regcall_v4_win,
                .x86_vectorcall,
                .x86_interrupt,
                => &.{.x86},

                .x86_16_cdecl,
                .x86_16_stdcall,
                .x86_16_regparmcall,
                .x86_16_interrupt,
                => &.{.x86_16},

                .aarch64_aapcs,
                .aarch64_aapcs_darwin,
                .aarch64_aapcs_win,
                .aarch64_vfabi,
                .aarch64_vfabi_sve,
                .aarch64_preserve_none,
                => &.{ .aarch64, .aarch64_be },

                .alpha_osf,
                => &.{.alpha},

                .arm_aapcs,
                .arm_aapcs_vfp,
                .arm_interrupt,
                => &.{ .arm, .armeb, .thumb, .thumbeb },

                .mips64_n64,
                .mips64_n32,
                .mips64_interrupt,
                => &.{ .mips64, .mips64el },

                .mips_o32,
                .mips_interrupt,
                => &.{ .mips, .mipsel },

                .riscv64_lp64,
                .riscv64_lp64_v,
                .riscv64_interrupt,
                => &.{ .riscv64, .riscv64be },

                .riscv32_ilp32,
                .riscv32_ilp32_v,
                .riscv32_interrupt,
                => &.{ .riscv32, .riscv32be },

                .sparc64_sysv,
                => &.{.sparc64},

                .sparc_sysv,
                => &.{.sparc},

                .powerpc64_elf,
                .powerpc64_elf_altivec,
                .powerpc64_elf_v2,
                => &.{ .powerpc64, .powerpc64le },

                .powerpc_sysv,
                .powerpc_sysv_altivec,
                .powerpc_aix,
                .powerpc_aix_altivec,
                => &.{ .powerpc, .powerpcle },

                .wasm_mvp,
                => &.{ .wasm64, .wasm32 },

                .arc_sysv,
                .arc_interrupt,
                => &.{ .arc, .arceb },

                .avr_gnu,
                .avr_builtin,
                .avr_signal,
                .avr_interrupt,
                => &.{.avr},

                .bpf_std,
                => &.{ .bpfel, .bpfeb },

                .csky_sysv,
                .csky_interrupt,
                => &.{.csky},

                .hexagon_sysv,
                .hexagon_sysv_hvx,
                => &.{.hexagon},

                .hppa_elf,
                => &.{.hppa},

                .hppa64_elf,
                => &.{.hppa64},

                .kvx_lp64,
                .kvx_ilp32,
                => &.{.kvx},

                .lanai_sysv,
                => &.{.lanai},

                .loongarch64_lp64,
                => &.{.loongarch64},

                .loongarch32_ilp32,
                => &.{.loongarch32},

                .m68k_sysv,
                .m68k_gnu,
                .m68k_rtd,
                .m68k_interrupt,
                => &.{.m68k},

                .m88k_sysv,
                => &.{.m88k},

                .microblaze_std,
                .microblaze_interrupt,
                => &.{ .microblaze, .microblazeel },

                .msp430_eabi,
                .msp430_interrupt,
                => &.{.msp430},

                .or1k_sysv,
                => &.{.or1k},

                .propeller_sysv,
                => &.{.propeller},

                .s390x_sysv,
                .s390x_sysv_vx,
                => &.{.s390x},

                .sh_gnu,
                .sh_renesas,
                .sh_interrupt,
                => &.{ .sh, .sheb },

                .ve_sysv,
                => &.{.ve},

                .xcore_xs1,
                .xcore_xs2,
                => &.{.xcore},

                .xtensa_call0,
                .xtensa_windowed,
                => &.{ .xtensa, .xtensaeb },

                .amdgcn_device,
                .amdgcn_kernel,
                .amdgcn_cs,
                => &.{.amdgcn},

                .nvptx_device,
                .nvptx_kernel,
                => &.{ .nvptx, .nvptx64 },

                .spirv_device,
                .spirv_kernel,
                .spirv_fragment,
                .spirv_vertex,
                .spirv_task,
                .spirv_mesh,
                => &.{ .spirv32, .spirv64 },

                .ez80_cet,
                .ez80_tiflags,
                => &.{.ez80},

                .spork8,
                => &.{.spork8},
            };
        }
    };

    pub const Model = struct {
        name: []const u8,
        llvm_name: ?[:0]const u8,
        features: Feature.Set,

        pub fn toCpu(model: *const Model, arch: Arch) Cpu {
            var features = model.features;
            features.populateDependencies(arch.allFeaturesList());
            return .{
                .arch = arch,
                .model = model,
                .features = features,
            };
        }

        /// Returns the most bare-bones CPU model that is valid for `arch`. Note that this function
        /// can return CPU models that are understood by LLVM, but *not* understood by Clang. If
        /// Clang compatibility is important, consider using `baseline` instead.
        pub fn generic(arch: Arch) *const Model {
            return switch (arch) {
                .alpha => &alpha.cpu.ev4,
                .amdgcn => &amdgcn.cpu.gfx600,
                .avr => &avr.cpu.avr1,
                .hppa => &hppa.cpu.ts_1,
                .hppa64 => &hppa.cpu.pa_8000,
                .kvx => &kvx.cpu.coolidge_v1,
                .loongarch32 => &loongarch.cpu.generic_la32,
                .loongarch64 => &loongarch.cpu.generic_la64,
                .mips, .mipsel => &mips.cpu.mips32,
                .mips64, .mips64el => &mips.cpu.mips64,
                .nvptx, .nvptx64 => &nvptx.cpu.sm_20,
                .powerpc, .powerpcle => &powerpc.cpu.ppc,
                .powerpc64, .powerpc64le => &powerpc.cpu.ppc64,
                .propeller => &propeller.cpu.p1,
                .riscv32, .riscv32be => &riscv.cpu.generic_rv32,
                .riscv64, .riscv64be => &riscv.cpu.generic_rv64,
                .sparc64 => &sparc.cpu.v9, // SPARC can only be 64-bit from v9 and up.
                .wasm32, .wasm64 => &wasm.cpu.mvp,
                .x86_16 => &x86.cpu.i86,
                .x86 => &x86.cpu.i386,
                .x86_64 => &x86.cpu.x86_64,
                inline else => |a| &@field(Target, @tagName(a.family())).cpu.generic,
            };
        }

        /// Returns a conservative CPU model for `arch` that is expected to be compatible with the
        /// vast majority of hardware available. This function is guaranteed to return CPU models
        /// that are understood by both LLVM and Clang, unlike `generic`.
        ///
        /// For certain `os` values, this function will additionally bump the baseline higher than
        /// the baseline would be for `arch` in isolation; for example, for `aarch64-macos`, the
        /// baseline is considered to be `apple_m1`. To avoid this behavior entirely, pass
        /// `Os.Tag.freestanding`.
        pub fn baseline(arch: Arch, os: Os) *const Model {
            return switch (arch) {
                .alpha => &alpha.cpu.ev6,
                .amdgcn => &amdgcn.cpu.gfx906,
                .arm => switch (os.tag) {
                    .@"3ds" => &arm.cpu.mpcore,
                    .vita => &arm.cpu.cortex_a9,
                    .gba => &arm.cpu.arm7tdmi,
                    else => &arm.cpu.baseline,
                },
                .thumb => switch (os.tag) {
                    .vita => &arm.cpu.cortex_a9,
                    .gba => &arm.cpu.arm7tdmi,
                    else => &arm.cpu.baseline,
                },
                .armeb, .thumbeb => &arm.cpu.baseline,
                .aarch64 => switch (os.tag) {
                    .haiku => &aarch64.cpu.cortex_a55,
                    .driverkit, .maccatalyst, .macos => &aarch64.cpu.apple_m1,
                    .ios, .tvos => &aarch64.cpu.apple_a7,
                    .visionos => &aarch64.cpu.apple_m2,
                    .watchos => &aarch64.cpu.apple_s4,
                    .@"switch" => &aarch64.cpu.cortex_a57,
                    else => generic(arch),
                },
                .avr => &avr.cpu.avr2,
                .bpfel, .bpfeb => &bpf.cpu.v3,
                .csky => &csky.cpu.ck810, // gcc/clang do not have a generic csky model.
                .hexagon => &hexagon.cpu.hexagonv68, // gcc/clang do not have a generic hexagon model.
                .hppa => &hppa.cpu.pa_7300lc,
                .kvx => &kvx.cpu.coolidge_v2,
                .lanai => &lanai.cpu.v11, // clang does not have a generic lanai model.
                .loongarch32 => &loongarch.cpu.la32v1_0,
                .loongarch64 => &loongarch.cpu.la64v1_0,
                .m68k => &m68k.cpu.M68030,
                .mips => &mips.cpu.mips32r2,
                .mipsel => switch (os.tag) {
                    .psx => &mips.cpu.r3000a,
                    .psp => &mips.cpu.allegrex,
                    else => &mips.cpu.mips32r2,
                },
                .mips64 => switch (os.tag) {
                    .openbsd => &mips.cpu.octeon,
                    else => &mips.cpu.mips64r2,
                },
                .mips64el => &mips.cpu.mips64r2,
                .msp430 => &msp430.cpu.msp430,
                .nvptx, .nvptx64 => &nvptx.cpu.sm_52,
                .powerpc => switch (os.tag) {
                    .openbsd, .wiiu => &powerpc.cpu.@"750",
                    else => generic(arch),
                },
                .powerpc64 => switch (os.tag) {
                    .linux, .freebsd => &powerpc.cpu.pwr8,
                    .openbsd => &powerpc.cpu.pwr9,
                    else => generic(arch),
                },
                .powerpc64le => &powerpc.cpu.ppc64le,
                .riscv32, .riscv32be => &riscv.cpu.baseline_rv32,
                .riscv64, .riscv64be => &riscv.cpu.baseline_rv64,
                .s390x => &s390x.cpu.arch11,
                .sparc => switch (os.tag) {
                    .linux => &sparc.cpu.v9, // glibc does not work with 'plain' v8.
                    else => generic(arch),
                },
                .sparc64 => &sparc.cpu.ultrasparc,
                .x86 => &x86.cpu.pentium4,
                .x86_64 => switch (os.tag) {
                    .driverkit, .maccatalyst => &x86.cpu.nehalem,
                    .macos => &x86.cpu.core2,
                    .ps4 => &x86.cpu.btver2,
                    .ps5 => &x86.cpu.znver2,
                    else => generic(arch),
                },
                .xcore => &xcore.cpu.xs1b_generic,
                .xtensa => &xtensa.cpu.esp32,
                .wasm32, .wasm64 => &wasm.cpu.lime1,

                else => generic(arch),
            };
        }
    };

    /// The "default" set of CPU features for cross-compiling. A conservative set
    /// of features that is expected to be supported on most available hardware.
    pub fn baseline(arch: Arch, os: Os) Cpu {
        return Model.baseline(arch, os).toCpu(arch);
    }

    /// Returns true if `feature` is enabled.
    pub fn has(cpu: Cpu, comptime family: Arch.Family, feature: @field(Target, @tagName(family)).Feature) bool {
        if (family != cpu.arch.family()) return false;
        return cpu.features.isEnabled(@backingInt(feature));
    }

    /// Returns true if any feature in `features` is enabled.
    pub fn hasAny(cpu: Cpu, comptime family: Arch.Family, features: []const @field(Target, @tagName(family)).Feature) bool {
        if (family != cpu.arch.family()) return false;
        for (features) |feature| {
            if (cpu.features.isEnabled(@backingInt(feature))) return true;
        }
        return false;
    }

    /// Returns true if all features in `features` are enabled.
    pub fn hasAll(cpu: Cpu, comptime family: Arch.Family, features: []const @field(Target, @tagName(family)).Feature) bool {
        if (family != cpu.arch.family()) return false;
        for (features) |feature| {
            if (!cpu.features.isEnabled(@backingInt(feature))) return false;
        }
        return true;
    }
};

pub fn zigTriple(target: *const Target, allocator: Allocator) Allocator.Error![]u8 {
    return Query.fromTarget(target).zigTriple(allocator);
}

/// Deprecated; to be removed in 0.18.0. Use `std.zig.target.hurdTupleSimple` instead.
pub fn hurdTupleSimple(allocator: Allocator, arch: Cpu.Arch, abi: Abi) ![]u8 {
    return std.fmt.allocPrint(allocator, "{s}-{s}", .{ @tagName(arch), @tagName(abi) });
}

/// Deprecated; to be removed in 0.18.0. Use `std.zig.target.hurdTuple` instead.
pub fn hurdTuple(target: *const Target, allocator: Allocator) ![]u8 {
    return hurdTupleSimple(allocator, target.cpu.arch, target.abi);
}

/// Deprecated; to be removed in 0.18.0. Use `std.zig.target.linuxTripleSimple` instead.
pub fn linuxTripleSimple(allocator: Allocator, arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 {
    return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ @tagName(arch), @tagName(os_tag), @tagName(abi) });
}

/// Deprecated; to be removed in 0.18.0. Use `std.zig.target.linuxTriple` instead.
pub fn linuxTriple(target: *const Target, allocator: Allocator) ![]u8 {
    return linuxTripleSimple(allocator, target.cpu.arch, target.os.tag, target.abi);
}

pub fn exeFileExt(target: *const Target) [:0]const u8 {
    return target.os.tag.exeFileExt(target.cpu.arch);
}

pub fn staticLibSuffix(target: *const Target) [:0]const u8 {
    return target.os.tag.staticLibSuffix(target.abi);
}

pub fn dynamicLibSuffix(target: *const Target) [:0]const u8 {
    return target.os.tag.dynamicLibSuffix();
}

pub fn libPrefix(target: *const Target) [:0]const u8 {
    return target.os.tag.libPrefix(target.abi);
}

pub inline fn isMinGW(target: *const Target) bool {
    return target.os.tag == .windows and target.abi.isGnu();
}

pub inline fn isGnuLibC(target: *const Target) bool {
    return switch (target.os.tag) {
        .hurd, .linux => target.abi.isGnu(),
        else => false,
    };
}

pub inline fn isMuslLibC(target: *const Target) bool {
    return target.os.tag == .linux and target.abi.isMusl();
}

pub inline fn isBionicLibC(target: *const Target) bool {
    return target.os.tag == .linux and target.abi.isAndroid();
}

pub inline fn isDarwinLibC(target: *const Target) bool {
    return switch (target.abi) {
        .none, .simulator => target.os.tag.isDarwin(),
        else => false,
    };
}

pub inline fn isFreeBSDLibC(target: *const Target) bool {
    return switch (target.abi) {
        .none, .eabihf => target.os.tag == .freebsd,
        else => false,
    };
}

pub inline fn isNetBSDLibC(target: *const Target) bool {
    return switch (target.abi) {
        .none, .eabi, .eabihf => target.os.tag == .netbsd,
        else => false,
    };
}

pub inline fn isOpenBSDLibC(target: *const Target) bool {
    return switch (target.abi) {
        .none, .eabi, .eabihf => target.os.tag == .openbsd,
        else => false,
    };
}

pub inline fn isWasiLibC(target: *const Target) bool {
    return target.os.tag == .wasi and target.abi.isMusl();
}

/// Does this target require linking libc? This may be the case if the target has an unstable
/// syscall interface, for example.
pub fn requiresLibC(target: *const Target) bool {
    return switch (target.os.tag) {
        .illumos,
        .driverkit,
        .ios,
        .maccatalyst,
        .macos,
        .tvos,
        .watchos,
        .visionos,
        .dragonfly,
        .haiku,
        .serenity,
        .emscripten,
        => true,

        // Android API levels prior to 29 did not have native TLS support. For these API levels, TLS
        // is implemented through calls to `__emutls_get_address`. We provide this function in
        // compiler-rt, but it's implemented by way of `pthread_key_create` et al, so linking libc
        // is required.
        .linux => target.abi.isAndroid() and target.os.version_range.linux.android < 29,

        .windows,
        .freebsd,
        .netbsd,
        .openbsd,
        .freestanding,
        .fuchsia,
        .managarm,
        .rtems,
        .cuda,
        .nvcl,
        .amdhsa,
        .psx,
        .ps3,
        .ps4,
        .ps5,
        .gba,
        .psp,
        .vita,
        .mesa3d,
        .contiki,
        .amdpal,
        .hermit,
        .hurd,
        .wasi,
        .uefi,
        .opencl,
        .opengl,
        .vulkan,
        .plan9,
        .other,
        .@"3ds",
        .wiiu,
        .@"switch",
        .tios,
        .ashetos,
        => false,
    };
}

/// The places where a user can specify an address space attribute
pub const AddressSpaceContext = enum {
    /// A function is specified to be placed in a certain address space.
    function,
    /// A (global) variable is specified to be placed in a certain address space. In contrast to
    /// `.constant`, these values (and thus the address space they will be placed in) are required
    /// to be mutable.
    variable,
    /// A (global) constant value is specified to be placed in a certain address space. In contrast
    /// to `.variable`, values placed in this address space are not required to be mutable.
    constant,
    /// A pointer is ascripted to point into a certain address space.
    pointer,
};

/// Returns whether this target supports `address_space`. If `context` is `null`, this
/// function simply answers the general question of whether the target has any concept
/// of `address_space`; if non-`null`, the function additionally checks whether
/// `address_space` is valid in that context.
pub fn supportsAddressSpace(
    target: Target,
    address_space: std.builtin.AddressSpace,
    context: ?AddressSpaceContext,
) bool {
    const arch = target.cpu.arch;

    const is_nvptx = arch.isNvptx();
    const is_spirv = arch.isSpirV();
    const is_gpu = is_nvptx or is_spirv or arch == .amdgcn;

    return switch (address_space) {
        .generic => true,
        .fs, .gs, .ss => (arch == .x86_64 or arch == .x86 or arch == .x86_16) and (context == null or context == .pointer),
        // Technically x86 can use segmentation...
        .far => (arch == .x86_16),

        .flash, .flash1, .flash2, .flash3, .flash4, .flash5 => arch == .avr, // TODO this should also check how many flash banks the cpu has
        .cog, .hub => arch == .propeller,
        .lut => arch == .propeller and std.Target.propeller.featureSetHas(target.cpu.features, .p2),

        .global, .local, .shared => is_gpu,
        .private => is_spirv,
        .constant => (is_gpu and (context == null or context == .constant)) or
            (is_spirv and (context == null or context == .constant or context == .pointer)),
        .param => is_nvptx,
        .input, .output, .uniform, .push_constant, .storage_buffer => is_spirv,
        .physical_storage_buffer => arch == .spirv64,
        .externref, .funcref => target.cpu.has(.wasm, .reference_types),
    };
}

pub const DynamicLinker = struct {
    /// Contains the memory used to store the dynamic linker path. This field
    /// should not be used directly. See `get` and `set`. This field exists so
    /// that this API requires no allocator.
    buffer: [255]u8,

    /// Used to construct the dynamic linker path. This field should not be used
    /// directly. See `get` and `set`.
    len: u8,

    pub const none: DynamicLinker = .{ .buffer = undefined, .len = 0 };

    /// Asserts that the length is less than or equal to 255 bytes.
    pub fn init(maybe_path: ?[]const u8) DynamicLinker {
        var dl: DynamicLinker = undefined;
        dl.set(maybe_path);
        return dl;
    }

    pub fn initFmt(comptime fmt_str: []const u8, args: anytype) !DynamicLinker {
        var dl: DynamicLinker = undefined;
        try dl.setFmt(fmt_str, args);
        return dl;
    }

    /// The returned memory has the same lifetime as the `DynamicLinker`.
    pub fn get(dl: *const DynamicLinker) ?[]const u8 {
        return if (dl.len > 0) dl.buffer[0..dl.len] else null;
    }

    /// Asserts that the length is less than or equal to 255 bytes.
    pub fn set(dl: *DynamicLinker, maybe_path: ?[]const u8) void {
        const path = maybe_path orelse "";
        @memcpy(dl.buffer[0..path.len], path);
        dl.len = @intCast(path.len);
    }

    /// Asserts that the length is less than or equal to 255 bytes.
    pub fn setFmt(dl: *DynamicLinker, comptime fmt_str: []const u8, args: anytype) !void {
        dl.len = @intCast((try std.mem.print(&dl.buffer, fmt_str, args)).len);
    }

    pub fn eql(lhs: DynamicLinker, rhs: DynamicLinker) bool {
        return std.mem.eql(u8, lhs.buffer[0..lhs.len], rhs.buffer[0..rhs.len]);
    }

    pub const Kind = enum {
        /// No dynamic linker.
        none,
        /// Dynamic linker path is determined by the arch/OS components.
        arch_os,
        /// Dynamic linker path is determined by the arch/OS/ABI components.
        arch_os_abi,
    };

    pub fn kind(os: Os.Tag) Kind {
        return switch (os) {
            .fuchsia,

            .haiku,
            .illumos,
            .serenity,

            .dragonfly,
            .freebsd,
            .netbsd,
            .openbsd,

            .driverkit,
            .ios,
            .maccatalyst,
            .macos,
            .tvos,
            .visionos,
            .watchos,
            => .arch_os,
            .hurd,
            .linux,
            => .arch_os_abi,
            .freestanding,
            .other,

            .contiki,
            .hermit,
            .managarm, // Needs to be double-checked.

            .plan9,
            .rtems,

            .uefi,
            .windows,

            .@"3ds",
            .wiiu,
            .@"switch",
            .gba,

            .emscripten,
            .wasi,

            .amdhsa,
            .amdpal,
            .cuda,
            .mesa3d,
            .nvcl,
            .opencl,
            .opengl,
            .vulkan,

            .psx,
            .ps3,
            .ps4,
            .ps5,
            .psp,
            .vita,

            .tios,
            .ashetos,
            => .none,
        };
    }

    /// The strictness of this function depends on the value of `kind(os.tag)`:
    ///
    /// * `.none`: Ignores all arguments and just returns `none`.
    /// * `.arch_os`: Ignores `abi` and returns the dynamic linker matching `cpu` and `os`.
    /// * `.arch_os_abi`: Returns the dynamic linker matching `cpu`, `os`, and `abi`.
    ///
    /// In the case of `.arch_os` in particular, callers should be aware that a valid dynamic linker
    /// being returned only means that the `cpu` + `os` combination represents a platform that
    /// actually exists and which has an established dynamic linker path that does not change with
    /// the ABI; it does not necessarily mean that `abi` makes any sense at all for that platform.
    /// The responsibility for determining whether `abi` is valid in this case rests with the
    /// caller. `Abi.default()` can be used to pick a best-effort default ABI for such platforms.
    pub fn standard(cpu: Cpu, os: Os.Tag, abi: Abi) DynamicLinker {
        return switch (os) {
            .fuchsia => switch (cpu.arch) {
                .arm,
                .aarch64,
                .riscv64,
                .thumb,
                .x86_64,
                => init("ld.so.1"), // Fuchsia is unusual in that `DT_INTERP` is just a basename.
                else => none,
            },

            .haiku => switch (cpu.arch) {
                .arm,
                .aarch64,
                .riscv64,
                .x86,
                .x86_64,
                => init("/system/runtime_loader"),
                else => none,
            },

            .hurd => switch (cpu.arch) {
                .aarch64,
                .aarch64_be,
                => |arch| if (abi == .gnu) initFmt("/lib/ld-{s}.so.1", .{@tagName(arch)}) else none,

                .x86 => if (abi == .gnu) init("/lib/ld.so.1") else none,
                .x86_64 => initFmt("/lib/ld-{s}.so.1", .{switch (abi) {
                    .gnu => "x86-64",
                    .gnux32 => "x32",
                    else => return none,
                }}),

                else => none,
            },

            .illumos,
            => switch (cpu.arch) {
                .x86,
                .x86_64,
                => initFmt("/lib/{s}ld.so.1", .{if (ptrBitWidth_cpu_abi(cpu, .none) == 64) "64/" else ""}),
                else => none,
            },

            .linux => if (abi.isAndroid())
                switch (cpu.arch) {
                    .arm => if (abi == .androideabi) init("/system/bin/linker") else none,

                    .aarch64,
                    .riscv64,
                    .x86,
                    .x86_64,
                    => if (abi == .android) initFmt("/system/bin/linker{s}", .{
                        if (ptrBitWidth_cpu_abi(cpu, abi) == 64) "64" else "",
                    }) else none,

                    else => none,
                }
            else if (abi.isMusl())
                switch (cpu.arch) {
                    .arm,
                    .armeb,
                    .thumb,
                    .thumbeb,
                    => |arch| initFmt("/lib/ld-musl-arm{s}{s}.so.1", .{
                        if (arch == .armeb or arch == .thumbeb) "eb" else "",
                        switch (abi) {
                            .musleabi => "",
                            .musleabihf => "hf",
                            else => return none,
                        },
                    }),

                    .loongarch32,
                    .loongarch64,
                    => |arch| initFmt("/lib/ld-musl-{s}{s}.so.1", .{
                        @tagName(arch),
                        switch (abi) {
                            .musl => "",
                            .muslf32 => "-sp",
                            .muslsf => "-sf",
                            else => return none,
                        },
                    }),

                    .aarch64,
                    .aarch64_be,
                    .hexagon,
                    .kvx,
                    .m68k,
                    .microblaze,
                    .microblazeel,
                    .or1k,
                    .powerpc64,
                    .powerpc64le,
                    .s390x,
                    => |arch| if (abi == .musl) initFmt("/lib/ld-musl-{s}.so.1", .{@tagName(arch)}) else none,

                    .mips,
                    .mipsel,
                    => |arch| initFmt("/lib/ld-musl-mips{s}{s}{s}.so.1", .{
                        if (cpu.has(.mips, .mips32r6)) "r6" else "",
                        if (arch == .mipsel) "el" else "",
                        switch (abi) {
                            .musleabi => "-sf",
                            .musleabihf => "",
                            else => return none,
                        },
                    }),

                    .mips64,
                    .mips64el,
                    => |arch| initFmt("/lib/ld-musl-mips{s}{s}{s}.so.1", .{
                        switch (abi) {
                            .muslabi64 => "64",
                            .muslabin32 => "n32",
                            else => return none,
                        },
                        if (cpu.has(.mips, .mips64r6)) "r6" else "",
                        if (arch == .mips64el) "el" else "",
                    }),

                    .powerpc => initFmt("/lib/ld-musl-powerpc{s}.so.1", .{switch (abi) {
                        .musleabi => "-sf",
                        .musleabihf => "",
                        else => return none,
                    }}),

                    .sh,
                    .sheb,
                    => |arch| initFmt("/lib/ld-musl-{t}{s}.so.1", .{
                        arch,
                        switch (abi) {
                            .musleabi => "-nofpu",
                            .musleabihf => "",
                            else => return none,
                        },
                    }),

                    .riscv32,
                    .riscv64,
                    => |arch| if (abi == .musl) initFmt("/lib/ld-musl-{s}{s}.so.1", .{
                        @tagName(arch),
                        if (cpu.has(.riscv, .d))
                            ""
                        else if (cpu.has(.riscv, .f))
                            "-sp"
                        else
                            "-sf",
                    }) else none,

                    .x86 => if (abi == .musl) init("/lib/ld-musl-i386.so.1") else none,

                    .x86_64 => initFmt("/lib/ld-musl-{s}.so.1", .{switch (abi) {
                        .musl => "x86_64",
                        .muslx32 => "x32",
                        else => return none,
                    }}),

                    else => none,
                }
            else if (abi.isGnu())
                switch (cpu.arch) {
                    .arc,
                    .arceb,
                    => |arch| if (abi == .gnu) initFmt("/lib/ld-linux-{t}.so.2", .{arch}) else none,

                    .arm,
                    .armeb,
                    => initFmt("/lib/ld-linux{s}.so.3", .{switch (abi) {
                        .gnueabi => "",
                        .gnueabihf => "-armhf",
                        else => return none,
                    }}),

                    .aarch64,
                    .aarch64_be,
                    .or1k,
                    => |arch| if (abi == .gnu) initFmt("/lib/ld-linux-{s}.so.1", .{@tagName(arch)}) else none,

                    .csky => initFmt("/lib/ld-linux-cskyv2{s}.so.1", .{switch (abi) {
                        .gnueabi => "",
                        .gnueabihf => "-hf",
                        else => return none,
                    }}),

                    .loongarch32,
                    .loongarch64,
                    => |arch| initFmt("/lib{s}/ld-linux-{s}{s}.so.1", .{
                        switch (arch) {
                            .loongarch32 => "32",
                            .loongarch64 => "64",
                            else => unreachable,
                        },
                        switch (arch) {
                            .loongarch32 => "loongarch-ilp32",
                            .loongarch64 => "loongarch-lp64",
                            else => unreachable,
                        },
                        switch (abi) {
                            .gnu => "d",
                            .gnuf32 => "f",
                            .gnusf => "s",
                            else => return none,
                        },
                    }),

                    .hppa,
                    .m68k,
                    .microblaze,
                    .microblazeel,
                    .xtensa,
                    .xtensaeb,
                    => if (abi == .gnu) init("/lib/ld.so.1") else none,

                    .mips,
                    .mipsel,
                    => switch (abi) {
                        .gnueabi,
                        .gnueabihf,
                        => initFmt("/lib/ld{s}.so.1", .{
                            if (cpu.has(.mips, .nan2008)) "-linux-mipsn8" else "",
                        }),
                        else => none,
                    },

                    .mips64,
                    .mips64el,
                    => initFmt("/lib{s}/ld{s}.so.1", .{
                        switch (abi) {
                            .gnuabi64 => "64",
                            .gnuabin32 => "32",
                            else => return none,
                        },
                        if (cpu.has(.mips, .nan2008)) "-linux-mipsn8" else "",
                    }),

                    .powerpc => switch (abi) {
                        .gnueabi,
                        .gnueabihf,
                        => init("/lib/ld.so.1"),
                        else => none,
                    },

                    .powerpc64 => if (abi == .gnu) init("/lib64/ld64.so.1") else none,
                    .powerpc64le => if (abi == .gnu) init("/lib64/ld64.so.2") else none,

                    .riscv32,
                    .riscv64,
                    => |arch| if (abi == .gnu) initFmt("/lib/ld-linux-{s}{s}.so.1", .{
                        switch (arch) {
                            .riscv32 => "riscv32-ilp32",
                            .riscv64 => "riscv64-lp64",
                            else => unreachable,
                        },
                        if (cpu.has(.riscv, .d))
                            "d"
                        else if (cpu.has(.riscv, .f))
                            "f"
                        else
                            "",
                    }) else none,

                    .s390x => if (abi == .gnu) init("/lib/ld64.so.1") else none,

                    .sh,
                    .sheb,
                    => switch (abi) {
                        .gnueabi,
                        .gnueabihf,
                        => init("/lib/ld-linux.so.2"),
                        else => none,
                    },

                    .alpha,
                    .sparc,
                    .x86,
                    => if (abi == .gnu) init("/lib/ld-linux.so.2") else none,

                    .sparc64 => if (abi == .gnu) init("/lib64/ld-linux.so.2") else none,

                    .x86_64 => switch (abi) {
                        .gnu => init("/lib64/ld-linux-x86-64.so.2"),
                        .gnux32 => init("/libx32/ld-linux-x32.so.2"),
                        else => none,
                    },

                    else => none,
                }
            else
                none, // Not a known Linux libc.

            .serenity => switch (cpu.arch) {
                .aarch64,
                .riscv64,
                .x86_64,
                => init("/usr/lib/Loader.so"),
                else => none,
            },

            .dragonfly => if (cpu.arch == .x86_64) init("/libexec/ld-elf.so.2") else none,

            .freebsd => switch (cpu.arch) {
                .arm,
                .aarch64,
                .powerpc,
                .powerpc64,
                .powerpc64le,
                .riscv64,
                .x86,
                .x86_64,
                => init("/libexec/ld-elf.so.1"),
                else => none,
            },

            .netbsd => switch (cpu.arch) {
                .alpha,
                .arm,
                .armeb,
                .aarch64,
                .aarch64_be,
                .hppa,
                .m68k,
                .mips,
                .mipsel,
                .mips64,
                .mips64el,
                .powerpc,
                .riscv32,
                .riscv64,
                .sh,
                .sheb,
                .sparc,
                .sparc64,
                .x86,
                .x86_64,
                => init("/libexec/ld.elf_so"),
                else => none,
            },

            .openbsd => switch (cpu.arch) {
                .alpha,
                .arm,
                .aarch64,
                .hppa,
                .m88k,
                .mips64,
                .mips64el,
                .powerpc,
                .powerpc64,
                .riscv64,
                .sh,
                .sparc64,
                .x86,
                .x86_64,
                => init("/usr/libexec/ld.so"),
                else => none,
            },

            .driverkit,
            .ios,
            .maccatalyst,
            .macos,
            .tvos,
            .visionos,
            .watchos,
            => switch (cpu.arch) {
                .aarch64,
                .x86_64,
                => init("/usr/lib/dyld"),
                else => none,
            },

            // Operating systems in this list have been verified as not having a standard
            // dynamic linker path.
            .freestanding,
            .other,

            .contiki,
            .hermit,

            .plan9,
            .rtems,

            .uefi,
            .windows,

            .@"3ds",
            .wiiu,
            .@"switch",
            .gba,

            .psx,
            .psp,
            .vita,

            .emscripten,
            .wasi,

            .amdhsa,
            .amdpal,
            .cuda,
            .mesa3d,
            .nvcl,
            .opencl,
            .opengl,
            .vulkan,

            .tios,
            .ashetos,
            => none,

            // TODO go over each item in this list and either move it to the above list, or
            // implement the standard dynamic linker path code for it.
            .managarm,

            .ps3,
            .ps4,
            .ps5,
            => none,
        } catch unreachable;
    }
};

pub fn standardDynamicLinkerPath(target: *const Target) DynamicLinker {
    return DynamicLinker.standard(target.cpu, target.os.tag, target.abi);
}

pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {
    return ptrBitWidth_arch_abi(cpu.arch, abi);
}

pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {
    switch (abi) {
        .gnux32,
        .muslx32,
        .x32,
        .gnuabin32,
        .muslabin32,
        .abin32,
        .ilp32,
        => return 32,
        else => {},
    }

    return switch (cpu_arch) {
        .avr,
        .msp430,
        .x86_16,
        .spork8,
        => 16,

        .ez80,
        => 24,

        .arc,
        .arceb,
        .arm,
        .armeb,
        .csky,
        .hexagon,
        .hppa,
        .kalimba,
        .lanai,
        .loongarch32,
        .m68k,
        .m88k,
        .microblaze,
        .microblazeel,
        .mips,
        .mipsel,
        .nvptx,
        .or1k,
        .powerpc,
        .powerpcle,
        .propeller,
        .riscv32,
        .riscv32be,
        .sh,
        .sheb,
        .sparc,
        .spirv32,
        .thumb,
        .thumbeb,
        .wasm32,
        .x86,
        .xcore,
        .xtensa,
        .xtensaeb,
        => 32,

        .aarch64,
        .aarch64_be,
        .alpha,
        .amdgcn,
        .bpfeb,
        .bpfel,
        .hppa64,
        .kvx,
        .loongarch64,
        .mips64,
        .mips64el,
        .nvptx64,
        .powerpc64,
        .powerpc64le,
        .riscv64,
        .riscv64be,
        .s390x,
        .sparc64,
        .spirv64,
        .ve,
        .wasm64,
        .x86_64,
        => 64,
    };
}

pub fn ptrBitWidth(target: *const Target) u16 {
    return ptrBitWidth_cpu_abi(target.cpu, target.abi);
}

pub fn stackAlignment(target: *const Target) u16 {
    // Overrides for when the stack alignment is not equal to the pointer width.
    switch (target.cpu.arch) {
        .ez80 => return 1,

        .m68k => return 2,

        .amdgcn => return 4,

        .arm,
        .armeb,
        .hppa,
        .lanai,
        .mips,
        .mipsel,
        .sparc,
        .thumb,
        .thumbeb,
        => return 8,

        .aarch64,
        .aarch64_be,
        .alpha,
        .bpfeb,
        .bpfel,
        .hppa64,
        .loongarch32,
        .loongarch64,
        .mips64,
        .mips64el,
        .sparc64,
        .ve,
        .wasm32,
        .wasm64,
        .x86_64,
        => return 16,

        // Some of the following prongs should really be testing the ABI, but our current `Abi` enum
        // can't handle that level of nuance yet.
        .powerpc64,
        .powerpc64le,
        => if (target.os.tag == .linux) return 16,

        .riscv32,
        .riscv32be,
        .riscv64,
        .riscv64be,
        => if (!target.cpu.has(.riscv, .e)) return 16,

        .x86 => if (target.os.tag != .windows and target.os.tag != .uefi) return 16,

        .kvx => return 32,

        .spork8 => return 256,

        else => {},
    }

    return @divExact(target.ptrBitWidth(), 8);
}

pub const StackGrowth = enum {
    down,
    up,
};

pub fn stackGrowth(target: *const Target) StackGrowth {
    // Strictly speaking, most architectures don't inherently define the stack growth direction; you
    // could quite easily argue that it is in fact a property of the ABI. However, that's just not
    // really how it plays out in the real world. And besides, we have no mechanism for indicating
    // a different stack growth ABI, nor a compelling use case for creating such a mechanism.
    return switch (target.cpu.arch) {
        .hppa,
        .hppa64,
        .spork8,
        => .up,
        else => .down,
    };
}

/// Default signedness of `char` for the native C compiler for this target
/// Note that char signedness is implementation-defined and many compilers provide
/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char
/// Returns `null` if no C ABI is defined for this target.
pub fn cCharSignedness(target: *const Target) ?std.builtin.Signedness {
    switch (target.os.tag) {
        .opengl => return null,
        else => {},
    }
    if (target.os.tag.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;
    return switch (target.cpu.arch) {
        .aarch64,
        .aarch64_be,
        .arm,
        .armeb,
        .arc,
        .arceb,
        .csky,
        .ez80,
        .hexagon,
        .msp430,
        .powerpc,
        .powerpcle,
        .powerpc64,
        .powerpc64le,
        .s390x,
        .riscv32,
        .riscv32be,
        .riscv64,
        .riscv64be,
        .thumb,
        .thumbeb,
        .xcore,
        .xtensa,
        .xtensaeb,
        => .unsigned,
        else => .signed,
    };
}

pub const CType = enum {
    char,
    short,
    ushort,
    int,
    uint,
    long,
    ulong,
    longlong,
    ulonglong,
    float,
    double,
    longdouble,
};

/// Returns `null` if no C ABI is defined for this target.
pub fn cTypeByteSize(t: *const Target, c_type: CType) ?u16 {
    return switch (c_type) {
        .char,
        .short,
        .ushort,
        .int,
        .uint,
        .long,
        .ulong,
        .longlong,
        .ulonglong,
        .float,
        .double,
        => @divExact(cTypeBitSize(t, c_type) orelse return null, 8),

        .longdouble => switch (cTypeBitSize(t, c_type) orelse return null) {
            64 => 8,
            80 => @intCast(std.mem.alignForward(usize, 10, cTypeAlignment(t, c_type).?)),
            128 => 16,
            else => unreachable,
        },
    };
}

/// Returns `null` if no C ABI is defined for this target.
pub fn cTypeBitSize(target: *const Target, c_type: CType) ?u16 {
    return switch (target.os.tag) {
        .freestanding,
        .other,
        .ashetos,
        => switch (target.cpu.arch) {
            .msp430,
            .x86_16,
            => switch (c_type) {
                .char => 8,
                .short, .ushort, .int, .uint => 16,
                .float, .long, .ulong => 32,
                .longlong, .ulonglong, .double, .longdouble => 64,
            },
            .avr => switch (c_type) {
                .char => 8,
                .short, .ushort, .int, .uint => 16,
                .long, .ulong, .float, .double, .longdouble => 32,
                .longlong, .ulonglong => 64,
            },
            // https://github.com/benanderman/spork-8/blob/main/Programming.md
            .spork8 => switch (c_type) {
                .char => 8,
                .short, .ushort, .int, .uint => 16,
                .long, .ulong, .float => 32,
                .double, .longdouble, .longlong, .ulonglong => 64,
            },
            .mips64,
            .mips64el,
            => switch (c_type) {
                .char => 8,
                .short, .ushort => 16,
                .int, .uint, .float => 32,
                .long, .ulong => switch (target.abi) {
                    .abin32 => 32,
                    else => 64,
                },
                .longlong, .ulonglong, .double => 64,
                .longdouble => 128,
            },
            .x86_64 => switch (c_type) {
                .char => 8,
                .short, .ushort => 16,
                .int, .uint, .float => 32,
                .long, .ulong => switch (target.abi) {
                    .x32 => 32,
                    else => 64,
                },
                .longlong, .ulonglong, .double => 64,
                .longdouble => 80,
            },
            else => switch (c_type) {
                .char => 8,
                .short, .ushort => 16,
                .int, .uint, .float => 32,
                .long, .ulong => target.ptrBitWidth(),
                .longlong, .ulonglong, .double => 64,
                .longdouble => switch (target.cpu.arch) {
                    .x86 => 80,

                    .alpha,
                    .riscv32,
                    .riscv32be,
                    .riscv64,
                    .riscv64be,
                    .aarch64,
                    .aarch64_be,
                    .powerpc,
                    .powerpcle,
                    .powerpc64,
                    .powerpc64le,
                    .s390x,
                    .sparc64,
                    .wasm32,
                    .wasm64,
                    .loongarch32,
                    .loongarch64,
                    .ve,
                    => 128,

                    else => 64,
                },
            },
        },

        .fuchsia,
        .hermit,

        .haiku,
        .hurd,
        .illumos,
        .linux,
        .plan9,
        .rtems,
        .serenity,

        .freebsd,
        .dragonfly,
        .netbsd,
        .openbsd,

        .wasi,
        .emscripten,
        => switch (target.cpu.arch) {
            .mips64,
            .mips64el,
            => switch (c_type) {
                .char => 8,
                .short, .ushort => 16,
                .int, .uint, .float => 32,
                .long, .ulong => switch (target.abi) {
                    .gnuabin32, .muslabin32, .abin32 => 32,
                    else => 64,
                },
                .longlong, .ulonglong, .double => 64,
                .longdouble => 128,
            },
            .x86_64 => switch (c_type) {
                .char => 8,
                .short, .ushort => 16,
                .int, .uint, .float => 32,
                .long, .ulong => switch (target.abi) {
                    .gnux32, .muslx32, .x32 => 32,
                    else => 64,
                },
                .longlong, .ulonglong, .double => 64,
                .longdouble => 80,
            },
            else => switch (c_type) {
                .char => 8,
                .short, .ushort => 16,
                .int, .uint, .float => 32,
                .long, .ulong => target.ptrBitWidth(),
                .longlong, .ulonglong, .double => 64,
                .longdouble => switch (target.cpu.arch) {
                    .x86 => switch (target.abi) {
                        .android => 64,
                        else => 80,
                    },

                    .powerpc,
                    .powerpcle,
                    => switch (target.abi) {
                        .musleabi, .musleabihf => 64,
                        else => switch (target.os.tag) {
                            .netbsd,
                            .openbsd,
                            => 64,
                            else => 128,
                        },
                    },

                    .powerpc64,
                    .powerpc64le,
                    => switch (target.abi) {
                        .musl => 64,
                        else => switch (target.os.tag) {
                            .freebsd,
                            .openbsd,
                            => 64,
                            else => 128,
                        },
                    },

                    .alpha,
                    .riscv32,
                    .riscv32be,
                    .riscv64,
                    .riscv64be,
                    .aarch64,
                    .aarch64_be,
                    .s390x,
                    .mips64,
                    .mips64el,
                    .sparc64,
                    .wasm32,
                    .wasm64,
                    .loongarch32,
                    .loongarch64,
                    .ve,
                    => 128,

                    else => 64,
                },
            },
        },

        .windows, .uefi => switch (target.cpu.arch) {
            .x86 => switch (c_type) {
                .char => 8,
                .short, .ushort => 16,
                .int, .uint, .float => 32,
                .long, .ulong => 32,
                .longlong, .ulonglong, .double => 64,
                .longdouble => switch (target.abi) {
                    .gnu => 80,
                    else => 64,
                },
            },
            .x86_64 => switch (c_type) {
                .char => 8,
                .short, .ushort => 16,
                .int, .uint, .float => 32,
                .long, .ulong => 32,
                .longlong, .ulonglong, .double => 64,
                .longdouble => switch (target.abi) {
                    .gnu => 80,
                    else => 64,
                },
            },
            else => switch (c_type) {
                .char => 8,
                .short, .ushort => 16,
                .int, .uint, .float => 32,
                .long, .ulong => 32,
                .longlong, .ulonglong, .double => 64,
                .longdouble => 64,
            },
        },

        .driverkit,
        .ios,
        .maccatalyst,
        .macos,
        .tvos,
        .visionos,
        .watchos,
        => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .float => 32,
            .long, .ulong => switch (target.cpu.arch) {
                .x86_64 => 64,
                else => switch (target.abi) {
                    .ilp32 => 32,
                    else => 64,
                },
            },
            .longlong, .ulonglong, .double => 64,
            .longdouble => switch (target.cpu.arch) {
                .x86_64 => 80,
                else => 64,
            },
        },

        .nvcl, .cuda => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .float => 32,
            .long, .ulong => switch (target.cpu.arch) {
                .nvptx => 32,
                .nvptx64 => 64,
                else => 64,
            },
            .longlong, .ulonglong, .double => 64,
            .longdouble => 64,
        },

        .amdhsa, .amdpal, .mesa3d => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .float => 32,
            .long, .ulong, .longlong, .ulonglong, .double => 64,
            .longdouble => 128,
        },

        .opencl, .vulkan => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .float => 32,
            .long, .ulong, .double => 64,
            .longlong, .ulonglong => 128,
            // Note: The OpenCL specification does not guarantee a particular size for long double,
            // but clang uses 128 bits.
            .longdouble => 128,
        },

        .@"3ds" => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .float, .long, .ulong => 32,
            .longlong, .ulonglong, .double, .longdouble => 64,
        },

        .wiiu => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .float, .long, .ulong => 32,
            .longlong, .ulonglong, .double, .longdouble => 64,
        },

        .@"switch" => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .float => 32,
            .long, .ulong, .longlong, .ulonglong, .double => 64,
            .longdouble => 128,
        },

        .gba => switch (c_type) {
            .char => return 8,
            .short, .ushort => return 16,
            .int, .uint, .long, .ulong, .float => return 32,
            .longlong, .ulonglong, .double, .longdouble => return 64,
        },

        .psx => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .long, .ulong, .float => 32,
            .longlong, .ulonglong, .double, .longdouble => 64,
        },
        .ps4, .ps5 => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .float => 32,
            .long, .ulong => 64,
            .longlong, .ulonglong, .double => 64,
            .longdouble => 80,
        },
        .psp, .vita => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint, .float => 32,
            .long, .ulong => 64,
            .longlong, .ulonglong, .double, .longdouble => 64,
        },
        .tios => switch (c_type) {
            .char => 8,
            .short, .ushort => 16,
            .int, .uint => 24,
            .long, .ulong, .float, .double => 32,
            .longlong, .ulonglong, .longdouble => 64,
        },

        .opengl => null,

        .ps3,
        .contiki,
        .managarm,
        => @panic("specify the C integer and float type sizes for this OS"),
    };
}

/// Returns `null` if no C ABI is defined for this target.
pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16 {
    // Overrides for unusual alignments
    switch (target.cpu.arch) {
        .avr,
        .ez80,
        .spork8,
        => return 1,
        .x86 => switch (target.os.tag) {
            .windows, .uefi => switch (c_type) {
                .longlong, .ulonglong, .double => return 8,
                .longdouble => switch (target.abi) {
                    .gnu => return 4,
                    else => return 8,
                },
                else => {},
            },
            else => {},
        },
        .m68k => switch (c_type) {
            .int, .uint, .long, .ulong => return 2,
            else => {},
        },
        .wasm32, .wasm64 => switch (target.os.tag) {
            .emscripten => switch (c_type) {
                .longdouble => return 8,
                else => {},
            },
            else => {},
        },
        else => {},
    }

    // Next-power-of-two-aligned, up to a maximum.
    return @min(
        std.math.ceilPowerOfTwoAssert(u16, ((cTypeBitSize(target, c_type) orelse return null) + 7) / 8),
        @as(u16, switch (target.cpu.arch) {
            .msp430,
            .x86_16,
            => 2,

            .arc,
            .arceb,
            .csky,
            .kalimba,
            .microblaze,
            .microblazeel,
            .or1k,
            .propeller,
            .sh,
            .sheb,
            .x86,
            .xcore,
            .xtensa,
            .xtensaeb,
            => 4,

            .amdgcn,
            .arm,
            .armeb,
            .bpfeb,
            .bpfel,
            .hexagon,
            .hppa,
            .lanai,
            .m68k,
            .m88k,
            .mips,
            .mipsel,
            .nvptx,
            .nvptx64,
            .s390x,
            .sparc,
            .thumb,
            .thumbeb,
            => 8,

            .aarch64,
            .aarch64_be,
            .alpha,
            .hppa64,
            .kvx,
            .loongarch32,
            .loongarch64,
            .mips64,
            .mips64el,
            .powerpc,
            .powerpcle,
            .powerpc64,
            .powerpc64le,
            .riscv32,
            .riscv32be,
            .riscv64,
            .riscv64be,
            .sparc64,
            .spirv32,
            .spirv64,
            .ve,
            .wasm32,
            .wasm64,
            .x86_64,
            => 16,

            .avr,
            .ez80,
            .spork8,
            => unreachable, // Handled above.
        }),
    );
}

pub fn cMaxIntAlignment(target: *const Target) u16 {
    return switch (target.cpu.arch) {
        .avr,
        .ez80,
        .spork8,
        => 1,

        .msp430,
        .x86_16,
        => 2,

        .arc,
        .arceb,
        .csky,
        .kalimba,
        .microblaze,
        .microblazeel,
        .or1k,
        .propeller,
        .sh,
        .sheb,
        .xcore,
        => 4,

        .x86 => switch (target.os.tag) {
            else => 4,
            .uefi, .windows => 8,
        },

        .arm,
        .armeb,
        .hexagon,
        .hppa,
        .lanai,
        .loongarch32,
        .m68k,
        .m88k,
        .mips,
        .mipsel,
        .powerpc,
        .powerpcle,
        .riscv32,
        .riscv32be,
        .s390x,
        .sparc,
        .thumb,
        .thumbeb,
        .xtensa,
        .xtensaeb,
        => 8,

        .aarch64,
        .aarch64_be,
        .alpha,
        .amdgcn,
        .bpfel,
        .bpfeb,
        .hppa64,
        .kvx,
        .loongarch64,
        .mips64,
        .mips64el,
        .nvptx,
        .nvptx64,
        .powerpc64,
        .powerpc64le,
        .riscv64,
        .riscv64be,
        .sparc64,
        .spirv32,
        .spirv64,
        .ve,
        .wasm32,
        .wasm64,
        .x86_64,
        => 16,
    };
}

pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention {
    return switch (target.cpu.arch) {
        .x86_64 => switch (target.os.tag) {
            .windows, .uefi => .{ .x86_64_win = .{} },
            else => switch (target.abi) {
                .gnux32, .muslx32, .x32 => .{ .x86_64_x32 = .{} },
                else => .{ .x86_64_sysv = .{} },
            },
        },
        .x86 => switch (target.os.tag) {
            .windows, .uefi => if (target.isMinGW()) .{ .x86_mingw = .{} } else .{ .x86_win = .{} },
            else => .{ .x86_sysv = .{} },
        },
        .x86_16 => .{ .x86_16_cdecl = .{} },
        .aarch64, .aarch64_be => if (target.os.tag.isDarwin())
            .{ .aarch64_aapcs_darwin = .{} }
        else switch (target.os.tag) {
            .windows => .{ .aarch64_aapcs_win = .{} },
            else => .{ .aarch64_aapcs = .{} },
        },
        .alpha => .{ .alpha_osf = .{} },
        .arm, .armeb, .thumb, .thumbeb => switch (target.abi.float()) {
            .soft => .{ .arm_aapcs = .{} },
            .hard => .{ .arm_aapcs_vfp = .{} },
        },
        .mips64, .mips64el => switch (target.abi) {
            .gnuabin32, .muslabin32, .abin32 => .{ .mips64_n32 = .{} },
            else => .{ .mips64_n64 = .{} },
        },
        .mips, .mipsel => .{ .mips_o32 = .{} },
        .riscv64, .riscv64be => .{ .riscv64_lp64 = .{} },
        .riscv32, .riscv32be => .{ .riscv32_ilp32 = .{} },
        .sparc64 => .{ .sparc64_sysv = .{} },
        .sparc => .{ .sparc_sysv = .{} },
        .powerpc64 => if (target.os.tag == .ps3 or target.abi.isGnu())
            .{ .powerpc64_elf = .{} }
        else
            .{ .powerpc64_elf_v2 = .{} },
        .powerpc64le => .{ .powerpc64_elf_v2 = .{} },
        .powerpc, .powerpcle => .{ .powerpc_sysv = .{} },
        .wasm32, .wasm64 => .{ .wasm_mvp = .{} },
        .arc, .arceb => .{ .arc_sysv = .{} },
        .avr => .avr_gnu,
        .bpfel, .bpfeb => .{ .bpf_std = .{} },
        .csky => .{ .csky_sysv = .{} },
        .hexagon => .{ .hexagon_sysv = .{} },
        .hppa => .{ .hppa_elf = .{} },
        .hppa64 => .{ .hppa64_elf = .{} },
        .kalimba => null,
        .kvx => switch (target.abi) {
            .ilp32 => .{ .kvx_ilp32 = .{} },
            else => .{ .kvx_lp64 = .{} },
        },
        .lanai => .{ .lanai_sysv = .{} },
        .loongarch64 => .{ .loongarch64_lp64 = .{} },
        .loongarch32 => .{ .loongarch32_ilp32 = .{} },
        .m68k => .{ .m68k_gnu = .{} },
        .m88k => .{ .m88k_sysv = .{} },
        .microblaze, .microblazeel => .{ .microblaze_std = .{} },
        .msp430 => .{ .msp430_eabi = .{} },
        .or1k => .{ .or1k_sysv = .{} },
        .propeller => .{ .propeller_sysv = .{} },
        .s390x => .{ .s390x_sysv = .{} },
        .sh, .sheb => .{ .sh_gnu = .{} },
        .ve => .{ .ve_sysv = .{} },
        .xcore => .{ .xcore_xs1 = .{} },
        .xtensa, .xtensaeb => .{ .xtensa_call0 = .{} },
        .amdgcn => .{ .amdgcn_device = .{} },
        .nvptx, .nvptx64 => .nvptx_device,
        .spirv32, .spirv64 => .spirv_device,
        .ez80 => .ez80_cet,
        .spork8 => .spork8,
    };
}

const Target = @This();
const std = @import("std.zig");
const builtin = @import("builtin");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;

test {
    std.testing.refAllDecls(Cpu.Arch);
}