authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-03-20 12:00:28 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-03-20 12:00:28 -07:00
logab25f4a6d42217b41a7cb2e6b988ddac977fb18b
tree1bb447a20f5fbf499c5779e0903a7f37882e81f7
parent2ec0490a726b18e00f0c9f128b7c86953de96d1d

cmd/generate: only create one Module per package


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

src/cmd/generate.zig+12-6
......@@ -61,7 +61,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
6161 \\ var urlpath = url;
6262 \\ urlpath = trimPrefix(u8, urlpath, "https://");
6363 \\ urlpath = trimPrefix(u8, urlpath, "git://");
64 \\ const repopath = b.fmt("{s}/zigmod/deps/git/{s}/{s}", .{ b.cache_root, urlpath, commit });
64 \\ const repopath = b.fmt("{s}/zigmod/deps/git/{s}/{s}", .{ b.cache_root.path.?, urlpath, commit });
6565 \\ flip(std.fs.cwd().access(repopath, .{})) catch return result;
6666 \\
6767 \\ var clonestep = std.build.RunStep.create(b, "clone");
......@@ -86,7 +86,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
8686 \\ const b = exe.builder;
8787 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {
8888 \\ const path = &@field(package_data, decl.name).entry;
89 \\ const root = if (@field(package_data, decl.name).store) |_| b.cache_root else ".";
89 \\ const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else ".";
9090 \\ if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });
9191 \\ }
9292 \\
......@@ -129,7 +129,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
129129 \\ var vcpkg = false;
130130 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {
131131 \\ const pkg = @as(Package, @field(package_data, decl.name));
132 \\ const root = if (pkg.store) |st| b.fmt("{s}/zigmod/deps/{s}", .{ b.cache_root, st }) else ".";
132 \\ const root = if (pkg.store) |st| b.fmt("{s}/zigmod/deps/{s}", .{ b.cache_root.path.?, st }) else ".";
133133 \\ for (pkg.system_libs) |item| {
134134 \\ exe.linkSystemLibrary(item);
135135 \\ llc = true;
......@@ -164,19 +164,25 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
164164 \\ system_libs: []const string = &.{},
165165 \\ frameworks: []const string = &.{},
166166 \\ vcpkg: bool = false,
167 \\ module: ?ModuleDependency = null,
167168 \\
168 \\ pub fn zp(self: *const Package, b: *std.build.Builder) ModuleDependency {
169 \\ pub fn zp(self: *Package, b: *std.build.Builder) ModuleDependency {
169170 \\ var temp: [100]ModuleDependency = undefined;
170171 \\ for (self.deps, 0..) |item, i| {
171172 \\ temp[i] = item.zp(b);
172173 \\ }
173 \\ return .{
174 \\ if (self.module) |mod| {
175 \\ return mod;
176 \\ }
177 \\ const result = ModuleDependency{
174178 \\ .name = self.name,
175179 \\ .module = b.createModule(.{
176180 \\ .source_file = .{ .path = self.entry.? },
177181 \\ .dependencies = b.allocator.dupe(ModuleDependency, temp[0..self.deps.len]) catch @panic("oom"),
178182 \\ }),
179183 \\ };
184 \\ self.module = result;
185 \\ return result;
180186 \\ }
181187 \\};
182188 \\
......@@ -229,7 +235,7 @@ fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void {
229235}
230236
231237fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
232 try w.writeAll("[_]*const Package{\n");
238 try w.writeAll("[_]*Package{\n");
233239 for (m.deps) |d| {
234240 if (d.main.len == 0) {
235241 continue;