authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-16 17:56:31 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-16 17:56:31 -08:00
log4f99940d97755b0da8226d56cd3b2995023f159c
treeaf92cc35e91ce95c036538c2dbca34228e03968f
parent7fc8d1bb6a4a2bc178a99dc1b6f918402c8a3c31

fetch: add util func to add all deps to an exe/lib


2 files changed, 12 insertions(+), 6 deletions(-)

README.md+1-3
......@@ -67,9 +67,7 @@ pub fn build(b: *Builder) void {
6767 const exe = b.addExecutable("zigmod", "src/main.zig");
6868 exe.setTarget(target);
6969 exe.setBuildMode(mode);
70+ for (deps.packages) |pkg| {
71+ exe.addPackage(pkg);
72+ }
70+ deps.addAllTo(exe);
7371 for (deps.system_libs) |lib| {
7472 exe.linkSystemLibrary(lib);
7573 }
src/cmd_fetch.zig+11-3
......@@ -20,11 +20,19 @@ pub fn execute(args: [][]u8) !void {
2020
2121 const w = f.writer();
2222 try w.print("const std = @import(\"std\");\n", .{});
23 try w.print("const Pkg = std.build.Pkg;\n", .{});
23 try w.print("const build = std.build;\n", .{});
2424 try w.print("\n", .{});
2525 try w.print("const home = \"{}\";\n", .{home});
2626 try w.print("const cache = home ++ \"/.cache/zigmod/deps\";\n", .{});
2727 try w.print("\n", .{});
28 try w.print("{}\n", .{
29 \\pub fn addAllTo(exe: build.LibExeObjStep) void {
30 \\ for (packages) |pkg| {
31 \\ exe.addPackage(pkg);
32 \\ }
33 \\}
34 });
35 try w.print("\n", .{});
2836 try w.print("pub const packages = ", .{});
2937 try print_deps(w, dir, try u.ModFile.init(gpa, "./zig.mod"), 0);
3038 try w.print(";\n", .{});
......@@ -68,7 +76,7 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.ModFile, tabs: i32) a
6876 try w.print("null", .{});
6977 return;
7078 }
71 try u.print_all(w, .{"&[_]Pkg{"}, true);
79 try u.print_all(w, .{"&[_]build.Pkg{"}, true);
7280 const t = " ";
7381 const r = try u.repeat(t, tabs);
7482 for (m.deps) |d| {
......@@ -77,7 +85,7 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.ModFile, tabs: i32) a
7785 const np = try u.concat(&[_][]const u8{p, "/zig.mod"});
7886 const n = try u.ModFile.init(gpa, np);
7987
80 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"Pkg{"})});
88 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"build.Pkg{"})});
8189 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".name = \"",n.name,"\","})});
8290 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".path = cache ++ \"/",dcpath,"/",n.main,"\","})});
8391 try w.print("{}", .{try u.concat(&[_][]const u8{r,t,t,".dependencies = "})});