authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-13 01:21:32+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-17 04:41:27+02:00
log4371e695efafb8ed2d727cda0837b602d142193a
treebc2eddc72df952a76eef362592b2e07f63a54f0a
parent6028db7f29e2e29ba08a55d83d92cdeb2787a01f
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

process_headers: Add NetBSD libc support.


1 files changed, 53 insertions(+), 12 deletions(-)

tools/process_headers.zig+53-12
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1//! To get started, run this tool with no args and read the help message.1//! To get started, run this tool with no args and read the help message.
2//!2//!
3//! The build systems of glibc, musl, and FreeBSD require specifying a single target3//! The build systems of glibc, musl, FreeBSD, and NetBSD require specifying a single target
4//! architecture. Meanwhile, Zig supports out-of-the-box cross compilation for4//! architecture. Meanwhile, Zig supports out-of-the-box cross compilation for
5//! every target. So the process to create libc headers that Zig ships is to use5//! every target. So the process to create libc headers that Zig ships is to use
6//! this tool.6//! this tool.
7//!7//!
8//! First, use the glibc, musl, and FreeBSD build systems to create installations of all the8//! First, use the glibc, musl, FreeBSD, and NetBSD build systems to create installations of all the
9//! targets in the `glibc_targets`, `musl_targets`, and `freebsd_targets` variables.9//! targets in the `glibc_targets`, `musl_targets`, `freebsd_targets`, and `netbsd_targets`
10//! Next, run this tool to create a new directory which puts .h files into10//! variables. Next, run this tool to create a new directory which puts .h files into
11//! <arch> subdirectories, with `generic` being files that apply to all architectures.11//! <arch> subdirectories, with `generic` being files that apply to all architectures.
12//! You'll then have to manually update Zig source repo with these new files.12//! You'll then have to manually update Zig source repo with these new files.
1313
...@@ -87,6 +87,21 @@ const freebsd_targets = [_]LibCTarget{...@@ -87,6 +87,21 @@ const freebsd_targets = [_]LibCTarget{
87 .{ .arch = .x86_64, .abi = .none },87 .{ .arch = .x86_64, .abi = .none },
88};88};
8989
90const netbsd_targets = [_]LibCTarget{
91 .{ .arch = .arm, .abi = .eabi },
92 .{ .arch = .arm, .abi = .eabihf },
93 .{ .arch = .aarch64, .abi = .none },
94 .{ .arch = .m68k, .abi = .none },
95 .{ .arch = .mips, .abi = .eabi },
96 .{ .arch = .mips, .abi = .eabihf },
97 .{ .arch = .powerpc, .abi = .eabi },
98 .{ .arch = .powerpc, .abi = .eabihf },
99 .{ .arch = .sparc, .abi = .none },
100 .{ .arch = .sparc64, .abi = .none },
101 .{ .arch = .x86, .abi = .none },
102 .{ .arch = .x86_64, .abi = .none },
103};
104
90const DestTarget = struct {105const DestTarget = struct {
91 arch: Arch,106 arch: Arch,
92 os: OsTag,107 os: OsTag,
...@@ -130,6 +145,7 @@ const LibCVendor = enum {...@@ -130,6 +145,7 @@ const LibCVendor = enum {
130 musl,145 musl,
131 glibc,146 glibc,
132 freebsd,147 freebsd,
148 netbsd,
133};149};
134150
135pub fn main() !void {151pub fn main() !void {
...@@ -177,6 +193,7 @@ pub fn main() !void {...@@ -177,6 +193,7 @@ pub fn main() !void {
177 .glibc => &glibc_targets,193 .glibc => &glibc_targets,
178 .musl => &musl_targets,194 .musl => &musl_targets,
179 .freebsd => &freebsd_targets,195 .freebsd => &freebsd_targets,
196 .netbsd => &netbsd_targets,
180 };197 };
181198
182 var path_table = PathTable.init(allocator);199 var path_table = PathTable.init(allocator);
...@@ -192,25 +209,49 @@ pub fn main() !void {...@@ -192,25 +209,49 @@ pub fn main() !void {
192 .musl => std.zig.target.muslArchName(libc_target.arch, libc_target.abi),209 .musl => std.zig.target.muslArchName(libc_target.arch, libc_target.abi),
193 .freebsd => switch (libc_target.arch) {210 .freebsd => switch (libc_target.arch) {
194 .arm => "armv7",211 .arm => "armv7",
195 .aarch64 => "aarch64",
196 .powerpc => "powerpc",
197 .powerpc64 => "powerpc64",
198 .powerpc64le => "powerpc64le",
199 .riscv64 => "riscv64",
200 .x86 => "i386",212 .x86 => "i386",
201 .x86_64 => "amd64",213 .x86_64 => "amd64",
214
215 .aarch64,
216 .powerpc,
217 .powerpc64,
218 .riscv64,
219 => |a| @tagName(a),
220
221 else => unreachable,
222 },
223 .netbsd => switch (libc_target.arch) {
224 .arm => if (libc_target.abi == .eabihf) "evbarmv7hf" else "evbarmv7",
225 .aarch64 => "evbarm64",
226 .m68k => "mac68k",
227 .mips => if (libc_target.abi == .eabihf) "evbmips" else "evbmipssf",
228 .powerpc => if (libc_target.abi == .eabihf) "evbppc" else "evbppcsf",
229 .x86 => "i386",
230 .x86_64 => "amd64",
231
232 .sparc,
233 .sparc64,
234 => |a| @tagName(a),
235
202 else => unreachable,236 else => unreachable,
203 },237 },
204 };238 };
205 const dest_target = DestTarget{239 const dest_target = DestTarget{
206 .arch = libc_target.arch,240 .arch = libc_target.arch,
207 .os = if (vendor == .freebsd) .freebsd else .linux,241 .os = switch (vendor) {
242 .musl, .glibc => .linux,
243 .freebsd => .freebsd,
244 .netbsd => .netbsd,
245 },
208 .abi = libc_target.abi,246 .abi = libc_target.abi,
209 };247 };
210248
211 search: for (search_paths.items) |search_path| {249 search: for (search_paths.items) |search_path| {
212 const sub_path = switch (vendor) {250 const sub_path = switch (vendor) {
213 .glibc, .freebsd => &[_][]const u8{ search_path, libc_dir, "usr", "include" },251 .glibc,
252 .freebsd,
253 .netbsd,
254 => &[_][]const u8{ search_path, libc_dir, "usr", "include" },
214 .musl => &[_][]const u8{ search_path, libc_dir, "usr", "local", "musl", "include" },255 .musl => &[_][]const u8{ search_path, libc_dir, "usr", "local", "musl", "include" },
215 };256 };
216 const target_include_dir = try std.fs.path.join(allocator, sub_path);257 const target_include_dir = try std.fs.path.join(allocator, sub_path);
...@@ -339,6 +380,6 @@ fn usageAndExit(arg0: []const u8) noreturn {...@@ -339,6 +380,6 @@ fn usageAndExit(arg0: []const u8) noreturn {
339 std.debug.print("--search-path can be used any number of times.\n", .{});380 std.debug.print("--search-path can be used any number of times.\n", .{});
340 std.debug.print(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{});381 std.debug.print(" subdirectories of search paths look like, e.g. x86_64-linux-gnu\n", .{});
341 std.debug.print("--out is a dir that will be created, and populated with the results\n", .{});382 std.debug.print("--out is a dir that will be created, and populated with the results\n", .{});
342 std.debug.print("--abi is either glibc, musl, or freebsd\n", .{});383 std.debug.print("--abi is either glibc, musl, freebsd, or netbsd\n", .{});
343 std.process.exit(1);384 std.process.exit(1);
344}385}