diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2025-05-12 01:19:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-12 01:19:23 +0200 |
| commit | 833d4c9ce4fb2588607a7c94d7919ad4e2edb641 (patch) | |
| tree | 3c5f1d75af1322d9a1eb5716debd9abe69b19484 /src/Compilation/Config.zig | |
| parent | c3906718b343c20e4021e68e68a9c163a98c2741 (diff) | |
| parent | f3e851dbd08c5467326ce983c4ae8ae2a1dc369c (diff) | |
| download | zig-833d4c9ce4fb2588607a7c94d7919ad4e2edb641.tar.gz zig-833d4c9ce4fb2588607a7c94d7919ad4e2edb641.zip | |
Merge pull request #23835 from alexrp/freebsd-libc
Support dynamically-linked FreeBSD libc when cross-compiling
Diffstat (limited to 'src/Compilation/Config.zig')
| -rw-r--r-- | src/Compilation/Config.zig | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index b46837679a..493c63f34f 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -335,6 +335,13 @@ pub fn resolve(options: Options) ResolveError!Config { break :b true; } if (options.link_libc) |x| break :b x; + switch (target.os.tag) { + // These targets don't require libc, but we don't yet have a syscall layer for them, + // so we default to linking libc for now. + .freebsd, + => break :b true, + else => {}, + } if (options.ensure_libc_on_non_freestanding and target.os.tag != .freestanding) break :b true; @@ -353,7 +360,9 @@ pub fn resolve(options: Options) ResolveError!Config { break :b .static; } if (explicitly_exe_or_dyn_lib and link_libc and - (target_util.osRequiresLibC(target) or (target.isGnuLibC() and !options.resolved_target.is_native_abi))) + (target_util.osRequiresLibC(target) or + // For these libcs, Zig can only provide dynamic libc when cross-compiling. + ((target.isGnuLibC() or target.isFreeBSDLibC()) and !options.resolved_target.is_native_abi))) { if (options.link_mode == .static) return error.LibCRequiresDynamicLinking; break :b .dynamic; @@ -368,12 +377,18 @@ pub fn resolve(options: Options) ResolveError!Config { if (options.link_mode) |link_mode| break :b link_mode; - if (explicitly_exe_or_dyn_lib and link_libc and options.resolved_target.is_native_abi and - (target.isGnuLibC() or target.isMuslLibC())) - { - // If targeting the system's native ABI and the system's libc is - // glibc or musl, link dynamically by default. - break :b .dynamic; + if (explicitly_exe_or_dyn_lib and link_libc) { + // When using the native glibc/musl ABI, dynamic linking is usually what people want. + if (options.resolved_target.is_native_abi and (target.isGnuLibC() or target.isMuslLibC())) { + break :b .dynamic; + } + + // When targeting systems where the kernel and libc are developed alongside each other, + // dynamic linking is the better default; static libc may contain code that requires + // the very latest kernel version. + if (target.isFreeBSDLibC()) { + break :b .dynamic; + } } // Static is generally a better default. Fight me. |
