| ... | @@ -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 and | 355 | 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 { |
| 368 | | 370 | |
| 369 | if (options.link_mode) |link_mode| break :b link_mode; | 371 | if (options.link_mode) |link_mode| break :b link_mode; |
| 370 | | 372 | |
| 371 | if (explicitly_exe_or_dyn_lib and link_libc and options.resolved_target.is_native_abi and | 373 | 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 is | 376 | 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 | } |
| 378 | | 386 | |
| 379 | // Static is generally a better default. Fight me. | 387 | // Static is generally a better default. Fight me. |