diff --git a/src/cmd_add.zig b/src/cmd_add.zig index f0958cbb0ed1b4a18199f265e325089c5b3f3683..408c0efa2961d46998b7b5197f2c0e90b7c29023 100644 --- a/src/cmd_add.zig +++ b/src/cmd_add.zig @@ -29,6 +29,11 @@ pub fn execute(args: [][]u8) !void { try ndl.append(u.Dep{ .type = dep_type.?, .path = path, + .name = "", + .main = "", + .c_include_dirs = &[_][]const u8{}, + .c_source_flags = &[_][]const u8{}, + .c_source_files = &[_][]const u8{}, }); // diff --git a/src/cmd_fetch.zig b/src/cmd_fetch.zig index acc58720ee4b079d46327ca58bf1da5f40ceefe2..4d91c605f2acfbc4e61cde94837161c7cc7e75a9 100644 --- a/src/cmd_fetch.zig +++ b/src/cmd_fetch.zig @@ -86,8 +86,21 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { } switch (d.type) { else => { + if (d.main.len == 0) { + if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { + try moduledeps.append(try u.Module.from(d)); + } + break; + } var dd = try fetch_deps(dir, try std.fmt.allocPrint(gpa, "{}{}", .{p, "/zig.mod"})); dd.clean_path = try d.clean_path(); + + if (d.name.len > 0) dd.name = d.name; + if (d.main.len > 0) dd.main = d.main; + if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; + if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags; + if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; + try moduledeps.append(dd); }, } @@ -121,6 +134,9 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) an const t = " "; const r = try u.repeat(t, tabs); for (m.deps) |d| { + if (d.main.len == 0) { + continue; + } try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"build.Pkg{"})}); try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".name = \"",d.name,"\","})}); try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".path = cache ++ \"/",d.clean_path,"/",d.main,"\","})}); diff --git a/src/util/dep.zig b/src/util/dep.zig index 7bd70262ddaa99d6f0606a56a3ceb9dbfe4a044f..4b43950d83c992cfcbe3eb193cd6ce2eca667145 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -12,6 +12,12 @@ pub const Dep = struct { type: u.DepType, path: []const u8, + name: []const u8, + main: []const u8, + c_include_dirs: [][]const u8, + c_source_flags: [][]const u8, + c_source_files: [][]const u8, + pub fn clean_path(self: Dep) ![]const u8 { var p = self.path; p = u.trim_prefix(p, "https://"); diff --git a/src/util/modfile.zig b/src/util/modfile.zig index 0f9f8a6bfb42e69d2ae91c05a71015ab49dff1fe..67c7986abc3d9844348cf897f046f9c689f6da9a 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -43,6 +43,11 @@ pub const ModFile = struct { try dep_list.append(u.Dep{ .type = dep_type, .path = path, + .name = item.mapping.get_string("name"), + .main = item.mapping.get_string("main"), + .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"), + .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"), + .c_source_files = try item.mapping.get_string_array(alloc, "c_source_files"), }); } } diff --git a/src/util/module.zig b/src/util/module.zig index e92f94697f9dd22c639661cfb9ad02f6bfd51459..af0499f99609edaa02cc6b885f5632063d4fa618 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -1,5 +1,7 @@ const std = @import("std"); +const u = @import("index.zig"); + // // @@ -7,8 +9,21 @@ pub const Module = struct { name: []const u8, main: []const u8, c_include_dirs: [][]const u8, + c_source_flags: [][]const u8, c_source_files: [][]const u8, deps: []Module, clean_path: []const u8, + + pub fn from(dep: u.Dep) !Module { + return Module{ + .name = dep.name, + .main = dep.main, + .c_include_dirs = dep.c_include_dirs, + .c_source_flags = dep.c_source_flags, + .c_source_files = dep.c_source_files, + .deps = &[_]Module{}, + .clean_path = try dep.clean_path(), + }; + } }; diff --git a/src/util/yaml.zig b/src/util/yaml.zig index b4be65cd226014ca6f8078424cb7c1e30e7c5b07..b94ce1506f58265940917045e0cfa7ece73b1436 100644 --- a/src/util/yaml.zig +++ b/src/util/yaml.zig @@ -44,6 +44,10 @@ pub const Mapping = struct { return null; } + pub fn get_string(self: Mapping, k: []const u8) []const u8 { + return if (self.get(k)) |v| v.string else ""; + } + pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 { const list = &std.ArrayList([]const u8).init(alloc); if (self.get(k)) |val| {