From 27c6c3754ca8e00b61371c3ea10e1efa38767183 Mon Sep 17 00:00:00 2001 From: Meghan Date: Sat, 28 Nov 2020 12:43:03 -0800 Subject: [PATCH] dry up deps.zig --- src/cmd_fetch.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cmd_fetch.zig b/src/cmd_fetch.zig index 1c6b6b36c0bc6cb7063ee19af6516666bb82dac7..f2e6897a9d32aaceb9b7bd859a7d0ef993160a4f 100644 --- a/src/cmd_fetch.zig +++ b/src/cmd_fetch.zig @@ -40,6 +40,10 @@ pub fn execute(args: [][]u8) !void { \\ exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0])); \\ } \\} + \\ + \\fn get_flags(comptime index: usize) []const u8 { + \\ return std.meta.declarations(c_source_flags)[index].name; + \\} }); try w.print("\n", .{}); try w.print("pub const packages = ", .{}); @@ -211,9 +215,9 @@ fn print_csrc_dirs_to(w: std.fs.File.Writer, mod: u.Module, list: *std.ArrayList try list.append(mod.clean_path); for (mod.c_source_files) |it| { if (!local) { - try w.print(" {}\"{}\", cache ++ \"/{}/{}\"{},\n", .{"[_][]const u8{", mod.clean_path, mod.clean_path, it, "}"}); + try w.print(" {}comptime get_flags({}), cache ++ \"/{}/{}\"{},\n", .{"[_][]const u8{", list.items.len-1, mod.clean_path, it, "}"}); } else { - try w.print(" {}\"{}\", \".{}/{}\"{},\n", .{"[_][]const u8{", mod.clean_path, mod.clean_path, it, "}"}); + try w.print(" {}comptime get_flags({}), \".{}/{}\"{},\n", .{"[_][]const u8{", list.items.len-1, mod.clean_path, it, "}"}); } } for (mod.deps) |d| { -- 2.54.0