Skip to content

Commit e8992af

Browse files
committed
Compilation.Config: Default to dynamic linking with FreeBSD libc.
1 parent 2116f2e commit e8992af

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/Compilation/Config.zig

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ pub fn resolve(options: Options) ResolveError!Config {
353353
break :b .static;
354354
}
355355
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)))
357359
{
358360
if (options.link_mode == .static) return error.LibCRequiresDynamicLinking;
359361
break :b .dynamic;
@@ -368,12 +370,18 @@ pub fn resolve(options: Options) ResolveError!Config {
368370

369371
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 and
372-
(target.isGnuLibC() or target.isMuslLibC()))
373-
{
374-
// If targeting the system's native ABI and the system's libc is
375-
// glibc or musl, link dynamically by default.
376-
break :b .dynamic;
373+
if (explicitly_exe_or_dyn_lib and link_libc) {
374+
// When using the native glibc/musl ABI, dynamic linking is usually what people want.
375+
if (options.resolved_target.is_native_abi and (target.isGnuLibC() or target.isMuslLibC())) {
376+
break :b .dynamic;
377+
}
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+
}
377385
}
378386

379387
// Static is generally a better default. Fight me.

0 commit comments

Comments
 (0)