| author | |
| committer | |
| log | 8e4624ad4051d31d793822cff9a03aad2a675abf |
| tree | c11674aa6229de99ac117df54dce822a90187c6e |
| parent | 76953c858cf2de793a44add7a50a1ae47067a3a7 |
6 files changed, 42 insertions(+), 4 deletions(-)
src/cmd_fetch.zig+6-2| ... | @@ -127,7 +127,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -127,7 +127,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 127 | if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { | 127 | if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { |
| 128 | var mod_from = try u.Module.from(d); | 128 | var mod_from = try u.Module.from(d); |
| 129 | mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; | 129 | mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 130 | try moduledeps.append(mod_from); | 130 | if (mod_from.is_for_this()) try moduledeps.append(mod_from); |
| 131 | } | 131 | } |
| 132 | break :blk; | 132 | break :blk; |
| 133 | }, | 133 | }, |
| ... | @@ -140,8 +140,10 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -140,8 +140,10 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 140 | if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; | 140 | if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; |
| 141 | if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags; | 141 | if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags; |
| 142 | if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; | 142 | if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; |
| 143 | if (d.only_os.len > 0) dd.only_os = d.only_os; | ||
| 144 | if (d.except_os.len > 0) dd.except_os = d.except_os; | ||
| 143 | 145 | ||
| 144 | try moduledeps.append(dd); | 146 | if (dd.is_for_this()) try moduledeps.append(dd); |
| 145 | }, | 147 | }, |
| 146 | } | 148 | } |
| 147 | } | 149 | } |
| ... | @@ -153,6 +155,8 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -153,6 +155,8 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 153 | .c_source_files = m.c_source_files, | 155 | .c_source_files = m.c_source_files, |
| 154 | .deps = moduledeps.items, | 156 | .deps = moduledeps.items, |
| 155 | .clean_path = "", | 157 | .clean_path = "", |
| 158 | .only_os = &[_][]const u8{}, | ||
| 159 | .except_os = &[_][]const u8{}, | ||
| 156 | }; | 160 | }; |
| 157 | } | 161 | } |
| 158 | 162 |
src/common.zig+6-2| ... | @@ -27,7 +27,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -27,7 +27,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 27 | if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { | 27 | if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { |
| 28 | var mod_from = try u.Module.from(d); | 28 | var mod_from = try u.Module.from(d); |
| 29 | mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; | 29 | mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 30 | try moduledeps.append(mod_from); | 30 | if (mod_from.is_for_this()) try moduledeps.append(mod_from); |
| 31 | } | 31 | } |
| 32 | break :blk; | 32 | break :blk; |
| 33 | }, | 33 | }, |
| ... | @@ -40,8 +40,10 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -40,8 +40,10 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 40 | if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; | 40 | if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; |
| 41 | if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags; | 41 | if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags; |
| 42 | if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; | 42 | if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; |
| 43 | if (d.only_os.len > 0) dd.only_os = d.only_os; | ||
| 44 | if (d.except_os.len > 0) dd.except_os = d.except_os; | ||
| 43 | 45 | ||
| 44 | try moduledeps.append(dd); | 46 | if (dd.is_for_this()) try moduledeps.append(dd); |
| 45 | }, | 47 | }, |
| 46 | } | 48 | } |
| 47 | } | 49 | } |
| ... | @@ -53,5 +55,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -53,5 +55,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 53 | .c_source_files = m.c_source_files, | 55 | .c_source_files = m.c_source_files, |
| 54 | .deps = moduledeps.items, | 56 | .deps = moduledeps.items, |
| 55 | .clean_path = "", | 57 | .clean_path = "", |
| 58 | .only_os = &[_][]const u8{}, | ||
| 59 | .except_os = &[_][]const u8{}, | ||
| 56 | }; | 60 | }; |
| 57 | } | 61 | } |
src/util/dep.zig+2| ... | @@ -18,6 +18,8 @@ pub const Dep = struct { | ... | @@ -18,6 +18,8 @@ pub const Dep = struct { |
| 18 | c_include_dirs: [][]const u8, | 18 | c_include_dirs: [][]const u8, |
| 19 | c_source_flags: [][]const u8, | 19 | c_source_flags: [][]const u8, |
| 20 | c_source_files: [][]const u8, | 20 | c_source_files: [][]const u8, |
| 21 | only_os: [][]const u8, | ||
| 22 | except_os: [][]const u8, | ||
| 21 | 23 | ||
| 22 | pub fn clean_path(self: Dep) ![]const u8 { | 24 | pub fn clean_path(self: Dep) ![]const u8 { |
| 23 | var p = self.path; | 25 | var p = self.path; |
src/util/funcs.zig+10| ... | @@ -156,3 +156,13 @@ pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 { | ... | @@ -156,3 +156,13 @@ pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 { |
| 156 | }; | 156 | }; |
| 157 | return result.term.Exited; | 157 | return result.term.Exited; |
| 158 | } | 158 | } |
| 159 | |||
| 160 | pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 { | ||
| 161 | const list = &std.ArrayList([]const u8).init(gpa); | ||
| 162 | for (input) |item| { | ||
| 163 | if (!std.mem.eql(u8, item, search)) { | ||
| 164 | try list.append(item); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | return list.items; | ||
| 168 | } |
src/util/modfile.zig+2| ... | @@ -49,6 +49,8 @@ pub const ModFile = struct { | ... | @@ -49,6 +49,8 @@ pub const ModFile = struct { |
| 49 | .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"), | 49 | .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"), |
| 50 | .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"), | 50 | .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"), |
| 51 | .c_source_files = try item.mapping.get_string_array(alloc, "c_source_files"), | 51 | .c_source_files = try item.mapping.get_string_array(alloc, "c_source_files"), |
| 52 | .only_os = try u.list_remove(try u.split(item.mapping.get_string("only_os"), ","), ""), | ||
| 53 | .except_os = try u.list_remove(try u.split(item.mapping.get_string("except_os"), ","), ""), | ||
| 52 | }); | 54 | }); |
| 53 | } | 55 | } |
| 54 | } | 56 | } |
src/util/module.zig+16| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const gpa = std.heap.c_allocator; | 2 | const gpa = std.heap.c_allocator; |
| 3 | const builtin = @import("builtin"); | ||
| 3 | 4 | ||
| 4 | const u = @import("index.zig"); | 5 | const u = @import("index.zig"); |
| 5 | 6 | ||
| ... | @@ -16,6 +17,8 @@ pub const Module = struct { | ... | @@ -16,6 +17,8 @@ pub const Module = struct { |
| 16 | c_include_dirs: [][]const u8, | 17 | c_include_dirs: [][]const u8, |
| 17 | c_source_flags: [][]const u8, | 18 | c_source_flags: [][]const u8, |
| 18 | c_source_files: [][]const u8, | 19 | c_source_files: [][]const u8, |
| 20 | only_os: [][]const u8, | ||
| 21 | except_os: [][]const u8, | ||
| 19 | 22 | ||
| 20 | deps: []Module, | 23 | deps: []Module, |
| 21 | clean_path: []const u8, | 24 | clean_path: []const u8, |
| ... | @@ -29,6 +32,8 @@ pub const Module = struct { | ... | @@ -29,6 +32,8 @@ pub const Module = struct { |
| 29 | .c_source_files = dep.c_source_files, | 32 | .c_source_files = dep.c_source_files, |
| 30 | .deps = &[_]Module{}, | 33 | .deps = &[_]Module{}, |
| 31 | .clean_path = try dep.clean_path(), | 34 | .clean_path = try dep.clean_path(), |
| 35 | .only_os = dep.only_os, | ||
| 36 | .except_os = dep.except_os, | ||
| 32 | }; | 37 | }; |
| 33 | } | 38 | } |
| 34 | 39 | ||
| ... | @@ -67,4 +72,15 @@ pub const Module = struct { | ... | @@ -67,4 +72,15 @@ pub const Module = struct { |
| 67 | const hex = try std.fmt.allocPrint(gpa, "{x}", .{out}); | 72 | const hex = try std.fmt.allocPrint(gpa, "{x}", .{out}); |
| 68 | return hex; | 73 | return hex; |
| 69 | } | 74 | } |
| 75 | |||
| 76 | pub fn is_for_this(self: Module) bool { | ||
| 77 | const os = @tagName(builtin.os.tag); | ||
| 78 | if (self.only_os.len > 0) { | ||
| 79 | return u.list_contains(self.only_os, os); | ||
| 80 | } | ||
| 81 | if (self.except_os.len > 0) { | ||
| 82 | return !u.list_contains(self.except_os, os); | ||
| 83 | } | ||
| 84 | return true; | ||
| 85 | } | ||
| 70 | }; | 86 | }; |