From f02d25d883cb5e9d9487e25ed9241c6c13bc1f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 7 Oct 2024 00:16:27 +0200 Subject: [PATCH] std.Target: Implement DynamicLinker.kind() function. This helps callers of DynamicLinker.standard() make informed decisions about the usefulness of the returned value. --- lib/std/Target.zig | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/lib/std/Target.zig b/lib/std/Target.zig index def304bc6c..32b8525c08 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -2009,6 +2009,75 @@ pub const DynamicLinker = struct { return std.mem.eql(u8, lhs.buffer[0..lhs.len], rhs.buffer[0..rhs.len]); } + pub const Kind = enum { + /// No dynamic linker. + none, + /// Dynamic linker path is determined by the arch/OS components. + arch_os, + /// Dynamic linker path is determined by the arch/OS/ABI components. + arch_os_abi, + }; + + pub fn kind(os: Os.Tag) Kind { + return switch (os) { + .fuchsia, + + .haiku, + .serenity, + + .dragonfly, + .freebsd, + .netbsd, + .openbsd, + + .bridgeos, + .driverkit, + .ios, + .macos, + .tvos, + .visionos, + .watchos, + + .illumos, + .solaris, + => .arch_os, + .hurd, + .linux, + => .arch_os_abi, + .freestanding, + .other, + + .contiki, + .elfiamcu, + .hermit, + + .aix, + .plan9, + .rtems, + .zos, + + .uefi, + .windows, + + .emscripten, + .wasi, + + .amdhsa, + .amdpal, + .cuda, + .mesa3d, + .nvcl, + .opencl, + .opengl, + .vulkan, + + .ps3, + .ps4, + .ps5, + => .none, + }; + } + pub fn standard(cpu: Cpu, os: Os, abi: Abi) DynamicLinker { return switch (os.tag) { .fuchsia => init("ld.so.1"), // Fuchsia is unusual in that `DT_INTERP` is just a basename.