aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2025-01-24 03:45:38 +0100
committerAlex Rønne Petersen <alex@alexrp.com>2025-02-17 19:18:19 +0100
commit481b7bf3f095488a89e20d88ada092529bc6e6f8 (patch)
tree9e4dde982be4327fb18d156d7b3540c8d03ce658 /lib
parente62352611faf3056b989cc1edaa4aedaa74f326e (diff)
downloadzig-481b7bf3f095488a89e20d88ada092529bc6e6f8.tar.gz
zig-481b7bf3f095488a89e20d88ada092529bc6e6f8.zip
std.Target: Remove functions that just wrap component functions.
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look at multiple components of the target. But functions like isWasm(), isDarwin(), isGnu(), etc only exist to save 4-8 characters. I don't think this is a good enough reason to keep them, especially given that: * It's not immediately obvious to a reader whether target.isDarwin() means the same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar functions *do* look at multiple components. * It's not clear where we would draw the line. The logical conclusion before this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(), Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand. * It's nice to just have a single correct way of doing something.
Diffstat (limited to 'lib')
-rw-r--r--lib/compiler/aro/aro/Compilation.zig4
-rw-r--r--lib/compiler/aro/aro/Driver/GCCDetector.zig2
-rw-r--r--lib/compiler/aro/aro/Toolchain.zig14
-rw-r--r--lib/compiler/aro/aro/Type.zig2
-rw-r--r--lib/compiler/aro/aro/target.zig17
-rw-r--r--lib/compiler/aro/aro/toolchains/Linux.zig14
-rw-r--r--lib/compiler_rt/common.zig6
-rw-r--r--lib/std/Build/Step/Compile.zig6
-rw-r--r--lib/std/Target.zig66
-rw-r--r--lib/std/Target/Query.zig5
-rw-r--r--lib/std/Thread.zig2
-rw-r--r--lib/std/Thread/Futex.zig2
-rw-r--r--lib/std/builtin.zig2
-rw-r--r--lib/std/c.zig12
-rw-r--r--lib/std/c/darwin.zig2
-rw-r--r--lib/std/debug.zig8
-rw-r--r--lib/std/debug/SelfInfo.zig8
-rw-r--r--lib/std/fs/Dir.zig2
-rw-r--r--lib/std/heap.zig6
-rw-r--r--lib/std/heap/WasmAllocator.zig2
-rw-r--r--lib/std/heap/debug_allocator.zig4
-rw-r--r--lib/std/math/big/int_test.zig2
-rw-r--r--lib/std/math/gamma.zig2
-rw-r--r--lib/std/math/log10.zig2
-rw-r--r--lib/std/posix.zig4
-rw-r--r--lib/std/zig/LibCDirs.zig4
-rw-r--r--lib/std/zig/LibCInstallation.zig10
-rw-r--r--lib/std/zig/system.zig2
-rw-r--r--lib/std/zig/system/NativePaths.zig2
29 files changed, 97 insertions, 117 deletions
diff --git a/lib/compiler/aro/aro/Compilation.zig b/lib/compiler/aro/aro/Compilation.zig
index 414cdb45f0..68bad1a5ce 100644
--- a/lib/compiler/aro/aro/Compilation.zig
+++ b/lib/compiler/aro/aro/Compilation.zig
@@ -308,7 +308,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
),
else => {},
}
- if (comp.target.isAndroid()) {
+ if (comp.target.abi.isAndroid()) {
try w.writeAll("#define __ANDROID__ 1\n");
}
@@ -734,7 +734,7 @@ pub fn float80Type(comp: *const Compilation) ?Type {
/// Smallest integer type with at least N bits
pub fn intLeastN(comp: *const Compilation, bits: usize, signedness: std.builtin.Signedness) Type {
- if (bits == 64 and (comp.target.isDarwin() or comp.target.isWasm())) {
+ if (bits == 64 and (comp.target.os.tag.isDarwin() or comp.target.cpu.arch.isWasm())) {
// WebAssembly and Darwin use `long long` for `int_least64_t` and `int_fast64_t`.
return .{ .specifier = if (signedness == .signed) .long_long else .ulong_long };
}
diff --git a/lib/compiler/aro/aro/Driver/GCCDetector.zig b/lib/compiler/aro/aro/Driver/GCCDetector.zig
index 720254316e..80e94a3b71 100644
--- a/lib/compiler/aro/aro/Driver/GCCDetector.zig
+++ b/lib/compiler/aro/aro/Driver/GCCDetector.zig
@@ -183,7 +183,7 @@ fn collectLibDirsAndTriples(
// TODO
return;
}
- if (target.isAndroid()) {
+ if (target.abi.isAndroid()) {
const AArch64AndroidTriples: [1][]const u8 = .{"aarch64-linux-android"};
const ARMAndroidTriples: [1][]const u8 = .{"arm-linux-androideabi"};
const MIPSELAndroidTriples: [1][]const u8 = .{"mipsel-linux-android"};
diff --git a/lib/compiler/aro/aro/Toolchain.zig b/lib/compiler/aro/aro/Toolchain.zig
index fca44e07ec..c3d43f05b9 100644
--- a/lib/compiler/aro/aro/Toolchain.zig
+++ b/lib/compiler/aro/aro/Toolchain.zig
@@ -161,7 +161,7 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
} else {
var linker_name = try std.ArrayList(u8).initCapacity(tc.driver.comp.gpa, 5 + use_linker.len); // "ld64." ++ use_linker
defer linker_name.deinit();
- if (tc.getTarget().isDarwin()) {
+ if (tc.getTarget().os.tag.isDarwin()) {
linker_name.appendSliceAssumeCapacity("ld64.");
} else {
linker_name.appendSliceAssumeCapacity("ld.");
@@ -343,7 +343,7 @@ pub fn buildLinkerArgs(tc: *Toolchain, argv: *std.ArrayList([]const u8)) !void {
}
fn getDefaultRuntimeLibKind(tc: *const Toolchain) RuntimeLibKind {
- if (tc.getTarget().isAndroid()) {
+ if (tc.getTarget().abi.isAndroid()) {
return .compiler_rt;
}
return .libgcc;
@@ -369,7 +369,7 @@ pub fn getCompilerRt(tc: *const Toolchain, component: []const u8, file_kind: Fil
fn getLibGCCKind(tc: *const Toolchain) LibGCCKind {
const target = tc.getTarget();
- if (tc.driver.static_libgcc or tc.driver.static or tc.driver.static_pie or target.isAndroid()) {
+ if (tc.driver.static_libgcc or tc.driver.static or tc.driver.static_pie or target.abi.isAndroid()) {
return .static;
}
if (tc.driver.shared_libgcc) {
@@ -384,7 +384,7 @@ fn getUnwindLibKind(tc: *const Toolchain) !UnwindLibKind {
switch (tc.getRuntimeLibKind()) {
.compiler_rt => {
const target = tc.getTarget();
- if (target.isAndroid() or target.os.tag == .aix) {
+ if (target.abi.isAndroid() or target.os.tag == .aix) {
return .compiler_rt;
} else {
return .none;
@@ -417,14 +417,14 @@ fn getAsNeededOption(is_solaris: bool, needed: bool) []const u8 {
fn addUnwindLibrary(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
const unw = try tc.getUnwindLibKind();
const target = tc.getTarget();
- if ((target.isAndroid() and unw == .libgcc) or
+ if ((target.abi.isAndroid() and unw == .libgcc) or
target.os.tag == .elfiamcu or
target.ofmt == .wasm or
target_util.isWindowsMSVCEnvironment(target) or
unw == .none) return;
const lgk = tc.getLibGCCKind();
- const as_needed = lgk == .unspecified and !target.isAndroid() and !target_util.isCygwinMinGW(target) and target.os.tag != .aix;
+ const as_needed = lgk == .unspecified and !target.abi.isAndroid() and !target_util.isCygwinMinGW(target) and target.os.tag != .aix;
if (as_needed) {
try argv.append(getAsNeededOption(target.os.tag == .solaris, true));
}
@@ -483,7 +483,7 @@ pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !v
},
}
- if (target.isAndroid() and !tc.driver.static and !tc.driver.static_pie) {
+ if (target.abi.isAndroid() and !tc.driver.static and !tc.driver.static_pie) {
try argv.append("-ldl");
}
}
diff --git a/lib/compiler/aro/aro/Type.zig b/lib/compiler/aro/aro/Type.zig
index 8ab2d3164a..6bec686a21 100644
--- a/lib/compiler/aro/aro/Type.zig
+++ b/lib/compiler/aro/aro/Type.zig
@@ -1102,7 +1102,7 @@ pub fn alignof(ty: Type, comp: *const Compilation) u29 {
.double => comp.target.cTypeAlignment(.double),
.long_double => comp.target.cTypeAlignment(.longdouble),
- .int128, .uint128 => if (comp.target.cpu.arch == .s390x and comp.target.os.tag == .linux and comp.target.isGnu()) 8 else 16,
+ .int128, .uint128 => if (comp.target.cpu.arch == .s390x and comp.target.os.tag == .linux and comp.target.abi.isGnu()) 8 else 16,
.fp16, .float16 => 2,
.float128 => 16,
diff --git a/lib/compiler/aro/aro/target.zig b/lib/compiler/aro/aro/target.zig
index aac2e7bdee..7495eb5d9a 100644
--- a/lib/compiler/aro/aro/target.zig
+++ b/lib/compiler/aro/aro/target.zig
@@ -117,8 +117,8 @@ pub fn int64Type(target: std.Target) Type {
.sparc64 => return intMaxType(target),
- .x86, .x86_64 => if (!target.isDarwin()) return intMaxType(target),
- .aarch64, .aarch64_be => if (!target.isDarwin() and target.os.tag != .openbsd and target.os.tag != .windows) return .{ .specifier = .long },
+ .x86, .x86_64 => if (!target.os.tag.isDarwin()) return intMaxType(target),
+ .aarch64, .aarch64_be => if (!target.os.tag.isDarwin() and target.os.tag != .openbsd and target.os.tag != .windows) return .{ .specifier = .long },
else => {},
}
return .{ .specifier = .long_long };
@@ -144,7 +144,7 @@ pub fn defaultFunctionAlignment(target: std.Target) u8 {
}
pub fn isTlsSupported(target: std.Target) bool {
- if (target.isDarwin()) {
+ if (target.os.tag.isDarwin()) {
var supported = false;
switch (target.os.tag) {
.macos => supported = !(target.os.isAtLeast(.macos, .{ .major = 10, .minor = 7, .patch = 0 }) orelse false),
@@ -199,7 +199,7 @@ pub fn minZeroWidthBitfieldAlignment(target: std.Target) ?u29 {
pub fn unnamedFieldAffectsAlignment(target: std.Target) bool {
switch (target.cpu.arch) {
.aarch64 => {
- if (target.isDarwin() or target.os.tag == .windows) return false;
+ if (target.os.tag.isDarwin() or target.os.tag == .windows) return false;
return true;
},
.armeb => {
@@ -229,7 +229,7 @@ pub fn packAllEnums(target: std.Target) bool {
pub fn defaultAlignment(target: std.Target) u29 {
switch (target.cpu.arch) {
.avr => return 1,
- .arm => if (target.isAndroid() or target.os.tag == .ios) return 16 else return 8,
+ .arm => if (target.abi.isAndroid() or target.os.tag == .ios) return 16 else return 8,
.sparc => if (std.Target.sparc.featureSetHas(target.cpu.features, .v9)) return 16 else return 8,
.mips, .mipsel => switch (target.abi) {
.none, .gnuabi64 => return 16,
@@ -242,9 +242,8 @@ pub fn defaultAlignment(target: std.Target) u29 {
pub fn systemCompiler(target: std.Target) LangOpts.Compiler {
// Android is linux but not gcc, so these checks go first
// the rest for documentation as fn returns .clang
- if (target.isDarwin() or
- target.isAndroid() or
- target.isBSD() or
+ if (target.abi.isAndroid() or
+ target.os.tag.isBSD() or
target.os.tag == .fuchsia or
target.os.tag == .solaris or
target.os.tag == .haiku or
@@ -268,7 +267,7 @@ pub fn systemCompiler(target: std.Target) LangOpts.Compiler {
pub fn hasFloat128(target: std.Target) bool {
if (target.cpu.arch.isWasm()) return true;
- if (target.isDarwin()) return false;
+ if (target.os.tag.isDarwin()) return false;
if (target.cpu.arch.isPowerPC()) return std.Target.powerpc.featureSetHas(target.cpu.features, .float128);
return switch (target.os.tag) {
.dragonfly,
diff --git a/lib/compiler/aro/aro/toolchains/Linux.zig b/lib/compiler/aro/aro/toolchains/Linux.zig
index 763222cc98..466a63eed5 100644
--- a/lib/compiler/aro/aro/toolchains/Linux.zig
+++ b/lib/compiler/aro/aro/toolchains/Linux.zig
@@ -27,7 +27,7 @@ pub fn discover(self: *Linux, tc: *Toolchain) !void {
fn buildExtraOpts(self: *Linux, tc: *const Toolchain) !void {
const gpa = tc.driver.comp.gpa;
const target = tc.getTarget();
- const is_android = target.isAndroid();
+ const is_android = target.abi.isAndroid();
if (self.distro.isAlpine() or is_android) {
try self.extra_opts.ensureUnusedCapacity(gpa, 2);
self.extra_opts.appendAssumeCapacity("-z");
@@ -113,7 +113,7 @@ fn findPaths(self: *Linux, tc: *Toolchain) !void {
try tc.addPathIfExists(&.{ sysroot, "/lib", multiarch_triple }, .file);
try tc.addPathIfExists(&.{ sysroot, "/lib", "..", os_lib_dir }, .file);
- if (target.isAndroid()) {
+ if (target.abi.isAndroid()) {
// TODO
}
try tc.addPathIfExists(&.{ sysroot, "/usr", "lib", multiarch_triple }, .file);
@@ -156,7 +156,7 @@ fn getStatic(self: *const Linux, d: *const Driver) bool {
pub fn getDefaultLinker(self: *const Linux, target: std.Target) []const u8 {
_ = self;
- if (target.isAndroid()) {
+ if (target.abi.isAndroid()) {
return "ld.lld";
}
return "ld";
@@ -169,7 +169,7 @@ pub fn buildLinkerArgs(self: *const Linux, tc: *const Toolchain, argv: *std.Arra
const is_pie = self.getPIE(d);
const is_static_pie = try self.getStaticPIE(d);
const is_static = self.getStatic(d);
- const is_android = target.isAndroid();
+ const is_android = target.abi.isAndroid();
const is_iamcu = target.os.tag == .elfiamcu;
const is_ve = target.cpu.arch == .ve;
const has_crt_begin_end_files = target.abi != .none; // TODO: clang checks for MIPS vendor
@@ -326,7 +326,7 @@ pub fn buildLinkerArgs(self: *const Linux, tc: *const Toolchain, argv: *std.Arra
}
fn getMultiarchTriple(target: std.Target) ?[]const u8 {
- const is_android = target.isAndroid();
+ const is_android = target.abi.isAndroid();
const is_mips_r6 = std.Target.mips.featureSetHas(target.cpu.features, .mips32r6);
return switch (target.cpu.arch) {
.arm, .thumb => if (is_android) "arm-linux-androideabi" else if (target.abi == .gnueabihf) "arm-linux-gnueabihf" else "arm-linux-gnueabi",
@@ -380,7 +380,7 @@ pub fn defineSystemIncludes(self: *const Linux, tc: *const Toolchain) !void {
// musl prefers /usr/include before builtin includes, so musl targets will add builtins
// at the end of this function (unless disabled with nostdlibinc)
- if (!tc.driver.nobuiltininc and (!target.isMusl() or tc.driver.nostdlibinc)) {
+ if (!tc.driver.nobuiltininc and (!target.abi.isMusl() or tc.driver.nostdlibinc)) {
try comp.addBuiltinIncludeDir(tc.driver.aro_name);
}
@@ -411,7 +411,7 @@ pub fn defineSystemIncludes(self: *const Linux, tc: *const Toolchain) !void {
try comp.addSystemIncludeDir("/usr/include");
std.debug.assert(!tc.driver.nostdlibinc);
- if (!tc.driver.nobuiltininc and target.isMusl()) {
+ if (!tc.driver.nobuiltininc and target.abi.isMusl()) {
try comp.addBuiltinIncludeDir(tc.driver.aro_name);
}
}
diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig
index 93bcd982e0..0e3bb1ee14 100644
--- a/lib/compiler_rt/common.zig
+++ b/lib/compiler_rt/common.zig
@@ -14,7 +14,7 @@ else
/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
/// export it to the host runtime.
pub const visibility: std.builtin.SymbolVisibility =
- if (builtin.target.isWasm() and linkage != .internal) .hidden else .default;
+ if (builtin.target.cpu.arch.isWasm() and linkage != .internal) .hidden else .default;
pub const want_aeabi = switch (builtin.abi) {
.eabi,
@@ -92,7 +92,7 @@ pub const panic = if (builtin.is_test) std.debug.FullPanic(std.debug.defaultPani
pub fn F16T(comptime OtherType: type) type {
return switch (builtin.cpu.arch) {
.arm, .armeb, .thumb, .thumbeb => if (std.Target.arm.featureSetHas(builtin.cpu.features, .has_v8))
- switch (builtin.abi.floatAbi()) {
+ switch (builtin.abi.float()) {
.soft => u16,
.hard => f16,
}
@@ -100,7 +100,7 @@ pub fn F16T(comptime OtherType: type) type {
u16,
.aarch64, .aarch64_be => f16,
.riscv32, .riscv64 => f16,
- .x86, .x86_64 => if (builtin.target.isDarwin()) switch (OtherType) {
+ .x86, .x86_64 => if (builtin.target.os.tag.isDarwin()) switch (OtherType) {
// Starting with LLVM 16, Darwin uses different abi for f16
// depending on the type of the other return/argument..???
f32, f64 => u16,
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
index 25061917fa..c2c91ad447 100644
--- a/lib/std/Build/Step/Compile.zig
+++ b/lib/std/Build/Step/Compile.zig
@@ -465,7 +465,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
if (compile.linkage != null and compile.linkage.? == .static) {
compile.out_lib_filename = compile.out_filename;
} else if (compile.version) |version| {
- if (target.isDarwin()) {
+ if (target.os.tag.isDarwin()) {
compile.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{
compile.name,
version.major,
@@ -480,7 +480,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
compile.out_lib_filename = compile.out_filename;
}
} else {
- if (target.isDarwin()) {
+ if (target.os.tag.isDarwin()) {
compile.out_lib_filename = compile.out_filename;
} else if (target.os.tag == .windows) {
compile.out_lib_filename = owner.fmt("{s}.lib", .{compile.name});
@@ -1524,7 +1524,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
try zig_args.append(b.fmt("{}", .{version}));
}
- if (compile.rootModuleTarget().isDarwin()) {
+ if (compile.rootModuleTarget().os.tag.isDarwin()) {
const install_name = compile.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{
compile.rootModuleTarget().libPrefix(),
compile.name,
diff --git a/lib/std/Target.zig b/lib/std/Target.zig
index 05bd2a3673..740949858f 100644
--- a/lib/std/Target.zig
+++ b/lib/std/Target.zig
@@ -144,10 +144,6 @@ pub const Os = struct {
};
}
- pub inline fn isGnuLibC(tag: Os.Tag, abi: Abi) bool {
- return (tag == .hurd or tag == .linux) and abi.isGnu();
- }
-
pub fn defaultVersionRange(tag: Tag, arch: Cpu.Arch, abi: Abi) Os {
return .{
.tag = tag,
@@ -973,7 +969,12 @@ pub const Abi = enum {
};
}
- pub inline fn floatAbi(abi: Abi) FloatAbi {
+ pub const Float = enum {
+ hard,
+ soft,
+ };
+
+ pub inline fn float(abi: Abi) Float {
return switch (abi) {
.androideabi,
.eabi,
@@ -2022,48 +2023,29 @@ pub fn libPrefix(target: Target) [:0]const u8 {
}
pub inline fn isMinGW(target: Target) bool {
- return target.os.tag == .windows and target.isGnu();
-}
-
-pub inline fn isGnu(target: Target) bool {
- return target.abi.isGnu();
-}
-
-pub inline fn isMusl(target: Target) bool {
- return target.abi.isMusl();
-}
-
-pub inline fn isAndroid(target: Target) bool {
- return target.abi.isAndroid();
-}
-
-pub inline fn isWasm(target: Target) bool {
- return target.cpu.arch.isWasm();
-}
-
-pub inline fn isDarwin(target: Target) bool {
- return target.os.tag.isDarwin();
-}
-
-pub inline fn isBSD(target: Target) bool {
- return target.os.tag.isBSD();
+ return target.os.tag == .windows and target.abi.isGnu();
}
pub inline fn isGnuLibC(target: Target) bool {
- return target.os.tag.isGnuLibC(target.abi);
+ return switch (target.os.tag) {
+ .hurd, .linux => target.abi.isGnu(),
+ else => false,
+ };
}
-pub inline fn isSpirV(target: Target) bool {
- return target.cpu.arch.isSpirV();
+pub inline fn isMuslLibC(target: Target) bool {
+ return target.os.tag == .linux and target.abi.isMusl();
}
-pub const FloatAbi = enum {
- hard,
- soft,
-};
+pub inline fn isDarwinLibC(target: Target) bool {
+ return switch (target.abi) {
+ .none, .macabi, .simulator => target.os.tag.isDarwin(),
+ else => false,
+ };
+}
-pub inline fn floatAbi(target: Target) FloatAbi {
- return target.abi.floatAbi();
+pub inline fn isWasiLibC(target: Target) bool {
+ return target.os.tag == .wasi and target.abi.isMusl();
}
pub const DynamicLinker = struct {
@@ -2699,7 +2681,7 @@ pub fn stackAlignment(target: Target) u16 {
/// 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
pub fn charSignedness(target: Target) std.builtin.Signedness {
- if (target.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;
+ if (target.os.tag.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;
return switch (target.cpu.arch) {
.arm,
@@ -3292,7 +3274,7 @@ pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {
.windows => .{ .aarch64_aapcs_win = .{} },
else => .{ .aarch64_aapcs = .{} },
},
- .arm, .armeb, .thumb, .thumbeb => switch (target.abi.floatAbi()) {
+ .arm, .armeb, .thumb, .thumbeb => switch (target.abi.float()) {
.soft => .{ .arm_aapcs = .{} },
.hard => .{ .arm_aapcs_vfp = .{} },
},
@@ -3305,7 +3287,7 @@ pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {
.riscv32 => .{ .riscv32_ilp32 = .{} },
.sparc64 => .{ .sparc64_sysv = .{} },
.sparc => .{ .sparc_sysv = .{} },
- .powerpc64 => if (target.isMusl())
+ .powerpc64 => if (target.abi.isMusl())
.{ .powerpc64_elf_v2 = .{} }
else
.{ .powerpc64_elf = .{} },
diff --git a/lib/std/Target/Query.zig b/lib/std/Target/Query.zig
index 56387c27b3..2d5c734108 100644
--- a/lib/std/Target/Query.zig
+++ b/lib/std/Target/Query.zig
@@ -26,7 +26,7 @@ os_version_min: ?OsVersion = null,
os_version_max: ?OsVersion = null,
/// `null` means default when cross compiling, or native when `os_tag` is native.
-/// If `isGnuLibC()` is `false`, this must be `null` and is ignored.
+/// If `isGnu()` is `false`, this must be `null` and is ignored.
glibc_version: ?SemanticVersion = null,
/// `null` means default when cross compiling, or native when `os_tag` is native.
@@ -235,8 +235,7 @@ pub fn parse(args: ParseOptions) !Query {
const abi_ver_text = abi_it.rest();
if (abi_it.next() != null) {
- const tag = result.os_tag orelse builtin.os.tag;
- if (tag.isGnuLibC(abi)) {
+ if (abi.isGnu()) {
result.glibc_version = parseVersion(abi_ver_text) catch |err| switch (err) {
error.Overflow => return error.InvalidAbiVersion,
error.InvalidVersion => return error.InvalidAbiVersion,
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig
index 6dcb956184..eaf136d0eb 100644
--- a/lib/std/Thread.zig
+++ b/lib/std/Thread.zig
@@ -734,7 +734,7 @@ const PosixThreadImpl = struct {
else => {
var count: c_int = undefined;
var count_len: usize = @sizeOf(c_int);
- const name = if (comptime target.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
+ const name = if (comptime target.os.tag.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
posix.sysctlbynameZ(name, &count, &count_len, null, 0) catch |err| switch (err) {
error.NameTooLong, error.UnknownName => unreachable,
else => |e| return e,
diff --git a/lib/std/Thread/Futex.zig b/lib/std/Thread/Futex.zig
index c18caec7a6..69ed57a908 100644
--- a/lib/std/Thread/Futex.zig
+++ b/lib/std/Thread/Futex.zig
@@ -80,7 +80,7 @@ else if (builtin.os.tag == .openbsd)
OpenbsdImpl
else if (builtin.os.tag == .dragonfly)
DragonflyImpl
-else if (builtin.target.isWasm())
+else if (builtin.target.cpu.arch.isWasm())
WasmImpl
else if (std.Thread.use_pthreads)
PosixImpl
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig
index 19570c28b6..3a8764eed9 100644
--- a/lib/std/builtin.zig
+++ b/lib/std/builtin.zig
@@ -957,7 +957,7 @@ pub const VaList = switch (builtin.cpu.arch) {
.amdgcn => *u8,
.avr => *anyopaque,
.bpfel, .bpfeb => *anyopaque,
- .hexagon => if (builtin.target.isMusl()) VaListHexagon else *u8,
+ .hexagon => if (builtin.target.abi.isMusl()) VaListHexagon else *u8,
.loongarch32, .loongarch64 => *anyopaque,
.mips, .mipsel, .mips64, .mips64el => *anyopaque,
.riscv32, .riscv64 => *anyopaque,
diff --git a/lib/std/c.zig b/lib/std/c.zig
index fea9bbe177..32579c04d0 100644
--- a/lib/std/c.zig
+++ b/lib/std/c.zig
@@ -2808,7 +2808,7 @@ pub const Sigaction = switch (native_os) {
.mipsel,
.mips64,
.mips64el,
- => if (builtin.target.isMusl())
+ => if (builtin.target.abi.isMusl())
linux.Sigaction
else if (builtin.target.ptrBitWidth() == 64) extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
@@ -6701,7 +6701,7 @@ pub const Stat = switch (native_os) {
return self.ctim;
}
},
- .mips, .mipsel => if (builtin.target.isMusl()) extern struct {
+ .mips, .mipsel => if (builtin.target.abi.isMusl()) extern struct {
dev: dev_t,
__pad0: [2]i32,
ino: ino_t,
@@ -6762,7 +6762,7 @@ pub const Stat = switch (native_os) {
return self.ctim;
}
},
- .mips64, .mips64el => if (builtin.target.isMusl()) extern struct {
+ .mips64, .mips64el => if (builtin.target.abi.isMusl()) extern struct {
dev: dev_t,
__pad0: [3]i32,
ino: ino_t,
@@ -9863,16 +9863,16 @@ pub const LC = enum(c_int) {
pub extern "c" fn setlocale(category: LC, locale: ?[*:0]const u8) ?[*:0]const u8;
-pub const getcontext = if (builtin.target.isAndroid() or builtin.target.os.tag == .openbsd)
+pub const getcontext = if (builtin.target.abi.isAndroid() or builtin.target.os.tag == .openbsd)
{} // android bionic and openbsd libc does not implement getcontext
-else if (native_os == .linux and builtin.target.isMusl())
+else if (native_os == .linux and builtin.target.abi.isMusl())
linux.getcontext
else
private.getcontext;
pub const max_align_t = if (native_abi == .msvc or native_abi == .itanium)
f64
-else if (builtin.target.isDarwin())
+else if (native_os.isDarwin())
c_longdouble
else
extern struct {
diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig
index 89aa792566..561a4e7ce4 100644
--- a/lib/std/c/darwin.zig
+++ b/lib/std/c/darwin.zig
@@ -979,7 +979,7 @@ pub const kevent64_s = extern struct {
// to make sure the struct is laid out the same. These values were
// produced from C code using the offsetof macro.
comptime {
- if (builtin.target.isDarwin()) {
+ if (builtin.target.os.tag.isDarwin()) {
assert(@offsetOf(kevent64_s, "ident") == 0);
assert(@offsetOf(kevent64_s, "filter") == 8);
assert(@offsetOf(kevent64_s, "flags") == 10);
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index c36c89b206..56d978626a 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -292,7 +292,7 @@ pub fn dumpHexFallible(bytes: []const u8) !void {
/// TODO multithreaded awareness
pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
nosuspend {
- if (builtin.target.isWasm()) {
+ if (builtin.target.cpu.arch.isWasm()) {
if (native_os == .wasi) {
const stderr = io.getStdErr().writer();
stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
@@ -380,7 +380,7 @@ pub inline fn getContext(context: *ThreadContext) bool {
/// TODO multithreaded awareness
pub fn dumpStackTraceFromBase(context: *ThreadContext) void {
nosuspend {
- if (builtin.target.isWasm()) {
+ if (builtin.target.cpu.arch.isWasm()) {
if (native_os == .wasi) {
const stderr = io.getStdErr().writer();
stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
@@ -478,7 +478,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *std.builtin.StackT
/// TODO multithreaded awareness
pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
nosuspend {
- if (builtin.target.isWasm()) {
+ if (builtin.target.cpu.arch.isWasm()) {
if (native_os == .wasi) {
const stderr = io.getStdErr().writer();
stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
@@ -759,7 +759,7 @@ pub const StackIterator = struct {
pub fn initWithContext(first_address: ?usize, debug_info: *SelfInfo, context: *posix.ucontext_t) !StackIterator {
// The implementation of DWARF unwinding on aarch64-macos is not complete. However, Apple mandates that
// the frame pointer register is always used, so on this platform we can safely use the FP-based unwinder.
- if (builtin.target.isDarwin() and native_arch == .aarch64)
+ if (builtin.target.os.tag.isDarwin() and native_arch == .aarch64)
return init(first_address, @truncate(context.mcontext.ss.fp));
if (SelfInfo.supports_unwinding) {
diff --git a/lib/std/debug/SelfInfo.zig b/lib/std/debug/SelfInfo.zig
index 3c4260b212..0bd3f2d41b 100644
--- a/lib/std/debug/SelfInfo.zig
+++ b/lib/std/debug/SelfInfo.zig
@@ -121,13 +121,13 @@ pub fn deinit(self: *SelfInfo) void {
}
pub fn getModuleForAddress(self: *SelfInfo, address: usize) !*Module {
- if (builtin.target.isDarwin()) {
+ if (builtin.target.os.tag.isDarwin()) {
return self.lookupModuleDyld(address);
} else if (native_os == .windows) {
return self.lookupModuleWin32(address);
} else if (native_os == .haiku) {
return self.lookupModuleHaiku(address);
- } else if (builtin.target.isWasm()) {
+ } else if (builtin.target.cpu.arch.isWasm()) {
return self.lookupModuleWasm(address);
} else {
return self.lookupModuleDl(address);
@@ -138,13 +138,13 @@ pub fn getModuleForAddress(self: *SelfInfo, address: usize) !*Module {
// This can be called when getModuleForAddress fails, so implementations should provide
// a path that doesn't rely on any side-effects of a prior successful module lookup.
pub fn getModuleNameForAddress(self: *SelfInfo, address: usize) ?[]const u8 {
- if (builtin.target.isDarwin()) {
+ if (builtin.target.os.tag.isDarwin()) {
return self.lookupModuleNameDyld(address);
} else if (native_os == .windows) {
return self.lookupModuleNameWin32(address);
} else if (native_os == .haiku) {
return null;
- } else if (builtin.target.isWasm()) {
+ } else if (builtin.target.cpu.arch.isWasm()) {
return null;
} else {
return self.lookupModuleNameDl(address);
diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig
index 39aad8d42d..4ebec1ce14 100644
--- a/lib/std/fs/Dir.zig
+++ b/lib/std/fs/Dir.zig
@@ -2587,7 +2587,7 @@ const CopyFileRawError = error{SystemResources} || posix.CopyFileRangeError || p
// The copy starts at offset 0, the initial offsets are preserved.
// No metadata is transferred over.
fn copy_file(fd_in: posix.fd_t, fd_out: posix.fd_t, maybe_size: ?u64) CopyFileRawError!void {
- if (builtin.target.isDarwin()) {
+ if (builtin.target.os.tag.isDarwin()) {
const rc = posix.system.fcopyfile(fd_in, fd_out, null, .{ .DATA = true });
switch (posix.errno(rc)) {
.SUCCESS => return,
diff --git a/lib/std/heap.zig b/lib/std/heap.zig
index 51f434743d..6fbc3d8b75 100644
--- a/lib/std/heap.zig
+++ b/lib/std/heap.zig
@@ -348,7 +348,7 @@ pub const page_allocator: Allocator = if (@hasDecl(root, "os") and
@hasDecl(root.os, "heap") and
@hasDecl(root.os.heap, "page_allocator"))
root.os.heap.page_allocator
-else if (builtin.target.isWasm()) .{
+else if (builtin.target.cpu.arch.isWasm()) .{
.ptr = undefined,
.vtable = &WasmAllocator.vtable,
} else if (builtin.target.os.tag == .plan9) .{
@@ -508,7 +508,7 @@ test PageAllocator {
const allocator = page_allocator;
try testAllocator(allocator);
try testAllocatorAligned(allocator);
- if (!builtin.target.isWasm()) {
+ if (!builtin.target.cpu.arch.isWasm()) {
try testAllocatorLargeAlignment(allocator);
try testAllocatorAlignedShrink(allocator);
}
@@ -990,7 +990,7 @@ test {
_ = FixedBufferAllocator;
_ = ThreadSafeAllocator;
_ = SbrkAllocator;
- if (builtin.target.isWasm()) {
+ if (builtin.target.cpu.arch.isWasm()) {
_ = WasmAllocator;
}
if (!builtin.single_threaded) _ = smp_allocator;
diff --git a/lib/std/heap/WasmAllocator.zig b/lib/std/heap/WasmAllocator.zig
index 0a9003f245..b511a216f7 100644
--- a/lib/std/heap/WasmAllocator.zig
+++ b/lib/std/heap/WasmAllocator.zig
@@ -7,7 +7,7 @@ const wasm = std.wasm;
const math = std.math;
comptime {
- if (!builtin.target.isWasm()) {
+ if (!builtin.target.cpu.arch.isWasm()) {
@compileError("only available for wasm32 arch");
}
if (!builtin.single_threaded) {
diff --git a/lib/std/heap/debug_allocator.zig b/lib/std/heap/debug_allocator.zig
index 44e7a4c943..3e5163cd6c 100644
--- a/lib/std/heap/debug_allocator.zig
+++ b/lib/std/heap/debug_allocator.zig
@@ -1140,7 +1140,7 @@ test "shrink" {
}
test "large object - grow" {
- if (builtin.target.isWasm()) {
+ if (builtin.target.cpu.arch.isWasm()) {
// Not expected to pass on targets that do not have memory mapping.
return error.SkipZigTest;
}
@@ -1319,7 +1319,7 @@ test "realloc large object to larger alignment" {
}
test "large object rejects shrinking to small" {
- if (builtin.target.isWasm()) {
+ if (builtin.target.cpu.arch.isWasm()) {
// Not expected to pass on targets that do not have memory mapping.
return error.SkipZigTest;
}
diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig
index 701dddf0c9..811cf98d73 100644
--- a/lib/std/math/big/int_test.zig
+++ b/lib/std/math/big/int_test.zig
@@ -2262,7 +2262,7 @@ test "bitNotWrap more than two limbs" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
// LLVM: unexpected runtime library name: __umodei4
- if (builtin.zig_backend == .stage2_llvm and comptime builtin.target.isWasm()) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_llvm and comptime builtin.target.cpu.arch.isWasm()) return error.SkipZigTest; // TODO
var a = try Managed.initSet(testing.allocator, maxInt(Limb));
defer a.deinit();
diff --git a/lib/std/math/gamma.zig b/lib/std/math/gamma.zig
index aad2a104cc..5577f71461 100644
--- a/lib/std/math/gamma.zig
+++ b/lib/std/math/gamma.zig
@@ -263,7 +263,7 @@ test gamma {
}
test "gamma.special" {
- if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
+ if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
inline for (&.{ f32, f64 }) |T| {
try expect(std.math.isNan(gamma(T, -std.math.nan(T))));
diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig
index 6f3d9a47f6..655a42215e 100644
--- a/lib/std/math/log10.zig
+++ b/lib/std/math/log10.zig
@@ -135,7 +135,7 @@ test log10_int {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
- if (builtin.zig_backend == .stage2_llvm and comptime builtin.target.isWasm()) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_llvm and comptime builtin.target.cpu.arch.isWasm()) return error.SkipZigTest; // TODO
inline for (
.{ u8, u16, u32, u64, u128, u256, u512 },
diff --git a/lib/std/posix.zig b/lib/std/posix.zig
index 011a6723d1..0a640bf62a 100644
--- a/lib/std/posix.zig
+++ b/lib/std/posix.zig
@@ -3583,7 +3583,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
return rc;
}
- const have_sock_flags = !builtin.target.isDarwin() and native_os != .haiku;
+ const have_sock_flags = !builtin.target.os.tag.isDarwin() and native_os != .haiku;
const filtered_sock_type = if (!have_sock_flags)
socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC)
else
@@ -3879,7 +3879,7 @@ pub fn accept(
/// description of the `CLOEXEC` flag in `open` for reasons why this may be useful.
flags: u32,
) AcceptError!socket_t {
- const have_accept4 = !(builtin.target.isDarwin() or native_os == .windows or native_os == .haiku);
+ const have_accept4 = !(builtin.target.os.tag.isDarwin() or native_os == .windows or native_os == .haiku);
assert(0 == (flags & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC))); // Unsupported flag(s)
const accepted_sock: socket_t = while (true) {
diff --git a/lib/std/zig/LibCDirs.zig b/lib/std/zig/LibCDirs.zig
index 2ca3f406b9..cda21fbb37 100644
--- a/lib/std/zig/LibCDirs.zig
+++ b/lib/std/zig/LibCDirs.zig
@@ -127,7 +127,7 @@ fn detectFromInstallation(arena: Allocator, target: std.Target, lci: *const LibC
var sysroot: ?[]const u8 = null;
- if (target.isDarwin()) d: {
+ if (target.os.tag.isDarwin()) d: {
const down1 = std.fs.path.dirname(lci.sys_include_dir.?) orelse break :d;
const down2 = std.fs.path.dirname(down1) orelse break :d;
try framework_list.append(try std.fs.path.join(arena, &.{ down2, "System", "Library", "Frameworks" }));
@@ -150,7 +150,7 @@ pub fn detectFromBuilding(
) !LibCDirs {
const s = std.fs.path.sep_str;
- if (target.isDarwin()) {
+ if (target.os.tag.isDarwin()) {
const list = try arena.alloc([]const u8, 1);
list[0] = try std.fmt.allocPrint(
arena,
diff --git a/lib/std/zig/LibCInstallation.zig b/lib/std/zig/LibCInstallation.zig
index 56bc388f5d..b52c009313 100644
--- a/lib/std/zig/LibCInstallation.zig
+++ b/lib/std/zig/LibCInstallation.zig
@@ -81,7 +81,7 @@ pub fn parse(
}
const os_tag = target.os.tag;
- if (self.crt_dir == null and !target.isDarwin()) {
+ if (self.crt_dir == null and !target.os.tag.isDarwin()) {
log.err("crt_dir may not be empty for {s}", .{@tagName(os_tag)});
return error.ParseError;
}
@@ -167,7 +167,7 @@ pub const FindNativeOptions = struct {
pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation {
var self: LibCInstallation = .{};
- if (is_darwin and args.target.isDarwin()) {
+ if (is_darwin and args.target.os.tag.isDarwin()) {
if (!std.zig.system.darwin.isSdkInstalled(args.allocator))
return error.DarwinSdkNotFound;
const sdk = std.zig.system.darwin.getSdk(args.allocator, args.target) orelse
@@ -444,7 +444,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, args: FindNativeOptions) FindE
self.crt_dir = try ccPrintFileName(.{
.allocator = args.allocator,
.search_basename = switch (args.target.os.tag) {
- .linux => if (args.target.isAndroid()) "crtbegin_dynamic.o" else "crt1.o",
+ .linux => if (args.target.abi.isAndroid()) "crtbegin_dynamic.o" else "crt1.o",
else => "crt1.o",
},
.want_dirname = .only_dir,
@@ -734,7 +734,7 @@ pub const CrtBasenames = struct {
const target = args.target;
- if (target.isAndroid()) return switch (mode) {
+ if (target.abi.isAndroid()) return switch (mode) {
.dynamic_lib => .{
.crtbegin = "crtbegin_so.o",
.crtend = "crtend_so.o",
@@ -1025,7 +1025,7 @@ const fs = std.fs;
const Allocator = std.mem.Allocator;
const Path = std.Build.Cache.Path;
-const is_darwin = builtin.target.isDarwin();
+const is_darwin = builtin.target.os.tag.isDarwin();
const is_windows = builtin.target.os.tag == .windows;
const is_haiku = builtin.target.os.tag == .haiku;
diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
index 68182366e8..84f9cf7330 100644
--- a/lib/std/zig/system.zig
+++ b/lib/std/zig/system.zig
@@ -415,7 +415,7 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
}
// https://github.com/llvm/llvm-project/issues/105978
- if (result.cpu.arch.isArm() and result.abi.floatAbi() == .soft) {
+ if (result.cpu.arch.isArm() and result.abi.float() == .soft) {
result.cpu.features.removeFeature(@intFromEnum(Target.arm.Feature.vfp2));
}
}
diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig
index be8e7b05dd..d7bc9dfad7 100644
--- a/lib/std/zig/system/NativePaths.zig
+++ b/lib/std/zig/system/NativePaths.zig
@@ -83,7 +83,7 @@ pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {
// TODO: consider also adding homebrew paths
// TODO: consider also adding macports paths
- if (builtin.target.isDarwin()) {
+ if (builtin.target.os.tag.isDarwin()) {
if (std.zig.system.darwin.isSdkInstalled(arena)) sdk: {
const sdk = std.zig.system.darwin.getSdk(arena, native_target) orelse break :sdk;
try self.addLibDir(try std.fs.path.join(arena, &.{ sdk, "usr/lib" }));