authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-07 20:44:03 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-07 20:44:42 -07:00
log8dba61a43dd20c3eaf98e644dd703356c3fb2b97
tree7626d1c4c3dbaff8e549329f88317fbf63aad028
parent38e07cec2fc15dd9f4310e833bf4aac690fbdf07
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

cmd/fetch: make package_data const


1 files changed, 11 insertions(+), 8 deletions(-)

src/cmd/fetch.zig+11-8
......@@ -68,23 +68,24 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
6868 \\ exe.linkLibC();
6969 \\ }
7070 \\ // clear module memo cache so addAllTo can be called more than once in the same build.zig
71 \\ inline for (comptime std.meta.declarations(package_data)) |decl| @field(package_data, decl.name).module_memo = null;
71 \\ module_memo.clearAndFree(exe.step.owner.allocator);
7272 \\}
7373 \\
7474 \\var link_lib_c = false;
75 \\var module_memo: std.StringArrayHashMapUnmanaged(*std.Build.Module) = .empty;
7576 \\pub const Package = struct {
77 \\ id: string,
7678 \\ directory: string,
7779 \\ import: ?struct { string, std.Build.LazyPath } = null,
78 \\ dependencies: []const *Package,
80 \\ dependencies: []const *const Package,
7981 \\ c_include_dirs: []const string = &.{},
8082 \\ c_source_files: []const string = &.{},
8183 \\ c_source_flags: []const string = &.{},
8284 \\ system_libs: []const string = &.{},
8385 \\ frameworks: []const string = &.{},
84 \\ module_memo: ?*std.Build.Module = null,
8586 \\
86 \\ pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module {
87 \\ if (self.module_memo) |cached| {
87 \\ pub fn module(self: *const Package, exe: *std.Build.Step.Compile) *std.Build.Module {
88 \\ if (module_memo.get(self.id)) |cached| {
8889 \\ return cached;
8990 \\ }
9091 \\ const b = exe.step.owner;
......@@ -129,7 +130,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
129130 \\ result.link_libc = true;
130131 \\ exe.linkLibC();
131132 \\ }
132 \\ self.module_memo = result;
133 \\ module_memo.putNoClobber(b.allocator, self.id, result) catch @panic("OOM");
133134 \\ return result;
134135 \\ }
135136 \\};
......@@ -303,7 +304,7 @@ fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module, alloc: std.mem
303304}
304305
305306fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
306 try w.writeAll("&[_]*Package{\n");
307 try w.writeAll("&[_]*const Package{\n");
307308 for (m.deps) |d| {
308309 if (d.main.len == 0) {
309310 continue;
......@@ -322,12 +323,14 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
322323 for (notdone.items, 0..) |mod, i| {
323324 if (contains_all(mod.deps, done.items)) {
324325 try w.print(
325 \\ pub var _{s} = Package{{
326 \\ pub const _{s} = Package{{
327 \\ .id = "{s}",
326328 \\ .directory = dirs._{s},
327329 \\
328330 , .{
329331 mod.short_id(),
330332 mod.short_id(),
333 mod.short_id(),
331334 });
332335 if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {
333336 try w.print(