authorgravatar for mail@linusgroh.delinus <mail@linusgroh.de> 2026-05-03 21:04:54+02:00
committergravatar for mail@linusgroh.delinus <mail@linusgroh.de> 2026-05-03 21:04:54+02:00
loga794287573a84f04f675efeb3278ebc00755a57b
tree694bb52e1de27df978be2d2611aa3f273cc14115
parent02097dff7049cecb16e301d37cd270159ef0f371
parent0f5de17d6dcf58c22d4070e45758e995bb9f1633

Merge pull request 'std.zig.LibCInstallation: Add support for serenity' (#32172) from linus/zig:more-serenity into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32172 Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>

2 files changed, 27 insertions(+), 6 deletions(-)

lib/std/zig/LibCInstallation.zig+26-5
......@@ -5,6 +5,7 @@ const builtin = @import("builtin");
55const is_darwin = builtin.target.os.tag.isDarwin();
66const is_windows = builtin.target.os.tag == .windows;
77const is_haiku = builtin.target.os.tag == .haiku;
8const is_serenity = builtin.target.os.tag == .serenity;
89
910const std = @import("std");
1011const Io = std.Io;
......@@ -112,7 +113,7 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const
112113 return error.ParseError;
113114 }
114115
115 if (self.gcc_dir == null and os_tag == .haiku) {
116 if (self.gcc_dir == null and (os_tag == .haiku or os_tag == .serenity)) {
116117 log.err("gcc_dir may not be empty for {s}", .{@tagName(os_tag)});
117118 return error.ParseError;
118119 }
......@@ -207,8 +208,12 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
207208 try self.findNativeCrtDirWindows(gpa, io, args.target, sdk);
208209 } else if (is_haiku) {
209210 try self.findNativeIncludeDirPosix(gpa, io, args);
210 try self.findNativeGccDirHaiku(gpa, io, args);
211 try self.findNativeGccDirPosix(gpa, io, args);
211212 self.crt_dir = try gpa.dupe(u8, "/system/develop/lib");
213 } else if (is_serenity) {
214 try self.findNativeIncludeDirPosix(gpa, io, args);
215 try self.findNativeGccDirPosix(gpa, io, args);
216 self.crt_dir = try gpa.dupe(u8, "/usr/lib");
212217 } else if (builtin.target.os.tag == .illumos) {
213218 // There is only one libc, and its headers/libraries are always in the same spot.
214219 self.include_dir = try gpa.dupe(u8, "/usr/include");
......@@ -314,7 +319,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar
314319 const include_dir_example_file = if (is_haiku) "posix/stdlib.h" else "stdlib.h";
315320 const sys_include_dir_example_file = if (is_windows)
316321 "sys\\types.h"
317 else if (is_haiku)
322 else if (is_haiku or is_serenity)
318323 "errno.h"
319324 else
320325 "sys/errno.h";
......@@ -457,7 +462,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args:
457462 });
458463}
459464
460fn findNativeGccDirHaiku(self: *LibCInstallation, gpa: Allocator, io: Io, args: FindNativeOptions) FindError!void {
465fn findNativeGccDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args: FindNativeOptions) FindError!void {
461466 self.gcc_dir = try ccPrintFileName(gpa, io, .{
462467 .environ_map = args.environ_map,
463468 .search_basename = "crtbeginS.o",
......@@ -949,6 +954,22 @@ pub const CrtBasenames = struct {
949954 },
950955 .static_exe, .static_pie => .{},
951956 },
957 .serenity => switch (mode) {
958 .dynamic_lib => .{
959 .crtbegin = "crtbeginS.o",
960 .crtend = "crtendS.o",
961 },
962 .dynamic_exe, .static_exe => .{
963 .crt0 = "crt0.o",
964 .crtbegin = "crtbegin.o",
965 .crtend = "crtend.o",
966 },
967 .dynamic_pie, .static_pie => .{
968 .crt0 = "crt0.o",
969 .crtbegin = "crtbeginS.o",
970 .crtend = "crtendS.o",
971 },
972 },
952973 else => .{},
953974 };
954975 }
......@@ -993,7 +1014,7 @@ pub fn resolveCrtPaths(
9931014 .crtn = if (crt_basenames.crtn) |basename| try crt_dir_path.join(arena, basename) else null,
9941015 };
9951016 },
996 .haiku => {
1017 .haiku, .serenity => {
9971018 const gcc_dir_path: Path = .{
9981019 .root_dir = std.Build.Cache.Directory.cwd(),
9991020 .sub_path = lci.gcc_dir orelse return error.LibCInstallationMissingCrtDir,
src/target.zig+1-1
......@@ -85,7 +85,7 @@ pub fn supports_fpic(target: *const std.Target) bool {
8585
8686pub fn defaultPie(target: *const std.Target) bool {
8787 return switch (target.os.tag) {
88 .openbsd => true,
88 .openbsd, .serenity => true,
8989 else => target.os.tag.isDarwin(),
9090 };
9191}