From 27c85e5969f01853b2437d56ddc7a7eee9bf35d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 7 Oct 2024 00:21:02 +0200 Subject: [PATCH] std.Target: Remove hasDynamicLinker() in favor of DynamicLinker.kind(). hasDynamicLinker() was just kind of lying in the case of Darwin platforms for the benefit of std.zig.system.detectAbiAndDynamicLinker(). A better name would have been hasElfDynamicLinker() or something. It also got the answer wrong for a bunch of platforms that don't actually use ELF. Anyway, this was clearly the wrong layer to do this at, so remove this function and instead use DynamicLinker.kind() + an isDarwin() check in detectAbiAndDynamicLinker(). --- lib/std/Target.zig | 24 ------------------------ lib/std/zig/system.zig | 5 +++-- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/lib/std/Target.zig b/lib/std/Target.zig index 32b8525c08..1d037d864e 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -1939,30 +1939,6 @@ pub inline fn floatAbi(target: Target) FloatAbi { return target.abi.floatAbi(); } -pub inline fn hasDynamicLinker(target: Target) bool { - if (target.cpu.arch.isWasm()) { - return false; - } - switch (target.os.tag) { - .freestanding, - .ios, - .tvos, - .watchos, - .macos, - .visionos, - .uefi, - .windows, - .emscripten, - .opencl, - .opengl, - .vulkan, - .plan9, - .other, - => return false, - else => return true, - } -} - 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 diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index d1967877b3..a33200b50c 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -963,14 +963,15 @@ fn detectAbiAndDynamicLinker( os: Target.Os, query: Target.Query, ) DetectError!Target { - const native_target_has_ld = comptime builtin.target.hasDynamicLinker(); + 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 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; // The Solaris/illumos environment is always the same. - if (!native_target_has_ld or have_all_info or os_is_non_native or is_solarish) { + if (!native_target_has_ld or have_all_info or os_is_non_native or is_solarish or is_darwin) { return defaultAbiAndDynamicLinker(cpu, os, query); } if (query.abi) |abi| {