From 94d567265a4dd86c0a64aad6c21b480d8559c5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 3 Nov 2024 16:27:59 +0100 Subject: [PATCH] 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 quickly gets out of hand. * It's nice to just have a single correct way of doing something. --- build.zig | 2 +- doc/langref/test_switch.zig | 4 +- doc/langref/test_variable_alignment.zig | 2 +- lib/compiler/aro/aro/Compilation.zig | 4 +- lib/compiler/aro/aro/Driver/GCCDetector.zig | 2 +- lib/compiler/aro/aro/Toolchain.zig | 14 ++--- lib/compiler/aro/aro/Type.zig | 2 +- lib/compiler/aro/aro/target.zig | 18 +++---- lib/compiler/aro/aro/toolchains/Linux.zig | 14 ++--- lib/compiler/resinator/main.zig | 4 +- lib/compiler_rt/common.zig | 6 +-- lib/compiler_rt/extendf_test.zig | 2 +- lib/compiler_rt/udivmod.zig | 2 +- lib/std/Build/Step/Compile.zig | 6 +-- lib/std/Target.zig | 52 ++++--------------- lib/std/Target/Query.zig | 2 +- lib/std/Thread.zig | 2 +- lib/std/Thread/Futex.zig | 6 +-- lib/std/Thread/Mutex.zig | 2 +- lib/std/atomic.zig | 2 +- lib/std/builtin.zig | 10 ++-- lib/std/c.zig | 12 ++--- lib/std/c/darwin.zig | 4 +- lib/std/crypto/ml_kem.zig | 2 +- lib/std/debug.zig | 8 +-- lib/std/debug/SelfInfo.zig | 8 +-- lib/std/fmt.zig | 6 +-- lib/std/fmt/format_float.zig | 2 +- lib/std/fs/Dir.zig | 2 +- lib/std/fs/path.zig | 2 +- lib/std/fs/test.zig | 4 +- lib/std/heap.zig | 8 +-- lib/std/heap/WasmAllocator.zig | 2 +- lib/std/heap/WasmPageAllocator.zig | 2 +- lib/std/math/big/int_test.zig | 2 +- lib/std/math/gamma.zig | 2 +- lib/std/math/log10.zig | 2 +- lib/std/os/windows.zig | 2 +- lib/std/posix.zig | 6 +-- lib/std/posix/test.zig | 6 +-- lib/std/valgrind.zig | 2 +- lib/std/zig/LibCDirs.zig | 4 +- lib/std/zig/LibCInstallation.zig | 22 ++++---- lib/std/zig/WindowsSdk.zig | 8 +-- lib/std/zig/c_translation.zig | 2 +- lib/std/zig/system.zig | 18 +++---- lib/std/zig/system/NativePaths.zig | 2 +- src/Compilation.zig | 10 ++-- src/Sema.zig | 6 +-- src/arch/x86_64/CodeGen.zig | 2 +- src/codegen/llvm.zig | 18 +++---- src/libtsan.zig | 12 ++--- src/libunwind.zig | 2 +- src/link.zig | 6 +-- src/link/Coff.zig | 2 +- src/link/Elf.zig | 2 +- src/link/MachO.zig | 4 +- src/main.zig | 8 +-- src/target.zig | 10 ++-- test/behavior/abs.zig | 2 +- test/behavior/align.zig | 2 +- test/behavior/alignof.zig | 2 +- test/behavior/asm.zig | 4 +- test/behavior/async_fn.zig | 2 +- test/behavior/floatop.zig | 4 +- test/behavior/fn.zig | 4 +- test/behavior/import_c_keywords.zig | 2 +- test/behavior/math.zig | 6 +-- test/behavior/vector.zig | 2 +- test/c_abi/main.zig | 16 +++--- .../link/glibc_compat/glibc_runtime_check.zig | 2 +- test/standalone/stack_iterator/build.zig | 4 +- .../stack_iterator/shared_lib_unwind.zig | 4 +- test/standalone/stack_iterator/unwind.zig | 2 +- 74 files changed, 203 insertions(+), 235 deletions(-) diff --git a/build.zig b/build.zig index d42af9a0b741..7c8249b81c23 100644 --- a/build.zig +++ b/build.zig @@ -710,7 +710,7 @@ fn addCmakeCfgOptionsToExe( exe: *std.Build.Step.Compile, use_zig_libcxx: bool, ) !void { - if (exe.rootModuleTarget().isDarwin()) { + if (exe.rootModuleTarget().os.tag.isDarwin()) { // useful for package maintainers exe.headerpad_max_install_names = true; } diff --git a/doc/langref/test_switch.zig b/doc/langref/test_switch.zig index 33fabbdfcda3..fc008a339fa7 100644 --- a/doc/langref/test_switch.zig +++ b/doc/langref/test_switch.zig @@ -44,7 +44,7 @@ test "switch simple" { } // Switch expressions can be used outside a function: -const os_msg = switch (builtin.target.os.tag) { +const os_msg = switch (builtin.os.tag) { .linux => "we found a linux user", else => "not a linux user", }; @@ -52,7 +52,7 @@ const os_msg = switch (builtin.target.os.tag) { // Inside a function, switch statements implicitly are compile-time // evaluated if the target expression is compile-time known. test "switch inside function" { - switch (builtin.target.os.tag) { + switch (builtin.os.tag) { .fuchsia => { // On an OS other than fuchsia, block is not even analyzed, // so this compile error is not triggered. diff --git a/doc/langref/test_variable_alignment.zig b/doc/langref/test_variable_alignment.zig index ea0024f98861..8840ceeb1c88 100644 --- a/doc/langref/test_variable_alignment.zig +++ b/doc/langref/test_variable_alignment.zig @@ -7,7 +7,7 @@ test "variable alignment" { const align_of_i32 = @alignOf(@TypeOf(x)); try expect(@TypeOf(&x) == *i32); try expect(*i32 == *align(align_of_i32) i32); - if (builtin.target.cpu.arch == .x86_64) { + if (builtin.cpu.arch == .x86_64) { try expect(@typeInfo(*i32).pointer.alignment == 4); } } diff --git a/lib/compiler/aro/aro/Compilation.zig b/lib/compiler/aro/aro/Compilation.zig index 414cdb45f004..68bad1a5ce9a 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 720254316e81..80e94a3b715f 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 fca44e07ecf5..c3d43f05b93a 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 8ab2d3164a77..6bec686a2113 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 dea667b78ff6..2277c9451c4f 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 (target.cpu.has(.sparc, .v9)) return 16 else return 8, .mips, .mipsel => switch (target.abi) { .none, .gnuabi64 => return 16, @@ -242,9 +242,9 @@ 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.os.tag.isDarwin() or + 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 +268,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 target.cpu.has(.powerpc, .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 9d441ad0fa1d..4ca22c7e3509 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 = target.cpu.has(.mips, .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/resinator/main.zig b/lib/compiler/resinator/main.zig index a918081226f5..6fc844b775a6 100644 --- a/lib/compiler/resinator/main.zig +++ b/lib/compiler/resinator/main.zig @@ -265,7 +265,7 @@ pub fn main() !void { fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.AutoIncludes, zig_lib_dir: []const u8) ![]const []const u8 { var includes = auto_includes_option; - if (builtin.target.os.tag != .windows) { + if (builtin.os.tag != .windows) { switch (includes) { // MSVC can't be found when the host isn't Windows, so short-circuit. .msvc => return error.MsvcIncludesNotFound, @@ -282,7 +282,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A // MSVC is only detectable on Windows targets. This unreachable is to signify // that .any and .msvc should be dealt with on non-Windows targets before this point, // since getting MSVC include paths uses Windows-only APIs. - if (builtin.target.os.tag != .windows) unreachable; + if (builtin.os.tag != .windows) unreachable; const target_query: std.Target.Query = .{ .os_tag = .windows, diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig index 0052662fbf08..83535ec8e594 100644 --- a/lib/compiler_rt/common.zig +++ b/lib/compiler_rt/common.zig @@ -13,7 +13,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.cpu.arch.isWasm() and linkage != .internal) .hidden else .default; pub const want_aeabi = switch (builtin.abi) { .eabi, .eabihf, @@ -96,7 +96,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_ pub fn F16T(comptime OtherType: type) type { return switch (builtin.cpu.arch) { .arm, .armeb, .thumb, .thumbeb => if (builtin.cpu.has(.arm, .has_v8)) - switch (builtin.abi.floatAbi()) { + switch (builtin.abi.float()) { .soft => u16, .hard => f16, } @@ -104,7 +104,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.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/compiler_rt/extendf_test.zig b/lib/compiler_rt/extendf_test.zig index bc154e750429..0a0b6dc7d050 100644 --- a/lib/compiler_rt/extendf_test.zig +++ b/lib/compiler_rt/extendf_test.zig @@ -140,7 +140,7 @@ test "extendhfsf2" { try test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN // On x86 the NaN becomes quiet because the return is pushed on the x87 // stack due to ABI requirements - if (builtin.target.cpu.arch != .x86 and builtin.target.os.tag == .windows) + if (builtin.cpu.arch != .x86 and builtin.os.tag == .windows) try test__extendhfsf2(0x7c01, 0x7f802000); // sNaN try test__extendhfsf2(0, 0); // 0 diff --git a/lib/compiler_rt/udivmod.zig b/lib/compiler_rt/udivmod.zig index a9705f317d32..c3d83b1f28c5 100644 --- a/lib/compiler_rt/udivmod.zig +++ b/lib/compiler_rt/udivmod.zig @@ -71,7 +71,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T { fn divwide(comptime T: type, _u1: T, _u0: T, v: T, r: *T) T { @setRuntimeSafety(is_test); - if (T == u64 and builtin.target.cpu.arch == .x86_64 and builtin.target.os.tag != .windows) { + if (T == u64 and builtin.cpu.arch == .x86_64 and builtin.os.tag != .windows) { var rem: T = undefined; const quo = asm ( \\divq %[v] diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index f0dad8b49aaa..2b83d41d02b0 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -457,7 +457,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, @@ -472,7 +472,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}); @@ -1519,7 +1519,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 4a8b5bdedbe3..00646fce2099 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -959,7 +959,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, @@ -2027,50 +2032,13 @@ 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); } -pub inline fn isSpirV(target: Target) bool { - return target.cpu.arch.isSpirV(); -} - -pub const FloatAbi = enum { - hard, - soft, -}; - -pub inline fn floatAbi(target: Target) FloatAbi { - return target.abi.floatAbi(); -} - 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 @@ -2714,7 +2682,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, @@ -3320,7 +3288,7 @@ pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention { .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) { .netbsd => .{ .arm_apcs = .{} }, .watchos => .{ .arm_aapcs16_vfp = .{} }, - else => switch (target.abi.floatAbi()) { + else => switch (target.abi.float()) { .soft => .{ .arm_aapcs = .{} }, .hard => .{ .arm_aapcs_vfp = .{} }, }, @@ -3334,7 +3302,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 d795fb6ef2b5..9c23cf77eee7 100644 --- a/lib/std/Target/Query.zig +++ b/lib/std/Target/Query.zig @@ -607,7 +607,7 @@ test parse { try std.testing.expectEqualSlices(u8, "native-native-gnu.2.1.1", text); } - if (builtin.target.abi.isAndroid()) { + if (builtin.abi.isAndroid()) { var query = try Query.parse(.{}); query.android_api_level = 30; diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index aa21a8a0ea6e..8b362f42d9f7 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -732,7 +732,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 2cd8e62f7cb8..b63553338c63 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.cpu.arch.isWasm()) WasmImpl else if (std.Thread.use_pthreads) PosixImpl @@ -100,7 +100,7 @@ const UnsupportedImpl = struct { fn unsupported(unused: anytype) noreturn { _ = unused; - @compileError("Unsupported operating system " ++ @tagName(builtin.target.os.tag)); + @compileError("Unsupported operating system " ++ @tagName(builtin.os.tag)); } }; @@ -180,7 +180,7 @@ const DarwinImpl = struct { // // ulock_wait() uses 32-bit micro-second timeouts where 0 = INFINITE or no-timeout // ulock_wait2() uses 64-bit nano-second timeouts (with the same convention) - const supports_ulock_wait2 = builtin.target.os.version_range.semver.min.major >= 11; + const supports_ulock_wait2 = builtin.os.version_range.semver.min.major >= 11; var timeout_ns: u64 = 0; if (timeout) |delay| { diff --git a/lib/std/Thread/Mutex.zig b/lib/std/Thread/Mutex.zig index be421c4c9401..69b1cbc3e4f5 100644 --- a/lib/std/Thread/Mutex.zig +++ b/lib/std/Thread/Mutex.zig @@ -158,7 +158,7 @@ const FutexImpl = struct { // On x86, use `lock bts` instead of `lock cmpxchg` as: // - they both seem to mark the cache-line as modified regardless: https://stackoverflow.com/a/63350048 // - `lock bts` is smaller instruction-wise which makes it better for inlining - if (comptime builtin.target.cpu.arch.isX86()) { + if (comptime builtin.cpu.arch.isX86()) { const locked_bit = @ctz(locked); return self.state.bitSet(locked_bit, .acquire) == 0; } diff --git a/lib/std/atomic.zig b/lib/std/atomic.zig index 7688c0dcd714..d3ba940dd2f1 100644 --- a/lib/std/atomic.zig +++ b/lib/std/atomic.zig @@ -348,7 +348,7 @@ test "Value.bitToggle" { /// Signals to the processor that the caller is inside a busy-wait spin-loop. pub inline fn spinLoopHint() void { - switch (builtin.target.cpu.arch) { + switch (builtin.cpu.arch) { // No-op instruction that can hint to save (or share with a hardware-thread) // pipelining/power resources // https://software.intel.com/content/www/us/en/develop/articles/benefitting-power-and-performance-sleep-loops.html diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 02948d660206..757300966c38 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -173,7 +173,7 @@ pub const CallingConvention = union(enum(u8)) { /// Functions marked as `extern` or `export` are given this calling convention by default. pub const c = builtin.target.cCallingConvention().?; - pub const winapi: CallingConvention = switch (builtin.target.cpu.arch) { + pub const winapi: CallingConvention = switch (builtin.cpu.arch) { .x86_64 => .{ .x86_64_win = .{} }, .x86 => .{ .x86_stdcall = .{} }, .aarch64 => .{ .aarch64_aapcs_win = .{} }, @@ -181,7 +181,7 @@ pub const CallingConvention = union(enum(u8)) { else => unreachable, }; - pub const kernel: CallingConvention = switch (builtin.target.cpu.arch) { + pub const kernel: CallingConvention = switch (builtin.cpu.arch) { .amdgcn => .amdgcn_kernel, .nvptx, .nvptx64 => .nvptx_kernel, .spirv, .spirv32, .spirv64 => .spirv_kernel, @@ -199,7 +199,7 @@ pub const CallingConvention = union(enum(u8)) { /// Deprecated; use `.@"inline"`. pub const Inline: CallingConvention = .@"inline"; /// Deprecated; use `.x86_64_interrupt`, `.x86_interrupt`, or `.avr_interrupt`. - pub const Interrupt: CallingConvention = switch (builtin.target.cpu.arch) { + pub const Interrupt: CallingConvention = switch (builtin.cpu.arch) { .x86_64 => .{ .x86_64_interrupt = .{} }, .x86 => .{ .x86_interrupt = .{} }, .avr => .avr_interrupt, @@ -212,7 +212,7 @@ pub const CallingConvention = union(enum(u8)) { /// Deprecated; use `.x86_fastcall`. pub const Fastcall: CallingConvention = .{ .x86_fastcall = .{} }; /// Deprecated; use `.x86_64_vectorcall`, `.x86_vectorcall`, or `aarch64_vfabi`. - pub const Vectorcall: CallingConvention = switch (builtin.target.cpu.arch) { + pub const Vectorcall: CallingConvention = switch (builtin.cpu.arch) { .x86_64 => .{ .x86_64_vectorcall = .{} }, .x86 => .{ .x86_vectorcall = .{} }, .aarch64, .aarch64_be => .{ .aarch64_vfabi = .{} }, @@ -906,7 +906,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.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 41c42aaa4b7b..3082b1c07e39 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -2731,7 +2731,7 @@ pub const Sigaction = switch (native_os) { .mipsel, .mips64, .mips64el, - => if (builtin.target.isMusl()) + => if (builtin.abi.isMusl()) linux.Sigaction else if (builtin.target.ptrBitWidth() == 64) extern struct { pub const handler_fn = *align(1) const fn (i32) callconv(.C) void; @@ -6448,7 +6448,7 @@ pub const Stat = switch (native_os) { return self.ctim; } }, - .mips, .mipsel => if (builtin.target.isMusl()) extern struct { + .mips, .mipsel => if (builtin.abi.isMusl()) extern struct { dev: dev_t, __pad0: [2]i32, ino: ino_t, @@ -6509,7 +6509,7 @@ pub const Stat = switch (native_os) { return self.ctim; } }, - .mips64, .mips64el => if (builtin.target.isMusl()) extern struct { + .mips64, .mips64el => if (builtin.abi.isMusl()) extern struct { dev: dev_t, __pad0: [3]i32, ino: ino_t, @@ -9589,16 +9589,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.abi.isAndroid() or builtin.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.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 (builtin.os.tag.isDarwin()) c_longdouble else extern struct { diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 573f29150d94..a9a8c28bbc64 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const native_arch = builtin.target.cpu.arch; +const native_arch = builtin.cpu.arch; const assert = std.debug.assert; const AF = std.c.AF; const PROT = std.c.PROT; @@ -977,7 +977,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.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/crypto/ml_kem.zig b/lib/std/crypto/ml_kem.zig index 950b72016b43..4299cfa003ed 100644 --- a/lib/std/crypto/ml_kem.zig +++ b/lib/std/crypto/ml_kem.zig @@ -1219,7 +1219,7 @@ const Poly = struct { // buf is interpreted as a₁…a_ηb₁…b_ηa₁…a_ηb₁…b_η…. We process // multiple coefficients in one batch. - const T = switch (builtin.target.cpu.arch) { + const T = switch (builtin.cpu.arch) { .x86_64, .x86 => u32, // Generates better code on Intel CPUs else => u64, // u128 might be faster on some other CPUs. }; diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 1529ad11304f..47d4e540a3e3 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -179,7 +179,7 @@ pub fn dumpHexFallible(bytes: []const u8) !void { /// TODO multithreaded awareness pub fn dumpCurrentStackTrace(start_addr: ?usize) void { nosuspend { - if (comptime builtin.target.isWasm()) { + if (builtin.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; @@ -267,7 +267,7 @@ pub inline fn getContext(context: *ThreadContext) bool { /// TODO multithreaded awareness pub fn dumpStackTraceFromBase(context: *ThreadContext) void { nosuspend { - if (comptime builtin.target.isWasm()) { + if (builtin.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; @@ -365,7 +365,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 (comptime builtin.target.isWasm()) { + if (builtin.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; @@ -655,7 +655,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.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 544cf0ac6ff4..69c2fadb2f43 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 (comptime builtin.target.isDarwin()) { + if (comptime builtin.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 (comptime builtin.target.isWasm()) { + } else if (builtin.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 (comptime builtin.target.isDarwin()) { + if (comptime builtin.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 (comptime builtin.target.isWasm()) { + } else if (builtin.cpu.arch.isWasm()) { return null; } else { return self.lookupModuleNameDl(address); diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 8deef118c01a..a9a7fba15018 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -2230,7 +2230,7 @@ test "float.special" { try expectFmt("f64: nan", "f64: {}", .{math.nan(f64)}); // negative nan is not defined by IEE 754, // and ARM thus normalizes it to positive nan - if (builtin.target.cpu.arch != .arm) { + if (builtin.cpu.arch != .arm) { try expectFmt("f64: -nan", "f64: {}", .{-math.nan(f64)}); } try expectFmt("f64: inf", "f64: {}", .{math.inf(f64)}); @@ -2241,7 +2241,7 @@ test "float.hexadecimal.special" { try expectFmt("f64: nan", "f64: {x}", .{math.nan(f64)}); // negative nan is not defined by IEE 754, // and ARM thus normalizes it to positive nan - if (builtin.target.cpu.arch != .arm) { + if (builtin.cpu.arch != .arm) { try expectFmt("f64: -nan", "f64: {x}", .{-math.nan(f64)}); } try expectFmt("f64: inf", "f64: {x}", .{math.inf(f64)}); @@ -2594,7 +2594,7 @@ test "positional/alignment/width/precision" { } test "vector" { - if (builtin.target.cpu.arch == .riscv64) { + if (builtin.cpu.arch == .riscv64) { // https://github.com/ziglang/zig/issues/4486 return error.SkipZigTest; } diff --git a/lib/std/fmt/format_float.zig b/lib/std/fmt/format_float.zig index 4c4c1a29229c..83e55421b987 100644 --- a/lib/std/fmt/format_float.zig +++ b/lib/std/fmt/format_float.zig @@ -1523,7 +1523,7 @@ fn check(comptime T: type, value: T, comptime expected: []const u8) !void { const s = try formatFloat(&buf, value, .{}); try std.testing.expectEqualStrings(expected, s); - if (T == f80 and builtin.target.os.tag == .windows and builtin.target.cpu.arch == .x86_64) return; + if (T == f80 and builtin.os.tag == .windows and builtin.cpu.arch == .x86_64) return; const o = try std.fmt.parseFloat(T, s); const o_bits: I = @bitCast(o); diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index fab9679838b3..7f97f566d13e 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -2594,7 +2594,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.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/fs/path.zig b/lib/std/fs/path.zig index 3376771313d6..f282137f60d8 100644 --- a/lib/std/fs/path.zig +++ b/lib/std/fs/path.zig @@ -26,7 +26,7 @@ const windows = std.os.windows; const os = std.os; const fs = std.fs; const process = std.process; -const native_os = builtin.target.os.tag; +const native_os = builtin.os.tag; pub const sep_windows = '\\'; pub const sep_posix = '/'; diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 618323dce364..98890a7436e3 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -220,7 +220,7 @@ fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void test "File.stat on a File that is a symlink returns Kind.sym_link" { // This test requires getting a file descriptor of a symlink which // is not possible on all targets - switch (builtin.target.os.tag) { + switch (builtin.os.tag) { .windows, .linux => {}, else => return error.SkipZigTest, } @@ -232,7 +232,7 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" { try setupSymlink(ctx.dir, dir_target_path, "symlink", .{ .is_directory = true }); - var symlink = switch (builtin.target.os.tag) { + var symlink = switch (builtin.os.tag) { .windows => windows_symlink: { const sub_path_w = try windows.cStrToPrefixedFileW(ctx.dir.fd, "symlink"); diff --git a/lib/std/heap.zig b/lib/std/heap.zig index 3d19d8daa6b2..cf4d138ea383 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -229,12 +229,12 @@ pub const page_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.cpu.arch.isWasm()) Allocator{ .ptr = undefined, .vtable = &WasmPageAllocator.vtable, } -else if (builtin.target.os.tag == .plan9) +else if (builtin.os.tag == .plan9) Allocator{ .ptr = undefined, .vtable = &SbrkAllocator(std.os.plan9.sbrk).vtable, @@ -611,7 +611,7 @@ test "PageAllocator" { const allocator = page_allocator; try testAllocator(allocator); try testAllocatorAligned(allocator); - if (!builtin.target.isWasm()) { + if (!builtin.cpu.arch.isWasm()) { try testAllocatorLargeAlignment(allocator); try testAllocatorAlignedShrink(allocator); } @@ -890,7 +890,7 @@ test { _ = @import("heap/memory_pool.zig"); _ = ArenaAllocator; _ = GeneralPurposeAllocator; - if (comptime builtin.target.isWasm()) { + if (comptime builtin.cpu.arch.isWasm()) { _ = WasmAllocator; _ = WasmPageAllocator; } diff --git a/lib/std/heap/WasmAllocator.zig b/lib/std/heap/WasmAllocator.zig index 61ad6247153f..685f048af1d0 100644 --- a/lib/std/heap/WasmAllocator.zig +++ b/lib/std/heap/WasmAllocator.zig @@ -9,7 +9,7 @@ const wasm = std.wasm; const math = std.math; comptime { - if (!builtin.target.isWasm()) { + if (!builtin.cpu.arch.isWasm()) { @compileError("WasmPageAllocator is only available for wasm32 arch"); } } diff --git a/lib/std/heap/WasmPageAllocator.zig b/lib/std/heap/WasmPageAllocator.zig index ca625e43ed6b..ebb44bdc0732 100644 --- a/lib/std/heap/WasmPageAllocator.zig +++ b/lib/std/heap/WasmPageAllocator.zig @@ -7,7 +7,7 @@ const maxInt = std.math.maxInt; const assert = std.debug.assert; comptime { - if (!builtin.target.isWasm()) { + if (!builtin.cpu.arch.isWasm()) { @compileError("WasmPageAllocator is only available for wasm32 arch"); } } diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig index 2e0ccc96c17b..4d6ab928859d 100644 --- a/lib/std/math/big/int_test.zig +++ b/lib/std/math/big/int_test.zig @@ -2237,7 +2237,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.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 aad2a104cc8b..1a4a05da9406 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.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 6f3d9a47f6d4..432c358f2527 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.cpu.arch.isWasm()) return error.SkipZigTest; // TODO inline for ( .{ u8, u16, u32, u64, u128, u256, u512 }, diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 5ca47731977e..bf4d9a35c800 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -1059,7 +1059,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil // us INVALID_PARAMETER. // The same reasoning for win10_rs5 as in os.renameatW() applies (FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE requires >= win10_rs5). var need_fallback = true; - if (comptime builtin.target.os.version_range.windows.min.isAtLeast(.win10_rs5)) { + if (comptime builtin.os.version_range.windows.min.isAtLeast(.win10_rs5)) { // Deletion with posix semantics if the filesystem supports it. var info = FILE_DISPOSITION_INFORMATION_EX{ .Flags = FILE_DISPOSITION_DELETE | diff --git a/lib/std/posix.zig b/lib/std/posix.zig index bb21a79690b8..bb3013fcc431 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -2783,7 +2783,7 @@ pub fn renameatW( // supported in order to avoid either (1) using a redundant call that we can know in advance will return // STATUS_NOT_SUPPORTED or (2) only setting IGNORE_READONLY_ATTRIBUTE when >= rs5 // and therefore having different behavior when the Windows version is >= rs1 but < rs5. - if (builtin.target.os.isAtLeast(.windows, .win10_rs5) orelse false) { + if (builtin.os.isAtLeast(.windows, .win10_rs5) orelse false) { const struct_buf_len = @sizeOf(windows.FILE_RENAME_INFORMATION_EX) + (max_path_bytes - 1); var rename_info_buf: [struct_buf_len]u8 align(@alignOf(windows.FILE_RENAME_INFORMATION_EX)) = undefined; const struct_len = @sizeOf(windows.FILE_RENAME_INFORMATION_EX) - 1 + new_path_w.len * 2; @@ -3566,7 +3566,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.os.tag.isDarwin() and native_os != .haiku; const filtered_sock_type = if (!have_sock_flags) socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC) else @@ -3862,7 +3862,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.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/posix/test.zig b/lib/std/posix/test.zig index dba7dcde6d9c..4453d6a79b6d 100644 --- a/lib/std/posix/test.zig +++ b/lib/std/posix/test.zig @@ -17,7 +17,7 @@ const a = std.testing.allocator; const builtin = @import("builtin"); const AtomicRmwOp = std.builtin.AtomicRmwOp; const AtomicOrder = std.builtin.AtomicOrder; -const native_os = builtin.target.os.tag; +const native_os = builtin.os.tag; const tmpDir = std.testing.tmpDir; const Dir = std.fs.Dir; const ArenaAllocator = std.heap.ArenaAllocator; @@ -838,11 +838,11 @@ test "sigaction" { return error.SkipZigTest; // https://github.com/ziglang/zig/issues/7427 - if (native_os == .linux and builtin.target.cpu.arch == .x86) + if (native_os == .linux and builtin.cpu.arch == .x86) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/15381 - if (native_os == .macos and builtin.target.cpu.arch == .x86_64) { + if (native_os == .macos and builtin.cpu.arch == .x86_64) { return error.SkipZigTest; } diff --git a/lib/std/valgrind.zig b/lib/std/valgrind.zig index 241f4c732a82..22ad0af1bf54 100644 --- a/lib/std/valgrind.zig +++ b/lib/std/valgrind.zig @@ -7,7 +7,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: return default; } - switch (builtin.target.cpu.arch) { + switch (builtin.cpu.arch) { .x86 => { return asm volatile ( \\ roll $3, %%edi ; roll $13, %%edi diff --git a/lib/std/zig/LibCDirs.zig b/lib/std/zig/LibCDirs.zig index 43c4c5d28fb9..21b0b86e3379 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 3d163532d147..d761119cd6fc 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 !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 @@ -198,14 +198,14 @@ pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation { try self.findNativeIncludeDirPosix(args); try self.findNativeGccDirHaiku(args); self.crt_dir = try args.allocator.dupeZ(u8, "/system/develop/lib"); - } else if (builtin.target.os.tag.isSolarish()) { + } else if (builtin.os.tag.isSolarish()) { // There is only one libc, and its headers/libraries are always in the same spot. self.include_dir = try args.allocator.dupeZ(u8, "/usr/include"); self.sys_include_dir = try args.allocator.dupeZ(u8, "/usr/include"); self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib/64"); } else if (std.process.can_spawn) { try self.findNativeIncludeDirPosix(args); - switch (builtin.target.os.tag) { + switch (builtin.os.tag) { .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib"), .linux => try self.findNativeCrtDirPosix(args), else => {}, @@ -407,7 +407,7 @@ fn findNativeCrtDirWindows( var result_buf = std.ArrayList(u8).init(allocator); defer result_buf.deinit(); - const arch_sub_dir = switch (builtin.target.cpu.arch) { + const arch_sub_dir = switch (builtin.cpu.arch) { .x86 => "x86", .x86_64 => "x64", .arm, .armeb => "arm", @@ -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, @@ -474,7 +474,7 @@ fn findNativeKernel32LibDir( var result_buf = std.ArrayList(u8).init(allocator); defer result_buf.deinit(); - const arch_sub_dir = switch (builtin.target.cpu.arch) { + const arch_sub_dir = switch (builtin.cpu.arch) { .x86 => "x86", .x86_64 => "x64", .arm, .armeb => "arm", @@ -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,8 +1025,8 @@ const fs = std.fs; const Allocator = std.mem.Allocator; const Path = std.Build.Cache.Path; -const is_darwin = builtin.target.isDarwin(); -const is_windows = builtin.target.os.tag == .windows; -const is_haiku = builtin.target.os.tag == .haiku; +const is_darwin = builtin.os.tag.isDarwin(); +const is_windows = builtin.os.tag == .windows; +const is_haiku = builtin.os.tag == .haiku; const log = std.log.scoped(.libc_installation); diff --git a/lib/std/zig/WindowsSdk.zig b/lib/std/zig/WindowsSdk.zig index 8fe37affc02d..fb759bcbae49 100644 --- a/lib/std/zig/WindowsSdk.zig +++ b/lib/std/zig/WindowsSdk.zig @@ -579,7 +579,7 @@ pub const Installation = struct { }; defer options_key.closeKey(); - const option_name = comptime switch (builtin.target.cpu.arch) { + const option_name = comptime switch (builtin.cpu.arch) { .thumb => "OptionId.DesktopCPParm", .aarch64 => "OptionId.DesktopCPParm64", .x86 => "OptionId.DesktopCPPx86", @@ -823,7 +823,7 @@ const MsvcLibDir = struct { lib_dir_buf.shrinkRetainingCapacity(installation_path_with_trailing_sep_len); try lib_dir_buf.appendSlice("VC\\Tools\\MSVC\\"); try lib_dir_buf.appendSlice(default_tools_version); - const folder_with_arch = "\\Lib\\" ++ comptime switch (builtin.target.cpu.arch) { + const folder_with_arch = "\\Lib\\" ++ comptime switch (builtin.cpu.arch) { .thumb => "arm", .aarch64 => "arm64", .x86 => "x86", @@ -908,7 +908,7 @@ const MsvcLibDir = struct { msvc_dir.shrinkRetainingCapacity(msvc_dir.items.len - "\\include".len); } - const folder_with_arch = "\\Lib\\" ++ comptime switch (builtin.target.cpu.arch) { + const folder_with_arch = "\\Lib\\" ++ comptime switch (builtin.cpu.arch) { .thumb => "arm", .aarch64 => "arm64", .x86 => "x86", @@ -976,7 +976,7 @@ const MsvcLibDir = struct { }; errdefer base_path.deinit(); - const folder_with_arch = "\\VC\\lib\\" ++ comptime switch (builtin.target.cpu.arch) { + const folder_with_arch = "\\VC\\lib\\" ++ comptime switch (builtin.cpu.arch) { .thumb => "arm", .aarch64 => "arm64", .x86 => "", //x86 is in the root of the Lib folder diff --git a/lib/std/zig/c_translation.zig b/lib/std/zig/c_translation.zig index 39f7fa9a113f..b650894457ce 100644 --- a/lib/std/zig/c_translation.zig +++ b/lib/std/zig/c_translation.zig @@ -509,7 +509,7 @@ fn ArithmeticConversion(comptime A: type, comptime B: type) type { test "ArithmeticConversion" { // Promotions not necessarily the same for other platforms - if (builtin.target.cpu.arch != .x86_64 or builtin.target.os.tag != .linux) return error.SkipZigTest; + if (builtin.cpu.arch != .x86_64 or builtin.os.tag != .linux) return error.SkipZigTest; const Test = struct { /// Order of operands should not matter for arithmetic conversions diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 2fdeb1bc36f3..cb880e0df48e 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -184,7 +184,7 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target { const query_os_tag = query.os_tag orelse builtin.os.tag; var os = query_os_tag.defaultVersionRange(query.cpu_arch orelse builtin.cpu.arch); if (query.os_tag == null) { - switch (builtin.target.os.tag) { + switch (builtin.os.tag) { .linux => { const uts = posix.uname(); const release = mem.sliceTo(&uts.release, 0); @@ -216,7 +216,7 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target { }, .macos => try darwin.macos.detect(&os), .freebsd, .netbsd, .dragonfly => { - const key = switch (builtin.target.os.tag) { + const key = switch (builtin.os.tag) { .freebsd => "kern.osreldate", .netbsd, .dragonfly => "kern.osrevision", else => unreachable, @@ -232,7 +232,7 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target { error.Unexpected => return error.OSVersionDetectionFail, }; - switch (builtin.target.os.tag) { + switch (builtin.os.tag) { .freebsd => { // https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/versions.html // Major * 100,000 has been convention since FreeBSD 2.2 (1997) @@ -401,7 +401,7 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target { } // https://github.com/llvm/llvm-project/issues/105978 - if (result.cpu.arch.isArm() and result.floatAbi() == .soft) { + if (result.cpu.arch.isArm() and result.abi.float() == .soft) { result.cpu.features.removeFeature(@intFromEnum(Target.arm.Feature.vfp2)); } @@ -542,7 +542,7 @@ pub fn abiAndDynamicLinkerFromFile( } }, // We only need this for detecting glibc version. - elf.PT_DYNAMIC => if (builtin.target.os.tag == .linux and result.isGnuLibC() and + elf.PT_DYNAMIC => if (builtin.os.tag == .linux and result.isGnuLibC() and query.glibc_version == null) { var dyn_off = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset); @@ -583,7 +583,7 @@ pub fn abiAndDynamicLinkerFromFile( } } - if (builtin.target.os.tag == .linux and result.isGnuLibC() and + if (builtin.os.tag == .linux and result.isGnuLibC() and query.glibc_version == null) { const shstrndx = elfInt(is_64, need_bswap, hdr32.e_shstrndx, hdr64.e_shstrndx); @@ -968,9 +968,9 @@ fn detectAbiAndDynamicLinker( query: Target.Query, ) DetectError!Target { const native_target_has_ld = comptime Target.DynamicLinker.kind(builtin.os.tag) != .none; - const is_linux = builtin.target.os.tag == .linux; - const is_solarish = builtin.target.os.tag.isSolarish(); - const is_darwin = builtin.target.os.tag.isDarwin(); + const is_linux = builtin.os.tag == .linux; + const is_solarish = builtin.os.tag.isSolarish(); + const is_darwin = builtin.os.tag.isDarwin(); const have_all_info = query.dynamic_linker.get() != null and query.abi != null and (!is_linux or query.abi.?.isGnu()); const os_is_non_native = query.os_tag != null; diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig index 3c961345567c..80f4a0be8334 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 (comptime builtin.target.isDarwin()) { + if (comptime builtin.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" })); diff --git a/src/Compilation.zig b/src/Compilation.zig index 128e4e7411d3..c3e2758bd0f2 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1745,7 +1745,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil if (comp.config.link_libc and is_exe_or_dyn_lib) { // If the "is darwin" check is moved below the libc_installation check below, // error.LibCInstallationMissingCrtDir is returned from lci.resolveCrtPaths(). - if (target.isDarwin()) { + if (target.os.tag.isDarwin()) { switch (target.abi) { .none, .simulator, .macabi => {}, else => return error.LibCUnavailable, @@ -1826,7 +1826,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil // When linking mingw-w64 there are some import libs we always need. try comp.windows_libs.ensureUnusedCapacity(gpa, mingw.always_link_libs.len); for (mingw.always_link_libs) |name| comp.windows_libs.putAssumeCapacity(name, {}); - } else if (target.isDarwin()) { + } else if (target.os.tag.isDarwin()) { switch (target.abi) { .none, .simulator, .macabi => {}, else => return error.LibCUnavailable, @@ -5655,7 +5655,7 @@ pub fn addCCArgs( // We might want to support -mfloat-abi=softfp for Arm and CSKY here in the future. if (target_util.clangSupportsFloatAbiArg(target)) { - const fabi = @tagName(target.floatAbi()); + const fabi = @tagName(target.abi.float()); try argv.append(switch (target.cpu.arch) { // For whatever reason, Clang doesn't support `-mfloat-abi` for s390x. @@ -5664,12 +5664,12 @@ pub fn addCCArgs( }); } - if (target_util.clangSupportsNoImplicitFloatArg(target) and target.floatAbi() == .soft) { + if (target_util.clangSupportsNoImplicitFloatArg(target) and target.abi.float() == .soft) { try argv.append("-mno-implicit-float"); } // https://github.com/llvm/llvm-project/issues/105972 - if (target.cpu.arch.isPowerPC() and target.floatAbi() == .soft) { + if (target.cpu.arch.isPowerPC() and target.abi.float() == .soft) { try argv.append("-D__NO_FPRS__"); try argv.append("-D_SOFT_FLOAT"); try argv.append("-D_SOFT_DOUBLE"); diff --git a/src/Sema.zig b/src/Sema.zig index 6ae8a463f74f..1cda8f68325c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -9657,7 +9657,7 @@ fn handleExternLibName( ); break :blk; } - if (!target.isWasm() and !block.ownerModule().pic) { + if (!target.cpu.arch.isWasm() and !block.ownerModule().pic) { return sema.fail( block, src_loc, @@ -27119,7 +27119,7 @@ fn zirWasmMemorySize( const index_src = block.builtinCallArgSrc(extra.node, 0); const builtin_src = block.nodeOffset(extra.node); const target = sema.pt.zcu.getTarget(); - if (!target.isWasm()) { + if (!target.cpu.arch.isWasm()) { return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); } @@ -27146,7 +27146,7 @@ fn zirWasmMemoryGrow( const index_src = block.builtinCallArgSrc(extra.node, 0); const delta_src = block.builtinCallArgSrc(extra.node, 1); const target = sema.pt.zcu.getTarget(); - if (!target.isWasm()) { + if (!target.cpu.arch.isWasm()) { return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); } diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index a5b0ee5dc09e..d2378b9703ff 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -19799,7 +19799,7 @@ fn floatCompilerRtAbiName(float_bits: u32) u8 { fn floatCompilerRtAbiType(self: *Self, ty: Type, other_ty: Type) Type { if (ty.toIntern() == .f16_type and (other_ty.toIntern() == .f32_type or other_ty.toIntern() == .f64_type) and - self.target.isDarwin()) return Type.u16; + self.target.os.tag.isDarwin()) return Type.u16; return ty; } diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 3a8811b37857..571e595ccb78 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1399,7 +1399,7 @@ pub const Object = struct { .large => .Large, }; - const float_abi: llvm.TargetMachine.FloatABI = if (comp.root_mod.resolved_target.result.floatAbi() == .hard) + const float_abi: llvm.TargetMachine.FloatABI = if (comp.root_mod.resolved_target.result.abi.float() == .hard) .Hard else .Soft; @@ -3051,7 +3051,7 @@ pub const Object = struct { function_index.setLinkage(.internal, &o.builder); function_index.setUnnamedAddr(.unnamed_addr, &o.builder); } else { - if (target.isWasm()) { + if (target.cpu.arch.isWasm()) { try attributes.addFnAttr(.{ .string = .{ .kind = try o.builder.string("wasm-import-name"), .value = try o.builder.string(nav.name.toSlice(ip)), @@ -3268,7 +3268,7 @@ pub const Object = struct { .value = try o.builder.string(std.mem.span(s)), } }, &o.builder); } - if (target.floatAbi() == .soft) { + if (target.abi.float() == .soft) { // `use-soft-float` means "use software routines for floating point computations". In // other words, it configures how LLVM lowers basic float instructions like `fcmp`, // `fadd`, etc. The float calling convention is configured on `TargetMachine` and is @@ -4952,7 +4952,7 @@ pub const NavGen = struct { const global_index = o.nav_map.get(nav_index).?; const decl_name = decl_name: { - if (zcu.getTarget().isWasm() and ty.zigTypeTag(zcu) == .@"fn") { + if (zcu.getTarget().cpu.arch.isWasm() and ty.zigTypeTag(zcu) == .@"fn") { if (lib_name.toSlice(ip)) |lib_name_slice| { if (!std.mem.eql(u8, lib_name_slice, "c")) { break :decl_name try o.builder.strtabStringFmt("{}|{s}", .{ nav.name.fmt(ip), lib_name_slice }); @@ -6714,7 +6714,7 @@ pub const FuncGen = struct { // Workaround for: // * https://github.com/llvm/llvm-project/blob/56905dab7da50bccfcceaeb496b206ff476127e1/llvm/lib/MC/WasmObjectWriter.cpp#L560 // * https://github.com/llvm/llvm-project/blob/56905dab7da50bccfcceaeb496b206ff476127e1/llvm/test/MC/WebAssembly/blockaddress.ll - if (zcu.comp.getTarget().isWasm()) break :jmp_table null; + if (zcu.comp.getTarget().cpu.arch.isWasm()) break :jmp_table null; // On a 64-bit target, 1024 pointers in our jump table is about 8K of pointers. This seems just // about acceptable - it won't fill L1d cache on most CPUs. @@ -10052,7 +10052,7 @@ pub const FuncGen = struct { // of the length. This means we need to emit a check where we skip the memset when the length // is 0 as we allow for undefined pointers in 0-sized slices. // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done. - const intrinsic_len0_traps = o.target.isWasm() and + const intrinsic_len0_traps = o.target.cpu.arch.isWasm() and ptr_ty.isSlice(zcu) and o.target.cpu.has(.wasm, .bulk_memory); @@ -10209,7 +10209,7 @@ pub const FuncGen = struct { // For this reason we must add a check for 0-sized slices as its pointer field can be undefined. // We only have to do this for slices as arrays will have a valid pointer. // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done. - if (o.target.isWasm() and + if (o.target.cpu.arch.isWasm() and o.target.cpu.has(.wasm, .bulk_memory) and dest_ptr_ty.isSlice(zcu)) { @@ -12679,7 +12679,7 @@ fn backendSupportsF16(target: std.Target) bool { .armeb, .thumb, .thumbeb, - => target.floatAbi() == .soft or target.cpu.has(.arm, .fp_armv8), + => target.abi.float() == .soft or target.cpu.has(.arm, .fp_armv8), .aarch64, .aarch64_be, => target.cpu.has(.aarch64, .fp_armv8), @@ -12706,7 +12706,7 @@ fn backendSupportsF128(target: std.Target) bool { .armeb, .thumb, .thumbeb, - => target.floatAbi() == .soft or target.cpu.has(.arm, .fp_armv8), + => target.abi.float() == .soft or target.cpu.has(.arm, .fp_armv8), .aarch64, .aarch64_be, => target.cpu.has(.aarch64, .fp_armv8), diff --git a/src/libtsan.zig b/src/libtsan.zig index d078fa2a38cf..983dd0fc35ac 100644 --- a/src/libtsan.zig +++ b/src/libtsan.zig @@ -36,7 +36,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo }, else => "tsan", }; - const link_mode: std.builtin.LinkMode = if (target.isDarwin()) .dynamic else .static; + const link_mode: std.builtin.LinkMode = if (target.os.tag.isDarwin()) .dynamic else .static; const output_mode = .Lib; const basename = try std.zig.binNameAlloc(arena, .{ .root_name = root_name, @@ -52,7 +52,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo const optimize_mode = comp.compilerRtOptMode(); const strip = comp.compilerRtStrip(); - const link_libcpp = target.isDarwin(); + const link_libcpp = target.os.tag.isDarwin(); const config = Compilation.Config.resolve(.{ .output_mode = output_mode, @@ -286,14 +286,14 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo }); } - const skip_linker_dependencies = !target.isDarwin(); - const linker_allow_shlib_undefined = target.isDarwin(); - const install_name = if (target.isDarwin()) + const skip_linker_dependencies = !target.os.tag.isDarwin(); + const linker_allow_shlib_undefined = target.os.tag.isDarwin(); + const install_name = if (target.os.tag.isDarwin()) try std.fmt.allocPrintZ(arena, "@rpath/{s}", .{basename}) else null; // Workaround for https://github.com/llvm/llvm-project/issues/97627 - const headerpad_size: ?u32 = if (target.isDarwin()) 32 else null; + const headerpad_size: ?u32 = if (target.os.tag.isDarwin()) 32 else null; const sub_compilation = Compilation.create(comp.gpa, arena, .{ .local_cache_directory = comp.global_cache_directory, .global_cache_directory = comp.global_cache_directory, diff --git a/src/libunwind.zig b/src/libunwind.zig index d7b22e206791..49a9aaea6ffe 100644 --- a/src/libunwind.zig +++ b/src/libunwind.zig @@ -136,7 +136,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr if (!comp.config.any_non_single_threaded) { try cflags.append("-D_LIBUNWIND_HAS_NO_THREADS"); } - if (target.cpu.arch.isArm() and target.abi.floatAbi() == .hard) { + if (target.cpu.arch.isArm() and target.abi.float() == .hard) { try cflags.append("-DCOMPILER_RT_ARMHF_TARGET"); } try cflags.append("-Wno-bitwise-conditional-parentheses"); diff --git a/src/link.zig b/src/link.zig index 7f53bde3201f..363223af6bb2 100644 --- a/src/link.zig +++ b/src/link.zig @@ -1304,7 +1304,7 @@ pub const File = struct { // with 0o755 permissions, but it works appropriately if the system is configured // more leniently. As another data point, C's fopen seems to open files with the // 666 mode. - const executable_mode = if (builtin.target.os.tag == .windows) 0 else 0o777; + const executable_mode = if (builtin.os.tag == .windows) 0 else 0o777; switch (effectiveOutputMode(use_lld, output_mode)) { .Lib => return switch (link_mode) { .dynamic => executable_mode, @@ -2025,7 +2025,7 @@ fn resolveLibInput( const lib_name = name_query.name; - if (target.isDarwin() and link_mode == .dynamic) tbd: { + if (target.os.tag.isDarwin() and link_mode == .dynamic) tbd: { // Prefer .tbd over .dylib. const test_path: Path = .{ .root_dir = lib_directory, @@ -2062,7 +2062,7 @@ fn resolveLibInput( // In the case of Darwin, the main check will be .dylib, so here we // additionally check for .so files. - if (target.isDarwin() and link_mode == .dynamic) so: { + if (target.os.tag.isDarwin() and link_mode == .dynamic) so: { const test_path: Path = .{ .root_dir = lib_directory, .sub_path = try std.fmt.allocPrint(arena, "lib{s}.so", .{lib_name}), diff --git a/src/link/Coff.zig b/src/link/Coff.zig index cf691c4f122d..ea2c634a3f4a 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -87,7 +87,7 @@ base_relocs: BaseRelocationTable = .{}, /// Hot-code swapping state. hot_state: if (is_hot_update_compatible) HotUpdateState else struct {} = .{}, -const is_hot_update_compatible = switch (builtin.target.os.tag) { +const is_hot_update_compatible = switch (builtin.os.tag) { .windows => true, else => false, }; diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 8f39d3412fcc..6ceea975db64 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -2026,7 +2026,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s try argv.append(lib_path); } try argv.append(try comp.crtFileAsString(arena, "libc_nonshared.a")); - } else if (target.isMusl()) { + } else if (target.abi.isMusl()) { try argv.append(try comp.crtFileAsString(arena, switch (link_mode) { .static => "libc.a", .dynamic => "libc.so", diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 1ffcabb1f50b..53e9ff1bac52 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -3513,7 +3513,7 @@ pub fn getTarget(self: MachO) std.Target { pub fn invalidateKernelCache(dir: fs.Dir, sub_path: []const u8) !void { const tracy = trace(@src()); defer tracy.end(); - if (comptime builtin.target.isDarwin() and builtin.target.cpu.arch == .aarch64) { + if (comptime builtin.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) { try dir.copyFile(sub_path, dir, sub_path, .{}); } } @@ -4002,7 +4002,7 @@ fn formatSectType( try writer.print("{s}", .{name}); } -const is_hot_update_compatible = switch (builtin.target.os.tag) { +const is_hot_update_compatible = switch (builtin.os.tag) { .macos => true, else => false, }; diff --git a/src/main.zig b/src/main.zig index 24fc0aa60cb3..318c29c684dd 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3897,7 +3897,7 @@ fn createModule( } create_module.lib_dir_args = undefined; // From here we use lib_directories instead. - if (resolved_target.is_native_os and target.isDarwin()) { + if (resolved_target.is_native_os and target.os.tag.isDarwin()) { // If we want to link against frameworks, we need system headers. if (create_module.frameworks.count() > 0) create_module.want_native_include_dirs = true; @@ -3939,7 +3939,7 @@ fn createModule( }; } - if (builtin.target.os.tag == .windows and (target.abi == .msvc or target.abi == .itanium) and + if (builtin.os.tag == .windows and (target.abi == .msvc or target.abi == .itanium) and any_name_queries_remaining) { if (create_module.libc_installation == null) { @@ -4323,7 +4323,7 @@ fn runOrTestHotSwap( ) !std.process.Child.Id { const lf = comp.bin_file.?; - const exe_path = switch (builtin.target.os.tag) { + const exe_path = switch (builtin.os.tag) { // On Windows it seems impossible to perform an atomic rename of a file that is currently // running in a process. Therefore, we do the opposite. We create a copy of the file in // tmp zig-cache and use it to spawn the child process. This way we are free to update @@ -4372,7 +4372,7 @@ fn runOrTestHotSwap( try argv.appendSlice(all_args[i..]); } - switch (builtin.target.os.tag) { + switch (builtin.os.tag) { .macos, .ios, .tvos, .watchos, .visionos => { const PosixSpawn = @import("DarwinPosixSpawn.zig"); diff --git a/src/target.zig b/src/target.zig index a9edcd606d24..f95768cf974c 100644 --- a/src/target.zig +++ b/src/target.zig @@ -11,7 +11,7 @@ pub const default_stack_protector_buffer_size = 4; pub fn cannotDynamicLink(target: std.Target) bool { return switch (target.os.tag) { .freestanding => true, - else => target.isSpirV(), + else => target.cpu.arch.isSpirV(), }; } @@ -39,12 +39,12 @@ pub fn libcNeedsLibUnwind(target: std.Target) bool { } pub fn requiresPIE(target: std.Target) bool { - return target.isAndroid() or target.isDarwin() or target.os.tag == .openbsd; + return target.abi.isAndroid() or target.os.tag.isDarwin() or target.os.tag == .openbsd; } /// This function returns whether non-pic code is completely invalid on the given target. pub fn requiresPIC(target: std.Target, linking_libc: bool) bool { - return target.isAndroid() or + return target.abi.isAndroid() or target.os.tag == .windows or target.os.tag == .uefi or osRequiresLibC(target) or (linking_libc and target.isGnuLibC()); @@ -220,7 +220,7 @@ pub fn clangSupportsStackProtector(target: std.Target) bool { } pub fn libcProvidesStackProtector(target: std.Target) bool { - return !target.isMinGW() and target.os.tag != .wasi and !target.isSpirV(); + return !target.isMinGW() and target.os.tag != .wasi and !target.cpu.arch.isSpirV(); } pub fn supportsReturnAddress(target: std.Target) bool { @@ -379,7 +379,7 @@ pub fn clangSupportsNoImplicitFloatArg(target: std.Target) bool { } pub fn needUnwindTables(target: std.Target) bool { - return target.os.tag == .windows or target.isDarwin() or std.debug.Dwarf.abi.supportsUnwinding(target); + return target.os.tag == .windows or target.os.tag.isDarwin() or std.debug.Dwarf.abi.supportsUnwinding(target); } pub fn defaultAddressSpace( diff --git a/test/behavior/abs.zig b/test/behavior/abs.zig index 1493e2dbd185..8ce1a7eb18f1 100644 --- a/test/behavior/abs.zig +++ b/test/behavior/abs.zig @@ -346,7 +346,7 @@ test "@abs float vectors" { // https://github.com/ziglang/zig/issues/12827 if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos and - builtin.target.cpu.arch == .x86_64) return error.SkipZigTest; + builtin.cpu.arch == .x86_64) return error.SkipZigTest; @setEvalBranchQuota(2000); try comptime testAbsFloatVectors(f16, 1); diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 6e6a1ac31930..60ba2c628fa7 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -1,7 +1,7 @@ const std = @import("std"); const expect = std.testing.expect; const builtin = @import("builtin"); -const native_arch = builtin.target.cpu.arch; +const native_arch = builtin.cpu.arch; const assert = std.debug.assert; var foo: u8 align(4) = 100; diff --git a/test/behavior/alignof.zig b/test/behavior/alignof.zig index e08a42cf1930..2c6e581fe11f 100644 --- a/test/behavior/alignof.zig +++ b/test/behavior/alignof.zig @@ -2,7 +2,7 @@ const std = @import("std"); const assert = std.debug.assert; const expect = std.testing.expect; const builtin = @import("builtin"); -const native_arch = builtin.target.cpu.arch; +const native_arch = builtin.cpu.arch; const maxInt = std.math.maxInt; const Foo = struct { diff --git a/test/behavior/asm.zig b/test/behavior/asm.zig index e82242f4257b..bebe80ec58a2 100644 --- a/test/behavior/asm.zig +++ b/test/behavior/asm.zig @@ -166,7 +166,7 @@ export fn derp() i32 { test "rw constraint (x86_64)" { if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; - if (builtin.target.cpu.arch != .x86_64) return error.SkipZigTest; + if (builtin.cpu.arch != .x86_64) return error.SkipZigTest; var res: i32 = 5; asm ("addl %[b], %[a]" @@ -178,7 +178,7 @@ test "rw constraint (x86_64)" { } test "asm modifiers (AArch64)" { - if (builtin.target.cpu.arch != .aarch64) return error.SkipZigTest; + if (builtin.cpu.arch != .aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support inline assembly diff --git a/test/behavior/async_fn.zig b/test/behavior/async_fn.zig index 17b2a4d99881..669e3ce9d0a1 100644 --- a/test/behavior/async_fn.zig +++ b/test/behavior/async_fn.zig @@ -131,7 +131,7 @@ test "@frameSize" { if (true) return error.SkipZigTest; // TODO if (builtin.os.tag == .wasi) return error.SkipZigTest; // TODO - if (builtin.target.cpu.arch == .thumb or builtin.target.cpu.arch == .thumbeb) + if (builtin.cpu.arch == .thumb or builtin.cpu.arch == .thumbeb) return error.SkipZigTest; const S = struct { diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig index 8dee05406a9e..351235693b6d 100644 --- a/test/behavior/floatop.zig +++ b/test/behavior/floatop.zig @@ -126,7 +126,7 @@ test "cmp f16" { if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; - 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.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 try testCmp(f16); try comptime testCmp(f16); @@ -135,7 +135,7 @@ test "cmp f16" { test "cmp f32/f64" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; - 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.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 try testCmp(f32); try comptime testCmp(f32); diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig index 41e9f11f0b42..aaad3726bcad 100644 --- a/test/behavior/fn.zig +++ b/test/behavior/fn.zig @@ -153,9 +153,9 @@ test "extern struct with stdcallcc fn pointer" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const S = extern struct { - ptr: *const fn () callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .C) i32, + ptr: *const fn () callconv(if (builtin.cpu.arch == .x86) .Stdcall else .C) i32, - fn foo() callconv(if (builtin.target.cpu.arch == .x86) .Stdcall else .C) i32 { + fn foo() callconv(if (builtin.cpu.arch == .x86) .Stdcall else .C) i32 { return 1234; } }; diff --git a/test/behavior/import_c_keywords.zig b/test/behavior/import_c_keywords.zig index 9029dca31d49..4cfa73f87fa2 100644 --- a/test/behavior/import_c_keywords.zig +++ b/test/behavior/import_c_keywords.zig @@ -79,7 +79,7 @@ test "import c keywords" { ptr_id = &an_alias_of_some_non_c_keyword_constant; try std.testing.expect(ptr_id == &some_non_c_keyword_constant); - if (builtin.target.ofmt != .coff and builtin.target.os.tag != .windows) { + if (builtin.target.ofmt != .coff and builtin.os.tag != .windows) { var ptr_fn: *const fn () callconv(.C) Id = &double; try std.testing.expect(ptr_fn == &float); ptr_fn = &an_alias_of_float; diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 7ef67db89555..bd21e8484a8d 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -1579,7 +1579,7 @@ test "NaN comparison" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; - 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.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 try testNanEqNan(f16); try testNanEqNan(f32); @@ -1734,7 +1734,7 @@ test "runtime comparison to NaN is comptime-known" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; - 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.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 const S = struct { fn doTheTest(comptime F: type, x: F) void { @@ -1765,7 +1765,7 @@ test "runtime int comparison to inf is comptime-known" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; - 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.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 const S = struct { fn doTheTest(comptime F: type, x: u32) void { diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index 19dca9821870..4f488aa4feff 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -986,7 +986,7 @@ test "saturating multiplication" { if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO: once #9660 has been solved, remove this line - if (builtin.target.cpu.arch == .wasm32) return error.SkipZigTest; + if (builtin.cpu.arch == .wasm32) return error.SkipZigTest; const S = struct { fn doTheTest() !void { diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index 7c25bc887574..d6c7443a6b3f 100644 --- a/test/c_abi/main.zig +++ b/test/c_abi/main.zig @@ -135,7 +135,7 @@ export fn zig_f64(x: f64) void { expect(x == 56.78) catch @panic("test failure: zig_f64"); } export fn zig_longdouble(x: c_longdouble) void { - if (!builtin.target.isWasm()) return; // waiting for #1481 + if (!builtin.cpu.arch.isWasm()) return; // waiting for #1481 expect(x == 12.34) catch @panic("test failure: zig_longdouble"); } @@ -1659,7 +1659,7 @@ test "bool simd vector" { } { - if (!builtin.target.isWasm()) c_vector_256_bool(.{ + if (!builtin.cpu.arch.isWasm()) c_vector_256_bool(.{ false, true, true, @@ -2177,7 +2177,7 @@ test "bool simd vector" { try expect(vec[255] == false); } { - if (!builtin.target.isWasm()) c_vector_512_bool(.{ + if (!builtin.cpu.arch.isWasm()) c_vector_512_bool(.{ true, true, true, @@ -5403,7 +5403,7 @@ pub export fn zig_ret_DC() DC { const CFF = extern struct { v1: u8, v2: f32, v3: f32 }; test "CFF: Zig passes to C" { - if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; + if (builtin.cpu.arch == .x86) return error.SkipZigTest; if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest; try expectOk(c_assert_CFF(.{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 })); @@ -5414,7 +5414,7 @@ test "CFF: Zig returns to C" { try expectOk(c_assert_ret_CFF()); } test "CFF: C passes to Zig" { - if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; + if (builtin.cpu.arch == .x86) return error.SkipZigTest; if (builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest; if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest; if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; @@ -5549,8 +5549,8 @@ const f16_struct = extern struct { }; extern fn c_f16_struct(f16_struct) f16_struct; test "f16 struct" { - if (builtin.target.cpu.arch.isMIPS64()) return error.SkipZigTest; - if (builtin.target.cpu.arch.isPowerPC32()) return error.SkipZigTest; + if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; + if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest; if (builtin.cpu.arch.isArm() and builtin.mode != .Debug) return error.SkipZigTest; const a = c_f16_struct(.{ .a = 12 }); @@ -5591,7 +5591,7 @@ test "f80 extra struct" { comptime { skip: { - if (builtin.target.isWasm()) break :skip; + if (builtin.cpu.arch.isWasm()) break :skip; _ = struct { export fn zig_f128(x: f128) f128 { diff --git a/test/link/glibc_compat/glibc_runtime_check.zig b/test/link/glibc_compat/glibc_runtime_check.zig index 5a925d8583f4..2f9fcda8a555 100644 --- a/test/link/glibc_compat/glibc_runtime_check.zig +++ b/test/link/glibc_compat/glibc_runtime_check.zig @@ -21,7 +21,7 @@ const c_string = @cImport( ); // Version of glibc this test is being built to run against -const glibc_ver = builtin.target.os.version_range.linux.glibc; +const glibc_ver = builtin.os.version_range.linux.glibc; // PR #17034 - fstat moved between libc_nonshared and libc fn checkStat() !void { diff --git a/test/standalone/stack_iterator/build.zig b/test/standalone/stack_iterator/build.zig index d69d59091238..4b68eaac8406 100644 --- a/test/standalone/stack_iterator/build.zig +++ b/test/standalone/stack_iterator/build.zig @@ -23,7 +23,7 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("unwind.zig"), .target = target, .optimize = optimize, - .unwind_tables = if (target.result.isDarwin()) true else null, + .unwind_tables = if (target.result.os.tag.isDarwin()) true else null, .omit_frame_pointer = false, }); @@ -85,7 +85,7 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("shared_lib_unwind.zig"), .target = target, .optimize = optimize, - .unwind_tables = if (target.result.isDarwin()) true else null, + .unwind_tables = if (target.result.os.tag.isDarwin()) true else null, .omit_frame_pointer = true, }); diff --git a/test/standalone/stack_iterator/shared_lib_unwind.zig b/test/standalone/stack_iterator/shared_lib_unwind.zig index d8e2e883d513..f459ac964db4 100644 --- a/test/standalone/stack_iterator/shared_lib_unwind.zig +++ b/test/standalone/stack_iterator/shared_lib_unwind.zig @@ -36,8 +36,8 @@ extern fn frame0( pub fn main() !void { // Disabled until the DWARF unwinder bugs on .aarch64 are solved - if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return; - if (builtin.target.isDarwin() and builtin.cpu.arch == .x86_64) return; // https://github.com/ziglang/zig/issues/21337 + if (builtin.omit_frame_pointer and comptime builtin.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) return; + if (builtin.os.tag.isDarwin() and builtin.cpu.arch == .x86_64) return; // https://github.com/ziglang/zig/issues/21337 if (!std.debug.have_ucontext or !std.debug.have_getcontext) return; diff --git a/test/standalone/stack_iterator/unwind.zig b/test/standalone/stack_iterator/unwind.zig index 69c463a0c116..6e703a2de1a7 100644 --- a/test/standalone/stack_iterator/unwind.zig +++ b/test/standalone/stack_iterator/unwind.zig @@ -88,7 +88,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void { pub fn main() !void { // Disabled until the DWARF unwinder bugs on .aarch64 are solved - if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return; + if (builtin.omit_frame_pointer and comptime builtin.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) return; if (!std.debug.have_ucontext or !std.debug.have_getcontext) return;