| ... | ... | @@ -68,23 +68,24 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D |
| 68 | 68 | \\ exe.linkLibC(); |
| 69 | 69 | \\ } |
| 70 | 70 | \\ // 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 | 74 | \\var link_lib_c = false; |
| 75 | \\var module_memo: std.StringArrayHashMapUnmanaged(*std.Build.Module) = .empty; |
| 75 | 76 | \\pub const Package = struct { |
| 77 | \\ id: string, |
| 76 | 78 | \\ directory: string, |
| 77 | 79 | \\ import: ?struct { string, std.Build.LazyPath } = null, |
| 78 | | \\ dependencies: []const *Package, |
| 80 | \\ dependencies: []const *const Package, |
| 79 | 81 | \\ c_include_dirs: []const string = &.{}, |
| 80 | 82 | \\ c_source_files: []const string = &.{}, |
| 81 | 83 | \\ c_source_flags: []const string = &.{}, |
| 82 | 84 | \\ system_libs: []const string = &.{}, |
| 83 | 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 | | \\ 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| { |
| 88 | 89 | \\ return cached; |
| 89 | 90 | \\ } |
| 90 | 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 | 130 | \\ result.link_libc = true; |
| 130 | 131 | \\ exe.linkLibC(); |
| 131 | 132 | \\ } |
| 132 | | \\ self.module_memo = result; |
| 133 | \\ module_memo.putNoClobber(b.allocator, self.id, result) catch @panic("OOM"); |
| 133 | 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 | 304 | } |
| 304 | 305 | |
| 305 | 306 | fn 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 | 308 | for (m.deps) |d| { |
| 308 | 309 | if (d.main.len == 0) { |
| 309 | 310 | continue; |
| ... | ... | @@ -322,12 +323,14 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul |
| 322 | 323 | for (notdone.items, 0..) |mod, i| { |
| 323 | 324 | if (contains_all(mod.deps, done.items)) { |
| 324 | 325 | try w.print( |
| 325 | | \\ pub var _{s} = Package{{ |
| 326 | \\ pub const _{s} = Package{{ |
| 327 | \\ .id = "{s}", |
| 326 | 328 | \\ .directory = dirs._{s}, |
| 327 | 329 | \\ |
| 328 | 330 | , .{ |
| 329 | 331 | mod.short_id(), |
| 330 | 332 | mod.short_id(), |
| 333 | mod.short_id(), |
| 331 | 334 | }); |
| 332 | 335 | if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) { |
| 333 | 336 | try w.print( |