authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 02:57:52 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 02:57:52 -08:00
logfb97f94ee81a6fca7950c481004e0f21d1682b5a
tree3b84dde27d6af256e5a90742ff1eba96f6f3df99
parentdf9cbb33a9e539c9075751edefb51453fde9d6fd

zig.mod- retire `dev_dependencies` in favor of `root_dependencies` and `build_dependencies`


11 files changed, 51 insertions(+), 13 deletions(-)

deps.zig-1
......@@ -164,5 +164,4 @@ pub const pkgs = struct {
164164};
165165
166166pub const imports = struct {
167 pub const zigmod = @import(".zigmod/deps/../../src/lib.zig");
168167};
docs/zig.mod.md+5-1
......@@ -42,10 +42,14 @@ This accepts a list of local directories to embed static assets. These files wil
4242- Type: `[]Dep`
4343This is a list of `Dep` objects. `Dep` objects are how you include the other people's code in your project. See the `Dep` documentation below to learn more about the attributes available here.
4444
45### `dev_dependencies`
45### `root_dependencies`
4646- Type: `[]Dep`
4747Similar to `dependencies` but will only get added to the project if the current `zig.mod` is the root module.
4848
49### `build_dependencies`
50- Type: `[]Dep`
51Similar to `dependencies` but will only get added to the project if the current `zig.mod` is the root module. Exposed in `deps.zig` through the `deps.imports` decl.
52
4953----
5054
5155### Dep Object
src/cmd/aquila/add.zig+6-1
......@@ -25,7 +25,12 @@ pub fn do(dir: std.fs.Dir, pkg_id: string) !string {
2525 });
2626
2727 const m = try zigmod.ModFile.from_dir(gpa, dir);
28 for (m.devdeps) |d| {
28 for (m.rootdeps) |d| {
29 if (std.mem.eql(u8, d.path, pkg_url)) {
30 return pkg_url;
31 }
32 }
33 for (m.builddeps) |d| {
2934 if (std.mem.eql(u8, d.path, pkg_url)) {
3035 return pkg_url;
3136 }
src/cmd/aquila/install.zig+7-1
......@@ -31,7 +31,13 @@ pub fn execute(args: [][]u8) !void {
3131 // get modfile and dep
3232 const m = try zigmod.ModFile.from_dir(gpa, homedir);
3333 var dep: zigmod.Dep = undefined;
34 for (m.devdeps) |d| {
34 for (m.rootdeps) |d| {
35 if (std.mem.eql(u8, d.path, pkgurl)) {
36 dep = d;
37 break;
38 }
39 }
40 for (m.builddeps) |d| {
3541 if (std.mem.eql(u8, d.path, pkgurl)) {
3642 dep = d;
3743 break;
src/cmd/fetch.zig+6
......@@ -351,6 +351,9 @@ fn print_pkgs(w: std.fs.File.Writer, m: zigmod.Module) !void {
351351 if (d.main.len == 0) {
352352 continue;
353353 }
354 if (d.for_build) {
355 continue;
356 }
354357 const ident = try zig_name_from_pkg_name(d.name);
355358 try w.print(" pub const {s} = package_data._{s};\n", .{ ident, d.id[0..12] });
356359 }
......@@ -362,6 +365,9 @@ fn print_imports(w: std.fs.File.Writer, m: zigmod.Module, path: string) !void {
362365 if (d.main.len == 0) {
363366 continue;
364367 }
368 if (!d.for_build) {
369 continue;
370 }
365371 const ident = try zig_name_from_pkg_name(d.name);
366372 try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main });
367373 }
src/cmd/zpm/add.zig+7-2
......@@ -40,9 +40,14 @@ pub fn execute(args: [][]u8) !void {
4040 std.log.warn("dependency with name '{s}' already exists in your dependencies", .{found.name});
4141 }
4242 }
43 for (self_module.devdeps) |dep| {
43 for (self_module.rootdeps) |dep| {
4444 if (std.mem.eql(u8, dep.name, found.name)) {
45 std.log.warn("dependency with name '{s}' already exists in your dev_dependencies", .{found.name});
45 std.log.warn("dependency with name '{s}' already exists in your root_dependencies", .{found.name});
46 }
47 }
48 for (self_module.builddeps) |dep| {
49 if (std.mem.eql(u8, dep.name, found.name)) {
50 std.log.warn("dependency with name '{s}' already exists in your build_dependencies", .{found.name});
4651 }
4752 }
4853
src/common.zig+8-1
......@@ -37,7 +37,12 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
3737 try moduledeps.append(try add_files_package(options.alloc, cachepath, "root", mdir, m.root_files));
3838 }
3939 try moduledeps.append(try collect_deps(cachepath, mdir, options));
40 for (m.devdeps) |*d| {
40 for (m.rootdeps) |*d| {
41 if (try get_module_from_dep(d, cachepath, options)) |founddep| {
42 try moduledeps.append(founddep);
43 }
44 }
45 for (m.builddeps) |*d| {
4146 if (try get_module_from_dep(d, cachepath, options)) |founddep| {
4247 try moduledeps.append(founddep);
4348 }
......@@ -229,6 +234,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
229234 .clean_path = d.path,
230235 .yaml = null,
231236 .dep = d.*,
237 .for_build = d.for_build,
232238 };
233239 },
234240 else => {
......@@ -259,6 +265,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
259265 else => e,
260266 };
261267 dd.dep = d.*;
268 dd.for_build = d.for_build;
262269 const save = dd;
263270 if (d.type != .local) dd.clean_path = u.trim_prefix(modpath, cachepath)[1..];
264271 if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48);
src/util/dep.zig+1
......@@ -28,6 +28,7 @@ pub const Dep = struct {
2828 deps: []zigmod.Dep,
2929 keep: bool = false,
3030 vcpkg: bool = false,
31 for_build: bool = false,
3132
3233 pub fn clean_path(self: Dep) !string {
3334 if (self.type == .local) {
src/util/modfile.zig+8-5
......@@ -23,9 +23,10 @@ pub const ModFile = struct {
2323 c_source_files: []const string,
2424 deps: []zigmod.Dep,
2525 yaml: yaml.Mapping,
26 devdeps: []zigmod.Dep,
2726 root_files: []const string,
2827 files: []const string,
28 rootdeps: []zigmod.Dep,
29 builddeps: []zigmod.Dep,
2930
3031 pub fn init(alloc: *std.mem.Allocator, mpath: string) !Self {
3132 const file = try std.fs.cwd().openFile(mpath, .{});
......@@ -59,15 +60,16 @@ pub const ModFile = struct {
5960 .c_include_dirs = try mapping.get_string_array(alloc, "c_include_dirs"),
6061 .c_source_flags = try mapping.get_string_array(alloc, "c_source_flags"),
6162 .c_source_files = try mapping.get_string_array(alloc, "c_source_files"),
62 .deps = try dep_list_by_name(alloc, mapping, &.{"dependencies"}),
63 .deps = try dep_list_by_name(alloc, mapping, &.{"dependencies"}, false),
6364 .yaml = mapping,
64 .devdeps = try dep_list_by_name(alloc, mapping, &.{"dev_dependencies"}),
6565 .root_files = try mapping.get_string_array(alloc, "root_files"),
6666 .files = try mapping.get_string_array(alloc, "files"),
67 .rootdeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "root_dependencies" }, false),
68 .builddeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "build_dependencies" }, true),
6769 };
6870 }
6971
70 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, props: []const string) anyerror![]zigmod.Dep {
72 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, props: []const string, for_build: bool) anyerror![]zigmod.Dep {
7173 var dep_list = std.ArrayList(zigmod.Dep).init(alloc);
7274 defer dep_list.deinit();
7375
......@@ -124,9 +126,10 @@ pub const ModFile = struct {
124126 .only_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("only_os"), ","), ""),
125127 .except_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("except_os"), ","), ""),
126128 .yaml = item.mapping,
127 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}),
129 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}, for_build),
128130 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep")),
129131 .vcpkg = std.mem.eql(u8, "true", item.mapping.get_string("vcpkg")),
132 .for_build = for_build,
130133 });
131134 }
132135 }
src/util/module.zig+2
......@@ -25,6 +25,7 @@ pub const Module = struct {
2525 deps: []Module,
2626 clean_path: string,
2727 dep: ?zigmod.Dep,
28 for_build: bool = false,
2829
2930 pub fn from(alloc: *std.mem.Allocator, dep: zigmod.Dep, modpath: string, options: *common.CollectOptions) !Module {
3031 var moddeps = std.ArrayList(Module).init(alloc);
......@@ -50,6 +51,7 @@ pub const Module = struct {
5051 .except_os = dep.except_os,
5152 .yaml = dep.yaml,
5253 .dep = dep,
54 .for_build = dep.for_build,
5355 };
5456 }
5557
zig.mod+1-1
......@@ -41,5 +41,5 @@ dependencies:
4141 - src: git https://github.com/nektro/zig-inquirer
4242 - src: git https://github.com/arqv/ini
4343
44dev_dependencies:
44root_dependencies:
4545 - src: git https://github.com/marlersoft/zigwin32