authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-19 04:30:34 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-19 04:30:34 -08:00
log2ce1b0d0d0d41d4858f2f5481fc299078cf5d44d
tree5367dbfc1372525fb784bd986f6695198b953f0e
parente5857e217f0a01d95581464d52c1e4aa822ccc4f

add c_source_flags property to zig.mod


2 files changed, 32 insertions(+), 5 deletions(-)

src/cmd_fetch.zig+30-5
......@@ -36,8 +36,8 @@ pub fn execute(args: [][]u8) !void {
3636 \\ for (c_include_dirs) |dir| {
3737 \\ exe.addIncludeDir(dir);
3838 \\ }
39 \\ for (c_source_files) |fpath| {
40 \\ exe.addCSourceFile(fpath, &[_][]const u8{});
39 \\ inline for (c_source_files) |fpath| {
40 \\ exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0]));
4141 \\ }
4242 \\}
4343 });
......@@ -50,7 +50,11 @@ pub fn execute(args: [][]u8) !void {
5050 try print_incl_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true);
5151 try w.print("{};\n", .{"}"});
5252 try w.print("\n", .{});
53 try w.print("{}\n", .{"pub const c_source_files = &[_][]const u8{"});
53 try w.print("{}\n", .{"pub const c_source_flags = struct {"});
54 try print_csrc_flags_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true);
55 try w.print("{};\n", .{"}"});
56 try w.print("\n", .{});
57 try w.print("{}\n", .{"pub const c_source_files = &[_][2][]const u8{"});
5458 try print_csrc_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true);
5559 try w.print("{};\n", .{"}"});
5660}
......@@ -92,6 +96,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
9296 .name = m.name,
9397 .main = m.main,
9498 .c_include_dirs = m.c_include_dirs,
99 .c_source_flags = m.c_source_flags,
95100 .c_source_files = m.c_source_files,
96101 .deps = moduledeps.items,
97102 .clean_path = "",
......@@ -151,12 +156,32 @@ fn print_csrc_dirs_to(w: std.fs.File.Writer, mod: u.Module, list: *std.ArrayList
151156 try list.append(mod.clean_path);
152157 for (mod.c_source_files) |it| {
153158 if (!local) {
154 try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it});
159 try w.print(" {}\"{}\", cache ++ \"/{}/{}\"{},\n", .{"[_][]const u8{", mod.clean_path, mod.clean_path, it, "}"});
155160 } else {
156 try w.print(" \".{}/{}\",\n", .{mod.clean_path, it});
161 try w.print(" {}\"{}\", \".{}/{}\"{},\n", .{"[_][]const u8{", mod.clean_path, mod.clean_path, it, "}"});
157162 }
158163 }
159164 for (mod.deps) |d| {
160165 try print_csrc_dirs_to(w, d, list, false);
161166 }
162167}
168
169fn print_csrc_flags_to(w: std.fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8), local: bool) anyerror!void {
170 if (u.list_contains(list, mod.clean_path)) {
171 return;
172 }
173 try list.append(mod.clean_path);
174 if (local) {
175 try w.print(" pub const @\"{}\" = {};\n", .{"", "&[_][]const u8{}"});
176 }
177 else {
178 try w.print(" pub const @\"{}\" = {}", .{mod.clean_path, "&[_][]const u8{"});
179 for (mod.c_source_flags) |it| {
180 try w.print("\"{Z}\",", .{it});
181 }
182 try w.print("{};\n", .{"}"});
183 }
184 for (mod.deps) |d| {
185 try print_csrc_flags_to(w, d, list, false);
186 }
187}
src/util/modfile.zig+2
......@@ -17,6 +17,7 @@ pub const ModFile = struct {
1717 name: []const u8,
1818 main: []const u8,
1919 c_include_dirs: [][]const u8,
20 c_source_flags: [][]const u8,
2021 c_source_files: [][]const u8,
2122 deps: []u.Dep,
2223
......@@ -52,6 +53,7 @@ pub const ModFile = struct {
5253 .name = name,
5354 .main = main,
5455 .c_include_dirs = try doc.mapping.get_string_array(alloc, "c_include_dirs"),
56 .c_source_flags = try doc.mapping.get_string_array(alloc, "c_source_flags"),
5557 .c_source_files = try doc.mapping.get_string_array(alloc, "c_source_files"),
5658 .deps = dep_list.items,
5759 };