authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-08 21:12:49+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-11 11:15:09+02:00
loge8992af7f0516c3c6dff5ada865c097788841f7c
tree284624947c0b078aeacb5b221f17cc7adcbe8df0
parent2116f2e3b2da0a01e119276e46fd3cbf4b35d548
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Compilation.Config: Default to dynamic linking with FreeBSD libc.


1 files changed, 15 insertions(+), 7 deletions(-)

src/Compilation/Config.zig+15-7
...@@ -353,7 +353,9 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -353,7 +353,9 @@ pub fn resolve(options: Options) ResolveError!Config {
353 break :b .static;353 break :b .static;
354 }354 }
355 if (explicitly_exe_or_dyn_lib and link_libc and355 if (explicitly_exe_or_dyn_lib and link_libc and
356 (target_util.osRequiresLibC(target) or (target.isGnuLibC() and !options.resolved_target.is_native_abi)))356 (target_util.osRequiresLibC(target) or
357 // For these libcs, Zig can only provide dynamic libc when cross-compiling.
358 ((target.isGnuLibC() or target.isFreeBSDLibC()) and !options.resolved_target.is_native_abi)))
357 {359 {
358 if (options.link_mode == .static) return error.LibCRequiresDynamicLinking;360 if (options.link_mode == .static) return error.LibCRequiresDynamicLinking;
359 break :b .dynamic;361 break :b .dynamic;
...@@ -368,12 +370,18 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -368,12 +370,18 @@ pub fn resolve(options: Options) ResolveError!Config {
368370
369 if (options.link_mode) |link_mode| break :b link_mode;371 if (options.link_mode) |link_mode| break :b link_mode;
370372
371 if (explicitly_exe_or_dyn_lib and link_libc and options.resolved_target.is_native_abi and373 if (explicitly_exe_or_dyn_lib and link_libc) {
372 (target.isGnuLibC() or target.isMuslLibC()))374 // When using the native glibc/musl ABI, dynamic linking is usually what people want.
373 {375 if (options.resolved_target.is_native_abi and (target.isGnuLibC() or target.isMuslLibC())) {
374 // If targeting the system's native ABI and the system's libc is376 break :b .dynamic;
375 // glibc or musl, link dynamically by default.377 }
376 break :b .dynamic;378
379 // When targeting systems where the kernel and libc are developed alongside each other,
380 // dynamic linking is the better default; static libc may contain code that requires
381 // the very latest kernel version.
382 if (target.isFreeBSDLibC()) {
383 break :b .dynamic;
384 }
377 }385 }
378386
379 // Static is generally a better default. Fight me.387 // Static is generally a better default. Fight me.