| author | |
| committer | |
| log | fb97f94ee81a6fca7950c481004e0f21d1682b5a |
| tree | 3b84dde27d6af256e5a90742ff1eba96f6f3df99 |
| parent | df9cbb33a9e539c9075751edefb51453fde9d6fd |
11 files changed, 51 insertions(+), 13 deletions(-)
deps.zig-1| ... | @@ -164,5 +164,4 @@ pub const pkgs = struct { | ... | @@ -164,5 +164,4 @@ pub const pkgs = struct { |
| 164 | }; | 164 | }; |
| 165 | 165 | ||
| 166 | pub const imports = struct { | 166 | pub const imports = struct { |
| 167 | pub const zigmod = @import(".zigmod/deps/../../src/lib.zig"); | ||
| 168 | }; | 167 | }; |
docs/zig.mod.md+5-1| ... | @@ -42,10 +42,14 @@ This accepts a list of local directories to embed static assets. These files wil | ... | @@ -42,10 +42,14 @@ This accepts a list of local directories to embed static assets. These files wil |
| 42 | - Type: `[]Dep` | 42 | - Type: `[]Dep` |
| 43 | This 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. | 43 | This 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. |
| 44 | 44 | ||
| 45 | ### `dev_dependencies` | 45 | ### `root_dependencies` |
| 46 | - Type: `[]Dep` | 46 | - Type: `[]Dep` |
| 47 | Similar to `dependencies` but will only get added to the project if the current `zig.mod` is the root module. | 47 | Similar to `dependencies` but will only get added to the project if the current `zig.mod` is the root module. |
| 48 | 48 | ||
| 49 | ### `build_dependencies` | ||
| 50 | - Type: `[]Dep` | ||
| 51 | Similar 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 | |||
| 49 | ---- | 53 | ---- |
| 50 | 54 | ||
| 51 | ### Dep Object | 55 | ### Dep Object |
src/cmd/aquila/add.zig+6-1| ... | @@ -25,7 +25,12 @@ pub fn do(dir: std.fs.Dir, pkg_id: string) !string { | ... | @@ -25,7 +25,12 @@ pub fn do(dir: std.fs.Dir, pkg_id: string) !string { |
| 25 | }); | 25 | }); |
| 26 | 26 | ||
| 27 | const m = try zigmod.ModFile.from_dir(gpa, dir); | 27 | 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| { | ||
| 29 | if (std.mem.eql(u8, d.path, pkg_url)) { | 34 | if (std.mem.eql(u8, d.path, pkg_url)) { |
| 30 | return pkg_url; | 35 | return pkg_url; |
| 31 | } | 36 | } |
src/cmd/aquila/install.zig+7-1| ... | @@ -31,7 +31,13 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -31,7 +31,13 @@ pub fn execute(args: [][]u8) !void { |
| 31 | // get modfile and dep | 31 | // get modfile and dep |
| 32 | const m = try zigmod.ModFile.from_dir(gpa, homedir); | 32 | const m = try zigmod.ModFile.from_dir(gpa, homedir); |
| 33 | var dep: zigmod.Dep = undefined; | 33 | 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| { | ||
| 35 | if (std.mem.eql(u8, d.path, pkgurl)) { | 41 | if (std.mem.eql(u8, d.path, pkgurl)) { |
| 36 | dep = d; | 42 | dep = d; |
| 37 | break; | 43 | break; |
src/cmd/fetch.zig+6| ... | @@ -351,6 +351,9 @@ fn print_pkgs(w: std.fs.File.Writer, m: zigmod.Module) !void { | ... | @@ -351,6 +351,9 @@ fn print_pkgs(w: std.fs.File.Writer, m: zigmod.Module) !void { |
| 351 | if (d.main.len == 0) { | 351 | if (d.main.len == 0) { |
| 352 | continue; | 352 | continue; |
| 353 | } | 353 | } |
| 354 | if (d.for_build) { | ||
| 355 | continue; | ||
| 356 | } | ||
| 354 | const ident = try zig_name_from_pkg_name(d.name); | 357 | const ident = try zig_name_from_pkg_name(d.name); |
| 355 | try w.print(" pub const {s} = package_data._{s};\n", .{ ident, d.id[0..12] }); | 358 | try w.print(" pub const {s} = package_data._{s};\n", .{ ident, d.id[0..12] }); |
| 356 | } | 359 | } |
| ... | @@ -362,6 +365,9 @@ fn print_imports(w: std.fs.File.Writer, m: zigmod.Module, path: string) !void { | ... | @@ -362,6 +365,9 @@ fn print_imports(w: std.fs.File.Writer, m: zigmod.Module, path: string) !void { |
| 362 | if (d.main.len == 0) { | 365 | if (d.main.len == 0) { |
| 363 | continue; | 366 | continue; |
| 364 | } | 367 | } |
| 368 | if (!d.for_build) { | ||
| 369 | continue; | ||
| 370 | } | ||
| 365 | const ident = try zig_name_from_pkg_name(d.name); | 371 | const ident = try zig_name_from_pkg_name(d.name); |
| 366 | try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main }); | 372 | try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main }); |
| 367 | } | 373 | } |
src/cmd/zpm/add.zig+7-2| ... | @@ -40,9 +40,14 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -40,9 +40,14 @@ pub fn execute(args: [][]u8) !void { |
| 40 | std.log.warn("dependency with name '{s}' already exists in your dependencies", .{found.name}); | 40 | std.log.warn("dependency with name '{s}' already exists in your dependencies", .{found.name}); |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | for (self_module.devdeps) |dep| { | 43 | for (self_module.rootdeps) |dep| { |
| 44 | if (std.mem.eql(u8, dep.name, found.name)) { | 44 | 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}); | ||
| 46 | } | 51 | } |
| 47 | } | 52 | } |
| 48 | 53 |
src/common.zig+8-1| ... | @@ -37,7 +37,12 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO | ... | @@ -37,7 +37,12 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO |
| 37 | try moduledeps.append(try add_files_package(options.alloc, cachepath, "root", mdir, m.root_files)); | 37 | try moduledeps.append(try add_files_package(options.alloc, cachepath, "root", mdir, m.root_files)); |
| 38 | } | 38 | } |
| 39 | try moduledeps.append(try collect_deps(cachepath, mdir, options)); | 39 | 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| { | ||
| 41 | if (try get_module_from_dep(d, cachepath, options)) |founddep| { | 46 | if (try get_module_from_dep(d, cachepath, options)) |founddep| { |
| 42 | try moduledeps.append(founddep); | 47 | try moduledeps.append(founddep); |
| 43 | } | 48 | } |
| ... | @@ -229,6 +234,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO | ... | @@ -229,6 +234,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 229 | .clean_path = d.path, | 234 | .clean_path = d.path, |
| 230 | .yaml = null, | 235 | .yaml = null, |
| 231 | .dep = d.*, | 236 | .dep = d.*, |
| 237 | .for_build = d.for_build, | ||
| 232 | }; | 238 | }; |
| 233 | }, | 239 | }, |
| 234 | else => { | 240 | else => { |
| ... | @@ -259,6 +265,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO | ... | @@ -259,6 +265,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 259 | else => e, | 265 | else => e, |
| 260 | }; | 266 | }; |
| 261 | dd.dep = d.*; | 267 | dd.dep = d.*; |
| 268 | dd.for_build = d.for_build; | ||
| 262 | const save = dd; | 269 | const save = dd; |
| 263 | if (d.type != .local) dd.clean_path = u.trim_prefix(modpath, cachepath)[1..]; | 270 | if (d.type != .local) dd.clean_path = u.trim_prefix(modpath, cachepath)[1..]; |
| 264 | if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48); | 271 | 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 { | ... | @@ -28,6 +28,7 @@ pub const Dep = struct { |
| 28 | deps: []zigmod.Dep, | 28 | deps: []zigmod.Dep, |
| 29 | keep: bool = false, | 29 | keep: bool = false, |
| 30 | vcpkg: bool = false, | 30 | vcpkg: bool = false, |
| 31 | for_build: bool = false, | ||
| 31 | 32 | ||
| 32 | pub fn clean_path(self: Dep) !string { | 33 | pub fn clean_path(self: Dep) !string { |
| 33 | if (self.type == .local) { | 34 | if (self.type == .local) { |
src/util/modfile.zig+8-5| ... | @@ -23,9 +23,10 @@ pub const ModFile = struct { | ... | @@ -23,9 +23,10 @@ pub const ModFile = struct { |
| 23 | c_source_files: []const string, | 23 | c_source_files: []const string, |
| 24 | deps: []zigmod.Dep, | 24 | deps: []zigmod.Dep, |
| 25 | yaml: yaml.Mapping, | 25 | yaml: yaml.Mapping, |
| 26 | devdeps: []zigmod.Dep, | ||
| 27 | root_files: []const string, | 26 | root_files: []const string, |
| 28 | files: []const string, | 27 | files: []const string, |
| 28 | rootdeps: []zigmod.Dep, | ||
| 29 | builddeps: []zigmod.Dep, | ||
| 29 | 30 | ||
| 30 | pub fn init(alloc: *std.mem.Allocator, mpath: string) !Self { | 31 | pub fn init(alloc: *std.mem.Allocator, mpath: string) !Self { |
| 31 | const file = try std.fs.cwd().openFile(mpath, .{}); | 32 | const file = try std.fs.cwd().openFile(mpath, .{}); |
| ... | @@ -59,15 +60,16 @@ pub const ModFile = struct { | ... | @@ -59,15 +60,16 @@ pub const ModFile = struct { |
| 59 | .c_include_dirs = try mapping.get_string_array(alloc, "c_include_dirs"), | 60 | .c_include_dirs = try mapping.get_string_array(alloc, "c_include_dirs"), |
| 60 | .c_source_flags = try mapping.get_string_array(alloc, "c_source_flags"), | 61 | .c_source_flags = try mapping.get_string_array(alloc, "c_source_flags"), |
| 61 | .c_source_files = try mapping.get_string_array(alloc, "c_source_files"), | 62 | .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), |
| 63 | .yaml = mapping, | 64 | .yaml = mapping, |
| 64 | .devdeps = try dep_list_by_name(alloc, mapping, &.{"dev_dependencies"}), | ||
| 65 | .root_files = try mapping.get_string_array(alloc, "root_files"), | 65 | .root_files = try mapping.get_string_array(alloc, "root_files"), |
| 66 | .files = try mapping.get_string_array(alloc, "files"), | 66 | .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), | ||
| 67 | }; | 69 | }; |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 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 { |
| 71 | var dep_list = std.ArrayList(zigmod.Dep).init(alloc); | 73 | var dep_list = std.ArrayList(zigmod.Dep).init(alloc); |
| 72 | defer dep_list.deinit(); | 74 | defer dep_list.deinit(); |
| 73 | 75 | ||
| ... | @@ -124,9 +126,10 @@ pub const ModFile = struct { | ... | @@ -124,9 +126,10 @@ pub const ModFile = struct { |
| 124 | .only_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("only_os"), ","), ""), | 126 | .only_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("only_os"), ","), ""), |
| 125 | .except_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("except_os"), ","), ""), | 127 | .except_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("except_os"), ","), ""), |
| 126 | .yaml = item.mapping, | 128 | .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), |
| 128 | .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep")), | 130 | .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep")), |
| 129 | .vcpkg = std.mem.eql(u8, "true", item.mapping.get_string("vcpkg")), | 131 | .vcpkg = std.mem.eql(u8, "true", item.mapping.get_string("vcpkg")), |
| 132 | .for_build = for_build, | ||
| 130 | }); | 133 | }); |
| 131 | } | 134 | } |
| 132 | } | 135 | } |
src/util/module.zig+2| ... | @@ -25,6 +25,7 @@ pub const Module = struct { | ... | @@ -25,6 +25,7 @@ pub const Module = struct { |
| 25 | deps: []Module, | 25 | deps: []Module, |
| 26 | clean_path: string, | 26 | clean_path: string, |
| 27 | dep: ?zigmod.Dep, | 27 | dep: ?zigmod.Dep, |
| 28 | for_build: bool = false, | ||
| 28 | 29 | ||
| 29 | pub fn from(alloc: *std.mem.Allocator, dep: zigmod.Dep, modpath: string, options: *common.CollectOptions) !Module { | 30 | pub fn from(alloc: *std.mem.Allocator, dep: zigmod.Dep, modpath: string, options: *common.CollectOptions) !Module { |
| 30 | var moddeps = std.ArrayList(Module).init(alloc); | 31 | var moddeps = std.ArrayList(Module).init(alloc); |
| ... | @@ -50,6 +51,7 @@ pub const Module = struct { | ... | @@ -50,6 +51,7 @@ pub const Module = struct { |
| 50 | .except_os = dep.except_os, | 51 | .except_os = dep.except_os, |
| 51 | .yaml = dep.yaml, | 52 | .yaml = dep.yaml, |
| 52 | .dep = dep, | 53 | .dep = dep, |
| 54 | .for_build = dep.for_build, | ||
| 53 | }; | 55 | }; |
| 54 | } | 56 | } |
| 55 | 57 |
zig.mod+1-1| ... | @@ -41,5 +41,5 @@ dependencies: | ... | @@ -41,5 +41,5 @@ dependencies: |
| 41 | - src: git https://github.com/nektro/zig-inquirer | 41 | - src: git https://github.com/nektro/zig-inquirer |
| 42 | - src: git https://github.com/arqv/ini | 42 | - src: git https://github.com/arqv/ini |
| 43 | 43 | ||
| 44 | dev_dependencies: | 44 | root_dependencies: |
| 45 | - src: git https://github.com/marlersoft/zigwin32 | 45 | - src: git https://github.com/marlersoft/zigwin32 |