diff --git a/src/cmd_fetch.zig b/src/cmd_fetch.zig index bac4a09ea5485ef7a47cbda4e98bdbc9a9760737..03b96181d33ec647c768f29a94a92b4e415a4f71 100644 --- a/src/cmd_fetch.zig +++ b/src/cmd_fetch.zig @@ -127,7 +127,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { var mod_from = try u.Module.from(d); mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; - try moduledeps.append(mod_from); + if (mod_from.is_for_this()) try moduledeps.append(mod_from); } break :blk; }, @@ -140,8 +140,10 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags; if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; + if (d.only_os.len > 0) dd.only_os = d.only_os; + if (d.except_os.len > 0) dd.except_os = d.except_os; - try moduledeps.append(dd); + if (dd.is_for_this()) try moduledeps.append(dd); }, } } @@ -153,6 +155,8 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { .c_source_files = m.c_source_files, .deps = moduledeps.items, .clean_path = "", + .only_os = &[_][]const u8{}, + .except_os = &[_][]const u8{}, }; } diff --git a/src/common.zig b/src/common.zig index d2f8b0514cb699640db73645293bc494447474b0..681a64a7c33915dfb99e53e9d0fb381a5b505928 100644 --- a/src/common.zig +++ b/src/common.zig @@ -27,7 +27,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { var mod_from = try u.Module.from(d); mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; - try moduledeps.append(mod_from); + if (mod_from.is_for_this()) try moduledeps.append(mod_from); } break :blk; }, @@ -40,8 +40,10 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags; if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; + if (d.only_os.len > 0) dd.only_os = d.only_os; + if (d.except_os.len > 0) dd.except_os = d.except_os; - try moduledeps.append(dd); + if (dd.is_for_this()) try moduledeps.append(dd); }, } } @@ -53,5 +55,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { .c_source_files = m.c_source_files, .deps = moduledeps.items, .clean_path = "", + .only_os = &[_][]const u8{}, + .except_os = &[_][]const u8{}, }; } diff --git a/src/util/dep.zig b/src/util/dep.zig index 3ef78a8808ad7d63edb83c3d88eb9afa1aaf8fd1..dd68a070abae62f59c47700f9d54e920cc8b644f 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -18,6 +18,8 @@ pub const Dep = struct { c_include_dirs: [][]const u8, c_source_flags: [][]const u8, c_source_files: [][]const u8, + only_os: [][]const u8, + except_os: [][]const u8, pub fn clean_path(self: Dep) ![]const u8 { var p = self.path; diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 5d47afade8e229f04349bdda2c4c954cdb3e2a6b..bdc0706d8e0cb755ee503048c172a5f3972a93bc 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -156,3 +156,13 @@ pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 { }; return result.term.Exited; } + +pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 { + const list = &std.ArrayList([]const u8).init(gpa); + for (input) |item| { + if (!std.mem.eql(u8, item, search)) { + try list.append(item); + } + } + return list.items; +} diff --git a/src/util/modfile.zig b/src/util/modfile.zig index 31511056a6333535d391e2680233d71fa39f2d47..62ab2cbc45154cfab8085dba230c1dc89d27c2a6 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -49,6 +49,8 @@ pub const ModFile = struct { .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"), .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"), .c_source_files = try item.mapping.get_string_array(alloc, "c_source_files"), + .only_os = try u.list_remove(try u.split(item.mapping.get_string("only_os"), ","), ""), + .except_os = try u.list_remove(try u.split(item.mapping.get_string("except_os"), ","), ""), }); } } diff --git a/src/util/module.zig b/src/util/module.zig index 29bb07286155968f0f1ab7b85b860426bb45a704..05b6dd0760fe978c53098a7dc749d6dd6fb96789 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -1,5 +1,6 @@ const std = @import("std"); const gpa = std.heap.c_allocator; +const builtin = @import("builtin"); const u = @import("index.zig"); @@ -16,6 +17,8 @@ pub const Module = struct { c_include_dirs: [][]const u8, c_source_flags: [][]const u8, c_source_files: [][]const u8, + only_os: [][]const u8, + except_os: [][]const u8, deps: []Module, clean_path: []const u8, @@ -29,6 +32,8 @@ pub const Module = struct { .c_source_files = dep.c_source_files, .deps = &[_]Module{}, .clean_path = try dep.clean_path(), + .only_os = dep.only_os, + .except_os = dep.except_os, }; } @@ -67,4 +72,15 @@ pub const Module = struct { const hex = try std.fmt.allocPrint(gpa, "{x}", .{out}); return hex; } + + pub fn is_for_this(self: Module) bool { + const os = @tagName(builtin.os.tag); + if (self.only_os.len > 0) { + return u.list_contains(self.only_os, os); + } + if (self.except_os.len > 0) { + return !u.list_contains(self.except_os, os); + } + return true; + } };