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 {...@@ -36,8 +36,8 @@ pub fn execute(args: [][]u8) !void {
36 \\ for (c_include_dirs) |dir| {36 \\ for (c_include_dirs) |dir| {
37 \\ exe.addIncludeDir(dir);37 \\ exe.addIncludeDir(dir);
38 \\ }38 \\ }
39 \\ for (c_source_files) |fpath| {39 \\ inline for (c_source_files) |fpath| {
40 \\ exe.addCSourceFile(fpath, &[_][]const u8{});40 \\ exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0]));
41 \\ }41 \\ }
42 \\}42 \\}
43 });43 });
...@@ -50,7 +50,11 @@ pub fn execute(args: [][]u8) !void {...@@ -50,7 +50,11 @@ pub fn execute(args: [][]u8) !void {
50 try print_incl_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true);50 try print_incl_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true);
51 try w.print("{};\n", .{"}"});51 try w.print("{};\n", .{"}"});
52 try w.print("\n", .{});52 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{"});
54 try print_csrc_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true);58 try print_csrc_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true);
55 try w.print("{};\n", .{"}"});59 try w.print("{};\n", .{"}"});
56}60}
...@@ -92,6 +96,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {...@@ -92,6 +96,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
92 .name = m.name,96 .name = m.name,
93 .main = m.main,97 .main = m.main,
94 .c_include_dirs = m.c_include_dirs,98 .c_include_dirs = m.c_include_dirs,
99 .c_source_flags = m.c_source_flags,
95 .c_source_files = m.c_source_files,100 .c_source_files = m.c_source_files,
96 .deps = moduledeps.items,101 .deps = moduledeps.items,
97 .clean_path = "",102 .clean_path = "",
...@@ -151,12 +156,32 @@ fn print_csrc_dirs_to(w: std.fs.File.Writer, mod: u.Module, list: *std.ArrayList...@@ -151,12 +156,32 @@ fn print_csrc_dirs_to(w: std.fs.File.Writer, mod: u.Module, list: *std.ArrayList
151 try list.append(mod.clean_path);156 try list.append(mod.clean_path);
152 for (mod.c_source_files) |it| {157 for (mod.c_source_files) |it| {
153 if (!local) {158 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, "}"});
155 } else {160 } else {
156 try w.print(" \".{}/{}\",\n", .{mod.clean_path, it});161 try w.print(" {}\"{}\", \".{}/{}\"{},\n", .{"[_][]const u8{", mod.clean_path, mod.clean_path, it, "}"});
157 }162 }
158 }163 }
159 for (mod.deps) |d| {164 for (mod.deps) |d| {
160 try print_csrc_dirs_to(w, d, list, false);165 try print_csrc_dirs_to(w, d, list, false);
161 }166 }
162}167}
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 {...@@ -17,6 +17,7 @@ pub const ModFile = struct {
17 name: []const u8,17 name: []const u8,
18 main: []const u8,18 main: []const u8,
19 c_include_dirs: [][]const u8,19 c_include_dirs: [][]const u8,
20 c_source_flags: [][]const u8,
20 c_source_files: [][]const u8,21 c_source_files: [][]const u8,
21 deps: []u.Dep,22 deps: []u.Dep,
2223
...@@ -52,6 +53,7 @@ pub const ModFile = struct {...@@ -52,6 +53,7 @@ pub const ModFile = struct {
52 .name = name,53 .name = name,
53 .main = main,54 .main = main,
54 .c_include_dirs = try doc.mapping.get_string_array(alloc, "c_include_dirs"),55 .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"),
55 .c_source_files = try doc.mapping.get_string_array(alloc, "c_source_files"),57 .c_source_files = try doc.mapping.get_string_array(alloc, "c_source_files"),
56 .deps = dep_list.items,58 .deps = dep_list.items,
57 };59 };