authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-26 01:05:12+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-26 05:50:51+01:00
logcef16b5130eae56a77262df532aae5a458736670
tree014e21edc6f9aaea20e30c5c925c238c3a2effd7
parente4a977f9e41165168fed7628134c701e9060a741
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Target: don't claim that OpenBSD requires libc

https://codeberg.org/ziglang/zig/issues/30982

4 files changed, 6 insertions(+), 5 deletions(-)

lib/std/Target.zig+1-1
...@@ -2180,7 +2180,6 @@ pub fn requiresLibC(target: *const Target) bool {...@@ -2180,7 +2180,6 @@ pub fn requiresLibC(target: *const Target) bool {
2180 .watchos,2180 .watchos,
2181 .visionos,2181 .visionos,
2182 .dragonfly,2182 .dragonfly,
2183 .openbsd,
2184 .haiku,2183 .haiku,
2185 .serenity,2184 .serenity,
2186 => true,2185 => true,
...@@ -2194,6 +2193,7 @@ pub fn requiresLibC(target: *const Target) bool {...@@ -2194,6 +2193,7 @@ pub fn requiresLibC(target: *const Target) bool {
2194 .windows,2193 .windows,
2195 .freebsd,2194 .freebsd,
2196 .netbsd,2195 .netbsd,
2196 .openbsd,
2197 .freestanding,2197 .freestanding,
2198 .fuchsia,2198 .fuchsia,
2199 .managarm,2199 .managarm,
src/Compilation/Config.zig+3-2
...@@ -239,6 +239,7 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -239,6 +239,7 @@ pub fn resolve(options: Options) ResolveError!Config {
239 // so we default to linking libc for now.239 // so we default to linking libc for now.
240 .freebsd,240 .freebsd,
241 .netbsd,241 .netbsd,
242 .openbsd,
242 => break :b true,243 => break :b true,
243 else => {},244 else => {},
244 }245 }
...@@ -266,7 +267,7 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -266,7 +267,7 @@ pub fn resolve(options: Options) ResolveError!Config {
266 if (explicitly_exe_or_dyn_lib and link_libc and267 if (explicitly_exe_or_dyn_lib and link_libc and
267 (target.requiresLibC() or268 (target.requiresLibC() or
268 // For these libcs, Zig can only provide dynamic libc when cross-compiling.269 // For these libcs, Zig can only provide dynamic libc when cross-compiling.
269 ((target.isGnuLibC() or target.isFreeBSDLibC() or target.isNetBSDLibC()) and270 ((target.isGnuLibC() or target.isFreeBSDLibC() or target.isNetBSDLibC() or target.isOpenBSDLibC()) and
270 !options.resolved_target.is_native_abi)))271 !options.resolved_target.is_native_abi)))
271 {272 {
272 if (options.link_mode == .static) return error.LibCRequiresDynamicLinking;273 if (options.link_mode == .static) return error.LibCRequiresDynamicLinking;
...@@ -286,7 +287,7 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -286,7 +287,7 @@ pub fn resolve(options: Options) ResolveError!Config {
286 // When targeting systems where the kernel and libc are developed alongside each other,287 // When targeting systems where the kernel and libc are developed alongside each other,
287 // dynamic linking is the better default; static libc may contain code that requires288 // dynamic linking is the better default; static libc may contain code that requires
288 // the very latest kernel version.289 // the very latest kernel version.
289 if (target.isFreeBSDLibC() or target.isNetBSDLibC()) {290 if (target.isFreeBSDLibC() or target.isNetBSDLibC() or target.isOpenBSDLibC()) {
290 break :b .dynamic;291 break :b .dynamic;
291 }292 }
292 }293 }
test/src/StackTrace.zig+1-1
...@@ -59,7 +59,7 @@ fn addCaseTarget(...@@ -59,7 +59,7 @@ fn addCaseTarget(
59 else => true,59 else => true,
60 };60 };
61 const both_libc = switch (target.result.os.tag) {61 const both_libc = switch (target.result.os.tag) {
62 .freebsd, .netbsd => false,62 .freebsd, .netbsd, .openbsd => false,
63 else => !target.result.requiresLibC(),63 else => !target.result.requiresLibC(),
64 };64 };
6565
test/tests.zig+1-1
...@@ -2379,7 +2379,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {...@@ -2379,7 +2379,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
2379 // These targets don't strictly require libc, but we don't yet have a2379 // These targets don't strictly require libc, but we don't yet have a
2380 // syscall layer for them, so the compiler links libc by default. They2380 // syscall layer for them, so the compiler links libc by default. They
2381 // therefore get the same treatment here.2381 // therefore get the same treatment here.
2382 if (test_target.link_libc == null and (target.os.tag == .freebsd or target.os.tag == .netbsd)) continue;2382 if (test_target.link_libc == null and (target.os.tag == .freebsd or target.os.tag == .netbsd or target.os.tag == .openbsd)) continue;
23832383
2384 if (!options.test_extra_targets and test_target.extra_target) continue;2384 if (!options.test_extra_targets and test_target.extra_target) continue;
23852385