From 481b7bf3f095488a89e20d88ada092529bc6e6f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 24 Jan 2025 03:45:38 +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 obviously quickly gets out of hand. * It's nice to just have a single correct way of doing something. --- build.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 | 17 +++-- lib/compiler/aro/aro/toolchains/Linux.zig | 14 ++-- lib/compiler_rt/common.zig | 6 +- lib/std/Build/Step/Compile.zig | 6 +- lib/std/Target.zig | 66 +++++++------------ lib/std/Target/Query.zig | 5 +- lib/std/Thread.zig | 2 +- lib/std/Thread/Futex.zig | 2 +- lib/std/builtin.zig | 2 +- lib/std/c.zig | 12 ++-- lib/std/c/darwin.zig | 2 +- lib/std/debug.zig | 8 +-- lib/std/debug/SelfInfo.zig | 8 +-- lib/std/fs/Dir.zig | 2 +- lib/std/heap.zig | 6 +- lib/std/heap/WasmAllocator.zig | 2 +- lib/std/heap/debug_allocator.zig | 4 +- lib/std/math/big/int_test.zig | 2 +- lib/std/math/gamma.zig | 2 +- lib/std/math/log10.zig | 2 +- lib/std/posix.zig | 4 +- lib/std/zig/LibCDirs.zig | 4 +- lib/std/zig/LibCInstallation.zig | 10 +-- lib/std/zig/system.zig | 2 +- lib/std/zig/system/NativePaths.zig | 2 +- src/Compilation.zig | 21 ++---- 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 | 4 +- src/link/Coff.zig | 2 +- src/link/Elf.zig | 4 +- src/link/MachO.zig | 2 +- src/main.zig | 2 +- src/target.zig | 8 +-- test/behavior/floatop.zig | 4 +- test/behavior/math.zig | 6 +- test/c_abi/main.zig | 8 +-- test/standalone/stack_iterator/build.zig | 4 +- .../stack_iterator/shared_lib_unwind.zig | 4 +- test/standalone/stack_iterator/unwind.zig | 2 +- 48 files changed, 149 insertions(+), 178 deletions(-) diff --git a/build.zig b/build.zig index 5ef2a76908..2d196041b3 100644 --- a/build.zig +++ b/build.zig @@ -742,7 +742,7 @@ fn addCmakeCfgOptionsToExe( const mod = exe.root_module; const target = mod.resolved_target.?.result; - if (target.isDarwin()) { + if (target.os.tag.isDarwin()) { // useful for package maintainers exe.headerpad_max_install_names = true; } 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" })); diff --git a/src/Compilation.zig b/src/Compilation.zig index 5bbeca4b7d..aafbc30fef 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1766,11 +1766,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()) { - switch (target.abi) { - .none, .simulator, .macabi => {}, - else => return error.LibCUnavailable, - } + if (target.isDarwinLibC()) { // TODO delete logic from MachO flush() and queue up tasks here instead. } else if (comp.libc_installation) |lci| { const basenames = LibCInstallation.CrtBasenames.get(.{ @@ -1793,7 +1789,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil // Loads the libraries provided by `target_util.libcFullLinkFlags(target)`. comp.link_task_queue.shared.appendAssumeCapacity(.load_host_libc); comp.remaining_prelink_tasks += 1; - } else if (target.isMusl() and !target.isWasm()) { + } else if (target.isMuslLibC()) { if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; if (musl.needsCrt0(comp.config.output_mode, comp.config.link_mode, comp.config.pie)) |f| { @@ -1817,7 +1813,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil comp.queued_jobs.glibc_crt_file[@intFromEnum(glibc.CrtFile.libc_nonshared_a)] = true; comp.remaining_prelink_tasks += 1; - } else if (target.isWasm() and target.os.tag == .wasi) { + } else if (target.isWasiLibC()) { if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; for (comp.wasi_emulated_libs) |crt_file| { @@ -1839,11 +1835,6 @@ 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()) { - switch (target.abi) { - .none, .simulator, .macabi => {}, - else => return error.LibCUnavailable, - } } else if (target.os.tag == .freestanding and capable_of_building_zig_libc) { comp.queued_jobs.zig_libc = true; comp.remaining_prelink_tasks += 1; @@ -5545,7 +5536,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. @@ -5598,7 +5589,7 @@ pub fn addCCArgs( if (ext != .assembly) { try argv.append(if (target.os.tag == .freestanding) "-ffreestanding" else "-fhosted"); - 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"); } @@ -5646,7 +5637,7 @@ pub fn addCCArgs( // LLVM IR files don't support these flags. if (ext != .ll and ext != .bc) { // 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 78a7a8f658..cbfeef6339 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -9378,7 +9378,7 @@ pub 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, @@ -26511,7 +26511,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)}); } @@ -26536,7 +26536,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 b46c839687..1afa8d2aff 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -90078,7 +90078,7 @@ fn floatCompilerRtAbiName(float_bits: u32) u8 { fn floatCompilerRtAbiType(self: *CodeGen, 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 .u16; + self.target.os.tag.isDarwin()) return .u16; return ty; } diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 91bbea8b4a..41c817303c 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1301,7 +1301,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; @@ -2939,7 +2939,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)), @@ -3156,7 +3156,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 @@ -4830,7 +4830,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 }); @@ -6567,7 +6567,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. @@ -10024,7 +10024,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 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory); @@ -10181,7 +10181,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 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory) and dest_ptr_ty.isSlice(zcu)) { @@ -12696,7 +12696,7 @@ fn backendSupportsF16(target: std.Target) bool { .armeb, .thumb, .thumbeb, - => target.floatAbi() == .soft or std.Target.arm.featureSetHas(target.cpu.features, .fp_armv8), + => target.abi.float() == .soft or std.Target.arm.featureSetHas(target.cpu.features, .fp_armv8), .aarch64, .aarch64_be, => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8), @@ -12723,7 +12723,7 @@ fn backendSupportsF128(target: std.Target) bool { .armeb, .thumb, .thumbeb, - => target.floatAbi() == .soft or std.Target.arm.featureSetHas(target.cpu.features, .fp_armv8), + => target.abi.float() == .soft or std.Target.arm.featureSetHas(target.cpu.features, .fp_armv8), .aarch64, .aarch64_be, => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8), diff --git a/src/libtsan.zig b/src/libtsan.zig index fc1bfc4a36..f1bab36582 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 .watchos => if (target.abi == .simulator) "clang_rt.tsan_watchossim_dynamic" else "clang_rt.tsan_watchos_dynamic", 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,9 +52,9 @@ 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 unwind_tables: std.builtin.UnwindTables = if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .@"async"; + const link_libcpp = target.os.tag.isDarwin(); const config = Compilation.Config.resolve(.{ .output_mode = output_mode, @@ -276,14 +276,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 75b573b520..937501933f 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 ec59cce101..d805b331e3 100644 --- a/src/link.zig +++ b/src/link.zig @@ -2067,7 +2067,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, @@ -2104,7 +2104,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 abba4f2a6a..3a9ba1e149 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1881,7 +1881,7 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: try argv.append(try allocPrint(arena, "-MLLVM:-target-abi={s}", .{mabi})); } - try argv.append(try allocPrint(arena, "-MLLVM:-float-abi={s}", .{if (target.abi.floatAbi() == .hard) "hard" else "soft"})); + try argv.append(try allocPrint(arena, "-MLLVM:-float-abi={s}", .{if (target.abi.float() == .hard) "hard" else "soft"})); if (comp.config.lto != .none) { switch (optimize_mode) { diff --git a/src/link/Elf.zig b/src/link/Elf.zig index edd45f65ee..990dacf67f 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1709,7 +1709,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s try argv.appendSlice(&.{ "-mllvm", - try std.fmt.allocPrint(arena, "-float-abi={s}", .{if (target.abi.floatAbi() == .hard) "hard" else "soft"}), + try std.fmt.allocPrint(arena, "-float-abi={s}", .{if (target.abi.float() == .hard) "hard" else "soft"}), }); if (comp.config.lto != .none) { @@ -2053,7 +2053,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 a5d4379004..a5e3d2e070 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -3548,7 +3548,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 (builtin.target.isDarwin() and builtin.target.cpu.arch == .aarch64) { + if (builtin.target.os.tag.isDarwin() and builtin.target.cpu.arch == .aarch64) { try dir.copyFile(sub_path, dir, sub_path, .{}); } } diff --git a/src/main.zig b/src/main.zig index 773426dab9..eac8674b19 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3983,7 +3983,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; diff --git a/src/target.zig b/src/target.zig index 621cac3479..8ccec7f7a8 100644 --- a/src/target.zig +++ b/src/target.zig @@ -12,7 +12,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(), }; } @@ -40,12 +40,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()); @@ -245,7 +245,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 { diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig index a47f229296..92ed49629f 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.target.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.target.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/math.zig b/test/behavior/math.zig index 735d3cdbc1..b40cd50ebb 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -1639,7 +1639,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.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 try testNanEqNan(f16); try testNanEqNan(f32); @@ -1795,7 +1795,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.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 const S = struct { fn doTheTest(comptime F: type, x: F) void { @@ -1826,7 +1826,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.target.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/c_abi/main.zig b/test/c_abi/main.zig index f18fa4b3d5..4b42eb637b 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.target.cpu.arch.isWasm()) return; // waiting for #1481 expect(x == 12.34) catch @panic("test failure: zig_longdouble"); } @@ -1661,7 +1661,7 @@ test "bool simd vector" { } { - if (!builtin.target.isWasm()) c_vector_256_bool(.{ + if (!builtin.target.cpu.arch.isWasm()) c_vector_256_bool(.{ false, true, true, @@ -2179,7 +2179,7 @@ test "bool simd vector" { try expect(vec[255] == false); } { - if (!builtin.target.isWasm()) c_vector_512_bool(.{ + if (!builtin.target.cpu.arch.isWasm()) c_vector_512_bool(.{ true, true, true, @@ -5593,7 +5593,7 @@ test "f80 extra struct" { comptime { skip: { - if (builtin.target.isWasm()) break :skip; + if (builtin.target.cpu.arch.isWasm()) break :skip; _ = struct { export fn zig_f128(x: f128) f128 { diff --git a/test/standalone/stack_iterator/build.zig b/test/standalone/stack_iterator/build.zig index 4a1ef4b5b2..b76cb6cecd 100644 --- a/test/standalone/stack_iterator/build.zig +++ b/test/standalone/stack_iterator/build.zig @@ -24,7 +24,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()) .@"async" else null, + .unwind_tables = if (target.result.os.tag.isDarwin()) .@"async" else null, .omit_frame_pointer = false, }), }); @@ -94,7 +94,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()) .@"async" else null, + .unwind_tables = if (target.result.os.tag.isDarwin()) .@"async" 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 d8e2e883d5..6a168d4b5d 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.target.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) return; + if (builtin.target.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 69c463a0c1..c8ad8e120f 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.target.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) return; if (!std.debug.have_ucontext or !std.debug.have_getcontext) return;