authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-07 12:53:22 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-07 12:53:22 -07:00
log7395668d0b99e4702a35823da1a188afc3d4c409
treef5d975bde17ae24a565d1a764802ac35d60420b0
parent0bf546d95cb27488eadc3a6d3e389da9eed272ef

deps.zig- add `imports` struct for build dependencies


3 files changed, 23 insertions(+), 0 deletions(-)

deps.zig+4
...@@ -114,3 +114,7 @@ pub const pkgs = struct {...@@ -114,3 +114,7 @@ pub const pkgs = struct {
114 pub const zigmod = package_data._89ujp8gq842x;114 pub const zigmod = package_data._89ujp8gq842x;
115};115};
116116
117pub const imports = struct {
118 pub const zigmod = @import(".zigmod/deps/../../src/lib.zig");
119};
120
docs/deps.zig.md+4
...@@ -35,3 +35,7 @@ This is a an array of all of the items in `package_data`, but only contains the...@@ -35,3 +35,7 @@ This is a an array of all of the items in `package_data`, but only contains the
35### `pkgs`35### `pkgs`
36- Type: `struct<NAME, Package>`36- Type: `struct<NAME, Package>`
37This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project. 37This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project.
38
39### `imports`
40- Type: `struct<NAME, @import(main)>`
41This is a struct that contains the imports of your `dev_dependencies`. Added in response to [zig#2206](https://github.com/ziglang/zig/issues/2206).
src/cmd/fetch.zig+15
...@@ -101,6 +101,10 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis...@@ -101,6 +101,10 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis
101 try w.writeAll("pub const pkgs = ");101 try w.writeAll("pub const pkgs = ");
102 try print_pkgs(w, top_module);102 try print_pkgs(w, top_module);
103 try w.writeAll(";\n\n");103 try w.writeAll(";\n\n");
104
105 try w.writeAll("pub const imports = struct {\n");
106 try print_imports(w, top_module, dir);
107 try w.writeAll("};\n\n");
104}108}
105109
106fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {110fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {
...@@ -241,3 +245,14 @@ fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void {...@@ -241,3 +245,14 @@ fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void {
241 }245 }
242 try w.writeAll("}");246 try w.writeAll("}");
243}247}
248
249fn print_imports(w: std.fs.File.Writer, m: u.Module, dir: []const u8) !void {
250 for (m.deps) |d| {
251 if (d.main.len == 0) {
252 continue;
253 }
254 const r1 = try std.mem.replaceOwned(u8, gpa, d.name, "-", "_");
255 const r2 = try std.mem.replaceOwned(u8, gpa, r1, "/", "_");
256 try w.print(" pub const {s} = @import(\"{s}/{}/{s}\");\n", .{ r2, dir, std.zig.fmtEscapes(d.clean_path), d.main });
257 }
258}