From 7395668d0b99e4702a35823da1a188afc3d4c409 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 7 Jul 2021 12:53:22 -0700 Subject: [PATCH] deps.zig- add `imports` struct for build dependencies --- deps.zig | 4 ++++ docs/deps.zig.md | 4 ++++ src/cmd/fetch.zig | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/deps.zig b/deps.zig index 1fcbd9bb38c20fada6de6eb803e2015e6a31e2ce..5fd43b88e96bbe4473c4df0dc9f7009649c6ee07 100644 --- a/deps.zig +++ b/deps.zig @@ -114,3 +114,7 @@ pub const pkgs = struct { pub const zigmod = package_data._89ujp8gq842x; }; +pub const imports = struct { + pub const zigmod = @import(".zigmod/deps/../../src/lib.zig"); +}; + diff --git a/docs/deps.zig.md b/docs/deps.zig.md index 7e342fe8fc2216dd30201c41fa1aa4e57820ee90..1fe2fcee000172e5ebf45a8f48a0562844313815 100644 --- a/docs/deps.zig.md +++ b/docs/deps.zig.md @@ -35,3 +35,7 @@ This is a an array of all of the items in `package_data`, but only contains the ### `pkgs` - Type: `struct` This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project. + +### `imports` +- Type: `struct` +This is a struct that contains the imports of your `dev_dependencies`. Added in response to [zig#2206](https://github.com/ziglang/zig/issues/2206). diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 3773bdf15c5f9637a9b0d963e335c8e52e8abfe3..4bc501af0e38b73e4c71b6f30bd9cc74baa07aeb 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -101,6 +101,10 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis try w.writeAll("pub const pkgs = "); try print_pkgs(w, top_module); try w.writeAll(";\n\n"); + + try w.writeAll("pub const imports = struct {\n"); + try print_imports(w, top_module, dir); + try w.writeAll("};\n\n"); } fn 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 { } try w.writeAll("}"); } + +fn print_imports(w: std.fs.File.Writer, m: u.Module, dir: []const u8) !void { + for (m.deps) |d| { + if (d.main.len == 0) { + continue; + } + const r1 = try std.mem.replaceOwned(u8, gpa, d.name, "-", "_"); + const r2 = try std.mem.replaceOwned(u8, gpa, r1, "/", "_"); + try w.print(" pub const {s} = @import(\"{s}/{}/{s}\");\n", .{ r2, dir, std.zig.fmtEscapes(d.clean_path), d.main }); + } +} -- 2.54.0