authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-07 00:21:02+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-26 22:00:49+02:00
log27c85e5969f01853b2437d56ddc7a7eee9bf35d0
tree695064b9ecba2fd19c90b5ab8e81db49cdf1d6ce
parentf02d25d883cb5e9d9487e25ed9241c6c13bc1f88
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

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().

2 files changed, 3 insertions(+), 26 deletions(-)

lib/std/Target.zig-24
...@@ -1939,30 +1939,6 @@ pub inline fn floatAbi(target: Target) FloatAbi {...@@ -1939,30 +1939,6 @@ pub inline fn floatAbi(target: Target) FloatAbi {
1939 return target.abi.floatAbi();1939 return target.abi.floatAbi();
1940}1940}
19411941
1942pub inline fn hasDynamicLinker(target: Target) bool {
1943 if (target.cpu.arch.isWasm()) {
1944 return false;
1945 }
1946 switch (target.os.tag) {
1947 .freestanding,
1948 .ios,
1949 .tvos,
1950 .watchos,
1951 .macos,
1952 .visionos,
1953 .uefi,
1954 .windows,
1955 .emscripten,
1956 .opencl,
1957 .opengl,
1958 .vulkan,
1959 .plan9,
1960 .other,
1961 => return false,
1962 else => return true,
1963 }
1964}
1965
1966pub const DynamicLinker = struct {1942pub const DynamicLinker = struct {
1967 /// Contains the memory used to store the dynamic linker path. This field1943 /// Contains the memory used to store the dynamic linker path. This field
1968 /// should not be used directly. See `get` and `set`. This field exists so1944 /// should not be used directly. See `get` and `set`. This field exists so
lib/std/zig/system.zig+3-2
...@@ -963,14 +963,15 @@ fn detectAbiAndDynamicLinker(...@@ -963,14 +963,15 @@ fn detectAbiAndDynamicLinker(
963 os: Target.Os,963 os: Target.Os,
964 query: Target.Query,964 query: Target.Query,
965) DetectError!Target {965) DetectError!Target {
966 const native_target_has_ld = comptime builtin.target.hasDynamicLinker();966 const native_target_has_ld = comptime Target.DynamicLinker.kind(builtin.os.tag) != .none;
967 const is_linux = builtin.target.os.tag == .linux;967 const is_linux = builtin.target.os.tag == .linux;
968 const is_solarish = builtin.target.os.tag.isSolarish();968 const is_solarish = builtin.target.os.tag.isSolarish();
969 const is_darwin = builtin.target.os.tag.isDarwin();
969 const have_all_info = query.dynamic_linker.get() != null and970 const have_all_info = query.dynamic_linker.get() != null and
970 query.abi != null and (!is_linux or query.abi.?.isGnu());971 query.abi != null and (!is_linux or query.abi.?.isGnu());
971 const os_is_non_native = query.os_tag != null;972 const os_is_non_native = query.os_tag != null;
972 // The Solaris/illumos environment is always the same.973 // The Solaris/illumos environment is always the same.
973 if (!native_target_has_ld or have_all_info or os_is_non_native or is_solarish) {974 if (!native_target_has_ld or have_all_info or os_is_non_native or is_solarish or is_darwin) {
974 return defaultAbiAndDynamicLinker(cpu, os, query);975 return defaultAbiAndDynamicLinker(cpu, os, query);
975 }976 }
976 if (query.abi) |abi| {977 if (query.abi) |abi| {