diff --git a/src/common.zig b/src/common.zig index 247b7acc7e920d7b882b6e368f27640937a173a5..1fb285b516043ef2adafdc9ed5dba3f1276a6751 100644 --- a/src/common.zig +++ b/src/common.zig @@ -180,7 +180,7 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: C } } -fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8, parent_name: []const u8, options: CollectOptions) !void { +pub fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8, parent_name: []const u8, options: CollectOptions) anyerror!void { const moddir = try get_moddir(dir, d, parent_name, options); switch (d.type) { .system_lib => { @@ -203,7 +203,7 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8 var dd = try collect_deps(dir, try u.concat(&.{ moddir, "/zig.mod" }), options) catch |e| switch (e) { error.FileNotFound => { if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { - var mod_from = try u.Module.from(d); + var mod_from = try u.Module.from(d, dir, options); if (d.type != .local) mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; if (mod_from.is_for_this()) try list.append(mod_from); } @@ -283,6 +283,7 @@ fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, list: *std. .only_os = &.{}, .except_os = &.{}, .yaml = null, + .deps = &.{}, }; try get_module_from_dep(list, d, destination, parent_name, .{ .log = false, diff --git a/src/util/dep.zig b/src/util/dep.zig index 00209771c16c1dfb0af3001b872dabbbcc10e719..ba2259bb4a24e69fe0a1212a5d56baa9665b65d1 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -24,6 +24,7 @@ pub const Dep = struct { only_os: []const []const u8, except_os: []const []const u8, yaml: ?yaml.Mapping, + deps: []const u.Dep, pub fn clean_path(self: Dep) ![]const u8 { if (self.type == .local) { diff --git a/src/util/modfile.zig b/src/util/modfile.zig index a078dc7895e41d7fd518f0d3ca81025cb4e13628..2c16a14f808fe1ad475674ede9a17345fca3a78b 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -45,7 +45,6 @@ pub const ModFile = struct { u.assert(false, "name may not contain any '/'", .{}); } - return Self{ .alloc = alloc, .id = if (id.len == 0) try u.random_string(48) else id, @@ -62,7 +61,7 @@ pub const ModFile = struct { }; } - fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: []const u8) ![]const u.Dep { + fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: []const u8) anyerror![]const u.Dep { const dep_list = &std.ArrayList(u.Dep).init(alloc); if (mapping.get(prop)) |dep_seq| { if (dep_seq == .sequence) { @@ -115,6 +114,7 @@ pub const ModFile = struct { .only_os = try u.list_remove(try u.split(item.mapping.get_string("only_os"), ","), ""), .except_os = try u.list_remove(try u.split(item.mapping.get_string("except_os"), ","), ""), .yaml = item.mapping, + .deps = try dep_list_by_name(alloc, item.mapping, "dependencies"), }); } } diff --git a/src/util/module.zig b/src/util/module.zig index 3e1fa46b098de4aeb1ab2018c4ba6c7ca74f02e8..aeade0e7348168f662cffdec64534f722b9070f4 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -4,6 +4,7 @@ const builtin = std.builtin; const u = @import("index.zig"); const yaml = @import("./yaml.zig"); +const common = @import("./../common.zig"); // // @@ -23,7 +24,12 @@ pub const Module = struct { deps: []Module, clean_path: []const u8, - pub fn from(dep: u.Dep) !Module { + pub fn from(dep: u.Dep, dir: []const u8, options: common.CollectOptions) !Module { + const moddeps = &std.ArrayList(Module).init(gpa); + defer moddeps.deinit(); + for (dep.deps) |d| { + try common.get_module_from_dep(moddeps, d, dir, dep.name, options); + } return Module{ .is_sys_lib = false, .id = if (dep.id.len > 0) dep.id else try u.random_string(48), @@ -32,7 +38,7 @@ pub const Module = struct { .c_include_dirs = dep.c_include_dirs, .c_source_flags = dep.c_source_flags, .c_source_files = dep.c_source_files, - .deps = &.{}, + .deps = moddeps.toOwnedSlice(), .clean_path = try dep.clean_path(), .only_os = dep.only_os, .except_os = dep.except_os,