authoravatarMeghan Denny<hello@nektro.net>2026-10-25 03:59:50-07:00
committeravatarMeghan Denny<hello@nektro.net>2026-10-25 04:11:33-07:00
logd0471726b19a8f24d74d58481cd071f788a46097
tree913f7a8bb6a3e9bfc331c239fe19cb16542b95c9
parent373a525dc24ba7fe53338316d61a606657fac1a5
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

cmd/fetch: refinement around how local dependencies are handled

- src: local name path would work as intended when the dep was in the root but when a local dep had a local dep of its own 'path' was still relative to the root instead of the module dir

5 files changed, 18 insertions(+), 12 deletions(-)

docs/zig.mod.md+1-1
...@@ -88,7 +88,7 @@ The available `type`s are:...@@ -88,7 +88,7 @@ The available `type`s are:
8888
89For the full details on `Dep` types, you can check out the source where the enum is defined: https://github.com/nektro/zigmod/blob/master/src/util/dep_type.zig.89For the full details on `Dep` types, you can check out the source where the enum is defined: https://github.com/nektro/zigmod/blob/master/src/util/dep_type.zig.
9090
91> Note: the `local` type modifies the input behavior to be shorthand for `<name> <main>` rather than `path version` since the latter fields don't make sense for local files.91> Note: the `local` type modifies the input behavior to be shorthand for `name path` rather than `path ?version` since the latter fields don't make sense for local files.
9292
93#### Dep `version`93#### Dep `version`
94- Type: `string-string`94- Type: `string-string`
src/cmd/fetch.zig+4
...@@ -325,6 +325,10 @@ fn print_dirs(w: nfs.File, list: []const zigmod.Module, alloc: std.mem.Allocator...@@ -325,6 +325,10 @@ fn print_dirs(w: nfs.File, list: []const zigmod.Module, alloc: std.mem.Allocator
325 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), u.altStringEscape(cwd_realpath) });325 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), u.altStringEscape(cwd_realpath) });
326 continue;326 continue;
327 }327 }
328 if (mod.type == .local) {
329 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) });
330 continue;
331 }
328 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) });332 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) });
329 }333 }
330}334}
src/common.zig+8-10
...@@ -39,12 +39,12 @@ pub fn collect_deps_deep(cachepath: [:0]const u8, mdir: nfs.Dir, options: *Colle...@@ -39,12 +39,12 @@ pub fn collect_deps_deep(cachepath: [:0]const u8, mdir: nfs.Dir, options: *Colle
39 }39 }
40 try moduledeps.append(try collect_deps(cachepath, mdir, ".", .local, options));40 try moduledeps.append(try collect_deps(cachepath, mdir, ".", .local, options));
41 for (m.rootdeps) |*d| {41 for (m.rootdeps) |*d| {
42 if (try get_module_from_dep(d, cachepath, options)) |founddep| {42 if (try get_module_from_dep(d, mdir, cachepath, options)) |founddep| {
43 try moduledeps.append(founddep);43 try moduledeps.append(founddep);
44 }44 }
45 }45 }
46 for (m.builddeps) |*d| {46 for (m.builddeps) |*d| {
47 if (try get_module_from_dep(d, cachepath, options)) |founddep| {47 if (try get_module_from_dep(d, mdir, cachepath, options)) |founddep| {
48 try moduledeps.append(founddep);48 try moduledeps.append(founddep);
49 }49 }
50 }50 }
...@@ -72,7 +72,7 @@ pub fn collect_deps(cachepath: [:0]const u8, mdir: nfs.Dir, mdir_path: string, d...@@ -72,7 +72,7 @@ pub fn collect_deps(cachepath: [:0]const u8, mdir: nfs.Dir, mdir_path: string, d
72 try gen_files_package(options.alloc, cachepath, mdir, m.files);72 try gen_files_package(options.alloc, cachepath, mdir, m.files);
73 }73 }
74 for (m.deps) |*d| {74 for (m.deps) |*d| {
75 if (try get_module_from_dep(d, cachepath, options)) |founddep| {75 if (try get_module_from_dep(d, if (dtype == .local) mdir else nfs.cwd(), cachepath, options)) |founddep| {
76 try moduledeps.append(founddep);76 try moduledeps.append(founddep);
77 }77 }
78 }78 }
...@@ -122,9 +122,6 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !...@@ -122,9 +122,6 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
122 }122 }
123 switch (d.type) {123 switch (d.type) {
124 .local => {124 .local => {
125 if (!std.mem.endsWith(u8, d.main, ".zig")) {
126 return gpa.dupeSentinel(u8, d.main, 0);
127 }
128 return d.path;125 return d.path;
129 },126 },
130 .system_lib, .framework => {127 .system_lib, .framework => {
...@@ -216,7 +213,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !...@@ -216,7 +213,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
216 }213 }
217}214}
218215
219pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *CollectOptions) anyerror!?zigmod.Module {216pub fn get_module_from_dep(d: *zigmod.Dep, localdir: nfs.Dir, cachepath: [:0]const u8, options: *CollectOptions) anyerror!?zigmod.Module {
220 if (options.lock) |lock| {217 if (options.lock) |lock| {
221 for (lock) |item| {218 for (lock) |item| {
222 if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) {219 if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) {
...@@ -229,7 +226,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co...@@ -229,7 +226,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co
229 }226 }
230 if (!d.is_for_this()) return null;227 if (!d.is_for_this()) return null;
231 const modpath = try get_modpath(cachepath, d.*, options);228 const modpath = try get_modpath(cachepath, d.*, options);
232 const moddir = if (modpath.len == 0) try nfs.cwd().openDir(cachepath, .{}) else try nfs.cwd().openDir(modpath, .{});229 const moddir = if (modpath.len == 0) try nfs.cwd().openDir(cachepath, .{}) else try localdir.openDir(modpath, .{});
233230
234 const nocache = d.type.isLocal();231 const nocache = d.type.isLocal();
235 if (!nocache) try options.already_fetched.append(modpath);232 if (!nocache) try options.already_fetched.append(modpath);
...@@ -287,10 +284,12 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co...@@ -287,10 +284,12 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co
287 };284 };
288 dd.dep = d.*;285 dd.dep = d.*;
289 dd.for_build = d.for_build;286 dd.for_build = d.for_build;
290 const save = dd;
291 if (d.type != .local) {287 if (d.type != .local) {
292 const new_clean_path = extras.trimPrefix(modpath, cachepath)[1..];288 const new_clean_path = extras.trimPrefix(modpath, cachepath)[1..];
293 dd.clean_path = new_clean_path.ptr[0..new_clean_path.len :0];289 dd.clean_path = new_clean_path.ptr[0..new_clean_path.len :0];
290 } else {
291 dd.clean_path = try moddir.realpathAlloc(gpa, ".");
292 dd.clean_path = dd.clean_path[std.fs.path.dirname(std.fs.path.dirname(cachepath).?).?.len + 1 ..];
294 }293 }
295 if (std.mem.eql(u8, &dd.id, &zigmod.Dep.EMPTY)) dd.id = u.random_string(48);294 if (std.mem.eql(u8, &dd.id, &zigmod.Dep.EMPTY)) dd.id = u.random_string(48);
296 if (d.name.len > 0) dd.name = d.name;295 if (d.name.len > 0) dd.name = d.name;
...@@ -300,7 +299,6 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co...@@ -300,7 +299,6 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co
300 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;299 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;
301 if (d.only_os.len > 0) dd.only_os = d.only_os;300 if (d.only_os.len > 0) dd.only_os = d.only_os;
302 if (d.except_os.len > 0) dd.except_os = d.except_os;301 if (d.except_os.len > 0) dd.except_os = d.except_os;
303 if (d.type == .local) dd.main = try std.fs.path.join(options.alloc, &.{ d.main, save.main });
304 if (dd.is_for_this()) return dd;302 if (dd.is_for_this()) return dd;
305 return null;303 return null;
306 },304 },
src/util/modfile.zig+4
...@@ -132,6 +132,10 @@ pub const ModFile = struct {...@@ -132,6 +132,10 @@ pub const ModFile = struct {
132 main = version.?;132 main = version.?;
133 version = "";133 version = "";
134 }134 }
135 if (!std.mem.endsWith(u8, main, ".zig")) {
136 path = main;
137 main = "";
138 }
135 }139 }
136140
137 var id = zigmod.Dep.EMPTY;141 var id = zigmod.Dep.EMPTY;
src/util/module.zig+1-1
...@@ -38,7 +38,7 @@ pub const Module = struct {...@@ -38,7 +38,7 @@ pub const Module = struct {
38 errdefer moddeps.deinit();38 errdefer moddeps.deinit();
3939
40 for (dep.deps) |*d| {40 for (dep.deps) |*d| {
41 if (try common.get_module_from_dep(d, cachepath, options)) |founddep| {41 if (try common.get_module_from_dep(d, nfs.cwd(), cachepath, options)) |founddep| {
42 try moddeps.append(founddep);42 try moddeps.append(founddep);
43 }43 }
44 }44 }