authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-16 18:49:27 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-16 18:49:27 -08:00
log1993719bd1e866bea7e654367eec773c094812cc
tree66fc5550d4ec06e0ffb9aacefb4a6f4da44c0a37
parentcac021f8392424fa5ef55035eadd4ed4548b9b5d

add being able to specify c source/include locations


3 files changed, 60 insertions(+), 0 deletions(-)

src/cmd_fetch.zig+34
...@@ -30,12 +30,26 @@ pub fn execute(args: [][]u8) !void {...@@ -30,12 +30,26 @@ pub fn execute(args: [][]u8) !void {
30 \\ for (packages) |pkg| {30 \\ for (packages) |pkg| {
31 \\ exe.addPackage(pkg);31 \\ exe.addPackage(pkg);
32 \\ }32 \\ }
33 \\ for (c_inlude_dirs) |dir| {
34 \\ exe.addIncludeDir(dir);
35 \\ }
36 \\ for (c_source_files) |fpath| {
37 \\ exe.addCSourceFile(fpath, &[_][]const u8{});
38 \\ }
33 \\}39 \\}
34 });40 });
35 try w.print("\n", .{});41 try w.print("\n", .{});
36 try w.print("pub const packages = ", .{});42 try w.print("pub const packages = ", .{});
37 try print_deps(w, dir, top_module, 0);43 try print_deps(w, dir, top_module, 0);
38 try w.print(";\n", .{});44 try w.print(";\n", .{});
45 try w.print("\n", .{});
46 try w.print("{}\n", .{"pub const c_inlude_dirs = &[_][]const u8{"});
47 try print_incl_dirs_to(w, top_module);
48 try w.print("{};\n", .{"}"});
49 try w.print("\n", .{});
50 try w.print("{}\n", .{"pub const c_source_files = &[_][]const u8{"});
51 try print_csrc_dirs_to(w, top_module);
52 try w.print("{};\n", .{"}"});
39}53}
4054
41fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {55fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
...@@ -66,6 +80,8 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {...@@ -66,6 +80,8 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
66 return u.Module{80 return u.Module{
67 .name = m.name,81 .name = m.name,
68 .main = m.main,82 .main = m.main,
83 .c_include_dirs = m.c_include_dirs,
84 .c_source_files = m.c_source_files,
69 .deps = moduledeps.items,85 .deps = moduledeps.items,
70 .clean_path = "",86 .clean_path = "",
71 };87 };
...@@ -99,3 +115,21 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) an...@@ -99,3 +115,21 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) an
99 }115 }
100 try w.print("{}", .{try u.concat(&[_][]const u8{r,"}"})});116 try w.print("{}", .{try u.concat(&[_][]const u8{r,"}"})});
101}117}
118
119fn print_incl_dirs_to(w: std.fs.File.Writer, mod: u.Module) anyerror!void {
120 for (mod.c_include_dirs) |it| {
121 try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it});
122 }
123 for (mod.deps) |d| {
124 try print_incl_dirs_to(w, d);
125 }
126}
127
128fn print_csrc_dirs_to(w: std.fs.File.Writer, mod: u.Module) anyerror!void {
129 for (mod.c_source_files) |it| {
130 try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it});
131 }
132 for (mod.deps) |d| {
133 try print_csrc_dirs_to(w, d);
134 }
135}
src/util/modfile.zig+24
...@@ -16,6 +16,8 @@ pub const ModFile = struct {...@@ -16,6 +16,8 @@ pub const ModFile = struct {
16 alloc: *std.mem.Allocator,16 alloc: *std.mem.Allocator,
17 name: []const u8,17 name: []const u8,
18 main: []const u8,18 main: []const u8,
19 c_include_dirs: [][]const u8,
20 c_source_files: [][]const u8,
19 deps: []u.Dep,21 deps: []u.Dep,
2022
21 pub fn init(alloc: *std.mem.Allocator, fpath: []const u8) !Self {23 pub fn init(alloc: *std.mem.Allocator, fpath: []const u8) !Self {
...@@ -29,6 +31,26 @@ pub const ModFile = struct {...@@ -29,6 +31,26 @@ pub const ModFile = struct {
29 const name = doc.mapping.get("name").?.string;31 const name = doc.mapping.get("name").?.string;
30 const main = doc.mapping.get("main").?.string;32 const main = doc.mapping.get("main").?.string;
3133
34 const cinclude_list = &std.ArrayList([]const u8).init(alloc);
35 if (doc.mapping.get("c_include_dirs")) |val| {
36 if (val == .sequence) {
37 for (val.sequence) |item, i| {
38 u.assert(item == .string, "modfile: {}[{}] is not a string", .{"c_include_dirs", i});
39 try cinclude_list.append(item.string);
40 }
41 }
42 }
43
44 const csrc_list = &std.ArrayList([]const u8).init(alloc);
45 if (doc.mapping.get("c_source_files")) |val| {
46 if (val == .sequence) {
47 for (val.sequence) |item, i| {
48 u.assert(item == .string, "modfile: {}[{}] is not a string", .{"c_source_files", i});
49 try csrc_list.append(item.string);
50 }
51 }
52 }
53
32 const dep_list = &std.ArrayList(u.Dep).init(alloc);54 const dep_list = &std.ArrayList(u.Dep).init(alloc);
33 if (doc.mapping.get("dependencies")) |dep_seq| {55 if (doc.mapping.get("dependencies")) |dep_seq| {
34 if (dep_seq == .sequence) {56 if (dep_seq == .sequence) {
...@@ -49,6 +71,8 @@ pub const ModFile = struct {...@@ -49,6 +71,8 @@ pub const ModFile = struct {
49 .alloc = alloc,71 .alloc = alloc,
50 .name = name,72 .name = name,
51 .main = main,73 .main = main,
74 .c_include_dirs = cinclude_list.items,
75 .c_source_files = csrc_list.items,
52 .deps = dep_list.items,76 .deps = dep_list.items,
53 };77 };
54 }78 }
src/util/module.zig+2
...@@ -6,6 +6,8 @@ const std = @import("std");...@@ -6,6 +6,8 @@ const std = @import("std");
6pub const Module = struct {6pub const Module = struct {
7 name: []const u8,7 name: []const u8,
8 main: []const u8,8 main: []const u8,
9 c_include_dirs: [][]const u8,
10 c_source_files: [][]const u8,
911
10 deps: []Module,12 deps: []Module,
11 clean_path: []const u8,13 clean_path: []const u8,