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");...@@ -5,6 +5,7 @@ const builtin = @import("builtin");
5const is_darwin = builtin.target.os.tag.isDarwin();5const is_darwin = builtin.target.os.tag.isDarwin();
6const is_windows = builtin.target.os.tag == .windows;6const is_windows = builtin.target.os.tag == .windows;
7const is_haiku = builtin.target.os.tag == .haiku;7const is_haiku = builtin.target.os.tag == .haiku;
8const is_serenity = builtin.target.os.tag == .serenity;
89
9const std = @import("std");10const std = @import("std");
10const Io = std.Io;11const Io = std.Io;
...@@ -112,7 +113,7 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const...@@ -112,7 +113,7 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const
112 return error.ParseError;113 return error.ParseError;
113 }114 }
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)) {
116 log.err("gcc_dir may not be empty for {s}", .{@tagName(os_tag)});117 log.err("gcc_dir may not be empty for {s}", .{@tagName(os_tag)});
117 return error.ParseError;118 return error.ParseError;
118 }119 }
...@@ -207,8 +208,12 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib...@@ -207,8 +208,12 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
207 try self.findNativeCrtDirWindows(gpa, io, args.target, sdk);208 try self.findNativeCrtDirWindows(gpa, io, args.target, sdk);
208 } else if (is_haiku) {209 } else if (is_haiku) {
209 try self.findNativeIncludeDirPosix(gpa, io, args);210 try self.findNativeIncludeDirPosix(gpa, io, args);
210 try self.findNativeGccDirHaiku(gpa, io, args);211 try self.findNativeGccDirPosix(gpa, io, args);
211 self.crt_dir = try gpa.dupe(u8, "/system/develop/lib");212 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");
212 } else if (builtin.target.os.tag == .illumos) {217 } else if (builtin.target.os.tag == .illumos) {
213 // There is only one libc, and its headers/libraries are always in the same spot.218 // There is only one libc, and its headers/libraries are always in the same spot.
214 self.include_dir = try gpa.dupe(u8, "/usr/include");219 self.include_dir = try gpa.dupe(u8, "/usr/include");
...@@ -314,7 +319,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar...@@ -314,7 +319,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, ar
314 const include_dir_example_file = if (is_haiku) "posix/stdlib.h" else "stdlib.h";319 const include_dir_example_file = if (is_haiku) "posix/stdlib.h" else "stdlib.h";
315 const sys_include_dir_example_file = if (is_windows)320 const sys_include_dir_example_file = if (is_windows)
316 "sys\\types.h"321 "sys\\types.h"
317 else if (is_haiku)322 else if (is_haiku or is_serenity)
318 "errno.h"323 "errno.h"
319 else324 else
320 "sys/errno.h";325 "sys/errno.h";
...@@ -457,7 +462,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args:...@@ -457,7 +462,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args:
457 });462 });
458}463}
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 {
461 self.gcc_dir = try ccPrintFileName(gpa, io, .{466 self.gcc_dir = try ccPrintFileName(gpa, io, .{
462 .environ_map = args.environ_map,467 .environ_map = args.environ_map,
463 .search_basename = "crtbeginS.o",468 .search_basename = "crtbeginS.o",
...@@ -949,6 +954,22 @@ pub const CrtBasenames = struct {...@@ -949,6 +954,22 @@ pub const CrtBasenames = struct {
949 },954 },
950 .static_exe, .static_pie => .{},955 .static_exe, .static_pie => .{},
951 },956 },
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 },
952 else => .{},973 else => .{},
953 };974 };
954 }975 }
...@@ -993,7 +1014,7 @@ pub fn resolveCrtPaths(...@@ -993,7 +1014,7 @@ pub fn resolveCrtPaths(
993 .crtn = if (crt_basenames.crtn) |basename| try crt_dir_path.join(arena, basename) else null,1014 .crtn = if (crt_basenames.crtn) |basename| try crt_dir_path.join(arena, basename) else null,
994 };1015 };
995 },1016 },
996 .haiku => {1017 .haiku, .serenity => {
997 const gcc_dir_path: Path = .{1018 const gcc_dir_path: Path = .{
998 .root_dir = std.Build.Cache.Directory.cwd(),1019 .root_dir = std.Build.Cache.Directory.cwd(),
999 .sub_path = lci.gcc_dir orelse return error.LibCInstallationMissingCrtDir,1020 .sub_path = lci.gcc_dir orelse return error.LibCInstallationMissingCrtDir,