authorgravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2026-05-02 01:04:58+01:00
committergravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2026-05-02 01:28:30+01:00
log0f5de17d6dcf58c22d4070e45758e995bb9f1633
tree965c208920de75e6088e97ce628b49fb043825b0
parent89b0c634c129aa048b7677c555ea1302a5d15d46

std.zig.LibCInstallation: Add support for serenity

Largely mirrors Haiku, Serenity provides crt0 and GCC the rest (though only crtbegin/crtend are used as per serenity's toolchain patches[1]): ``` $ find Build/aarch64/Root -iname 'crt*.o' Build/aarch64/Root/usr/local/lib/gcc/aarch64-serenity/15.2.0/crtbeginS.o Build/aarch64/Root/usr/local/lib/gcc/aarch64-serenity/15.2.0/crtend.o Build/aarch64/Root/usr/local/lib/gcc/aarch64-serenity/15.2.0/crtbegin.o Build/aarch64/Root/usr/local/lib/gcc/aarch64-serenity/15.2.0/crtfastmath.o Build/aarch64/Root/usr/local/lib/gcc/aarch64-serenity/15.2.0/crti.o Build/aarch64/Root/usr/local/lib/gcc/aarch64-serenity/15.2.0/crtn.o Build/aarch64/Root/usr/local/lib/gcc/aarch64-serenity/15.2.0/crtendS.o Build/aarch64/Root/usr/lib/crt0.o ``` Serenity has a GCC and LLVM toolchain that work equally well, support for the latter may be added in the future. [1]: https://github.com/SerenityOS/serenity/blob/727c4a3d1a6748221b383207dac354e564b6150d/Toolchain/Patches/gcc/0001-Add-a-gcc-driver-for-SerenityOS.patch#L120-L127

1 files changed, 26 insertions(+), 5 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,