authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-01 01:15:36+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-05 16:50:44+01:00
logd0ad76c03c11b6b033d13b28dac913ec11cb9c3a
tree6fed0fe593ac42a1583673b5c810c6dd2befb85d
parent4d3a847cd1aaed8587732c1da94e941d6015b050
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

update_openbsd_libc: add tool for updating openbsd libc startup code


2 files changed, 62 insertions(+), 0 deletions(-)

test/standalone/build.zig+1
......@@ -50,6 +50,7 @@ pub fn build(b: *std.Build) void {
5050 "../../tools/update_glibc.zig",
5151 "../../tools/update_mingw.zig",
5252 "../../tools/update_netbsd_libc.zig",
53 "../../tools/update_openbsd_libc.zig",
5354 }) |tool_src_path| {
5455 if (std.mem.endsWith(u8, tool_src_path, "dump-cov.zig") and tools_target.result.os.tag == .windows) continue;
5556
tools/update_openbsd_libc.zig created+61
......@@ -0,0 +1,61 @@
1//! This script updates the .c, .h, .s, and .S files that make up the start
2//! files such as crt1.o.
3//!
4//! Example usage:
5//! `zig run tools/update_openbsd_libc.zig -- ~/Downloads/openbsd-src .`
6
7const std = @import("std");
8const Io = std.Io;
9
10const exempt_files = [_][]const u8{
11 // This file is maintained by a separate project and does not come from OpenBSD.
12 "abilists",
13};
14
15pub fn main(init: std.process.Init) !void {
16 const arena = init.arena.allocator();
17 const io = init.io;
18 const args = try init.minimal.args.toSlice(arena);
19
20 const openbsd_src_path = args[1];
21 const zig_src_path = args[2];
22
23 const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/openbsd", .{zig_src_path});
24
25 var dest_dir = Io.Dir.cwd().openDir(io, dest_dir_path, .{ .iterate = true }) catch |err| {
26 std.log.err("unable to open destination directory '{s}': {t}", .{ dest_dir_path, err });
27 std.process.exit(1);
28 };
29 defer dest_dir.close(io);
30
31 var openbsd_src_dir = try Io.Dir.cwd().openDir(io, openbsd_src_path, .{});
32 defer openbsd_src_dir.close(io);
33
34 // Copy updated files from upstream.
35 {
36 var walker = try dest_dir.walk(arena);
37 defer walker.deinit();
38
39 walk: while (try walker.next(io)) |entry| {
40 if (entry.kind != .file) continue;
41 if (std.mem.startsWith(u8, entry.basename, ".")) continue;
42 for (exempt_files) |p| {
43 if (std.mem.eql(u8, entry.path, p)) continue :walk;
44 }
45
46 std.log.info("updating '{s}/{s}' from '{s}/{s}'", .{
47 dest_dir_path, entry.path,
48 openbsd_src_path, entry.path,
49 });
50
51 openbsd_src_dir.copyFile(entry.path, dest_dir, entry.path, io, .{}) catch |err| {
52 std.log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {t}", .{
53 openbsd_src_path, entry.path, dest_dir_path, entry.path, err,
54 });
55 if (err == error.FileNotFound) {
56 try dest_dir.deleteFile(io, entry.path);
57 }
58 };
59 }
60 }
61}