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...@@ -68,23 +68,24 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
68 \\ exe.linkLibC();68 \\ exe.linkLibC();
69 \\ }69 \\ }
70 \\ // clear module memo cache so addAllTo can be called more than once in the same build.zig70 \\ // 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);
72 \\}72 \\}
73 \\73 \\
74 \\var link_lib_c = false;74 \\var link_lib_c = false;
75 \\var module_memo: std.StringArrayHashMapUnmanaged(*std.Build.Module) = .empty;
75 \\pub const Package = struct {76 \\pub const Package = struct {
77 \\ id: string,
76 \\ directory: string,78 \\ directory: string,
77 \\ import: ?struct { string, std.Build.LazyPath } = null,79 \\ import: ?struct { string, std.Build.LazyPath } = null,
78 \\ dependencies: []const *Package,80 \\ dependencies: []const *const Package,
79 \\ c_include_dirs: []const string = &.{},81 \\ c_include_dirs: []const string = &.{},
80 \\ c_source_files: []const string = &.{},82 \\ c_source_files: []const string = &.{},
81 \\ c_source_flags: []const string = &.{},83 \\ c_source_flags: []const string = &.{},
82 \\ system_libs: []const string = &.{},84 \\ system_libs: []const string = &.{},
83 \\ frameworks: []const string = &.{},85 \\ frameworks: []const string = &.{},
84 \\ module_memo: ?*std.Build.Module = null,
85 \\86 \\
86 \\ pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module {87 \\ pub fn module(self: *const Package, exe: *std.Build.Step.Compile) *std.Build.Module {
87 \\ if (self.module_memo) |cached| {88 \\ if (module_memo.get(self.id)) |cached| {
88 \\ return cached;89 \\ return cached;
89 \\ }90 \\ }
90 \\ const b = exe.step.owner;91 \\ const b = exe.step.owner;
...@@ -129,7 +130,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -129,7 +130,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
129 \\ result.link_libc = true;130 \\ result.link_libc = true;
130 \\ exe.linkLibC();131 \\ exe.linkLibC();
131 \\ }132 \\ }
132 \\ self.module_memo = result;133 \\ module_memo.putNoClobber(b.allocator, self.id, result) catch @panic("OOM");
133 \\ return result;134 \\ return result;
134 \\ }135 \\ }
135 \\};136 \\};
...@@ -303,7 +304,7 @@ fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module, alloc: std.mem...@@ -303,7 +304,7 @@ fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module, alloc: std.mem
303}304}
304305
305fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {306fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
306 try w.writeAll("&[_]*Package{\n");307 try w.writeAll("&[_]*const Package{\n");
307 for (m.deps) |d| {308 for (m.deps) |d| {
308 if (d.main.len == 0) {309 if (d.main.len == 0) {
309 continue;310 continue;
...@@ -322,12 +323,14 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul...@@ -322,12 +323,14 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
322 for (notdone.items, 0..) |mod, i| {323 for (notdone.items, 0..) |mod, i| {
323 if (contains_all(mod.deps, done.items)) {324 if (contains_all(mod.deps, done.items)) {
324 try w.print(325 try w.print(
325 \\ pub var _{s} = Package{{326 \\ pub const _{s} = Package{{
327 \\ .id = "{s}",
326 \\ .directory = dirs._{s},328 \\ .directory = dirs._{s},
327 \\329 \\
328 , .{330 , .{
329 mod.short_id(),331 mod.short_id(),
330 mod.short_id(),332 mod.short_id(),
333 mod.short_id(),
331 });334 });
332 if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {335 if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {
333 try w.print(336 try w.print(