From 481b7bf3f095488a89e20d88ada092529bc6e6f8 Mon Sep 17 00:00:00 2001 From: Alex Rønne Petersen Date: Fri, 24 Jan 2025 03:45:38 +0100 Subject: 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. --- src/Compilation.zig | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/Compilation.zig') 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"); -- cgit v1.2.3