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...@@ -61,7 +61,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
61 \\ var urlpath = url;61 \\ var urlpath = url;
62 \\ urlpath = trimPrefix(u8, urlpath, "https://");62 \\ urlpath = trimPrefix(u8, urlpath, "https://");
63 \\ urlpath = trimPrefix(u8, urlpath, "git://");63 \\ 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 });
65 \\ flip(std.fs.cwd().access(repopath, .{})) catch return result;65 \\ flip(std.fs.cwd().access(repopath, .{})) catch return result;
66 \\66 \\
67 \\ var clonestep = std.build.RunStep.create(b, "clone");67 \\ 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...@@ -86,7 +86,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
86 \\ const b = exe.builder;86 \\ const b = exe.builder;
87 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {87 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {
88 \\ const path = &@field(package_data, decl.name).entry;88 \\ 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 ".";
90 \\ if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });90 \\ if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });
91 \\ }91 \\ }
92 \\92 \\
...@@ -129,7 +129,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -129,7 +129,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
129 \\ var vcpkg = false;129 \\ var vcpkg = false;
130 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {130 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {
131 \\ const pkg = @as(Package, @field(package_data, decl.name));131 \\ 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 ".";
133 \\ for (pkg.system_libs) |item| {133 \\ for (pkg.system_libs) |item| {
134 \\ exe.linkSystemLibrary(item);134 \\ exe.linkSystemLibrary(item);
135 \\ llc = true;135 \\ llc = true;
...@@ -164,19 +164,25 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -164,19 +164,25 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
164 \\ system_libs: []const string = &.{},164 \\ system_libs: []const string = &.{},
165 \\ frameworks: []const string = &.{},165 \\ frameworks: []const string = &.{},
166 \\ vcpkg: bool = false,166 \\ vcpkg: bool = false,
167 \\ module: ?ModuleDependency = null,
167 \\168 \\
168 \\ pub fn zp(self: *const Package, b: *std.build.Builder) ModuleDependency {169 \\ pub fn zp(self: *Package, b: *std.build.Builder) ModuleDependency {
169 \\ var temp: [100]ModuleDependency = undefined;170 \\ var temp: [100]ModuleDependency = undefined;
170 \\ for (self.deps, 0..) |item, i| {171 \\ for (self.deps, 0..) |item, i| {
171 \\ temp[i] = item.zp(b);172 \\ temp[i] = item.zp(b);
172 \\ }173 \\ }
173 \\ return .{174 \\ if (self.module) |mod| {
175 \\ return mod;
176 \\ }
177 \\ const result = ModuleDependency{
174 \\ .name = self.name,178 \\ .name = self.name,
175 \\ .module = b.createModule(.{179 \\ .module = b.createModule(.{
176 \\ .source_file = .{ .path = self.entry.? },180 \\ .source_file = .{ .path = self.entry.? },
177 \\ .dependencies = b.allocator.dupe(ModuleDependency, temp[0..self.deps.len]) catch @panic("oom"),181 \\ .dependencies = b.allocator.dupe(ModuleDependency, temp[0..self.deps.len]) catch @panic("oom"),
178 \\ }),182 \\ }),
179 \\ };183 \\ };
184 \\ self.module = result;
185 \\ return result;
180 \\ }186 \\ }
181 \\};187 \\};
182 \\188 \\
...@@ -229,7 +235,7 @@ fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void {...@@ -229,7 +235,7 @@ fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void {
229}235}
230236
231fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {237fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
232 try w.writeAll("[_]*const Package{\n");238 try w.writeAll("[_]*Package{\n");
233 for (m.deps) |d| {239 for (m.deps) |d| {
234 if (d.main.len == 0) {240 if (d.main.len == 0) {
235 continue;241 continue;