build.zig improvements

This commit is contained in:
Motiejus Jakštys 2024-10-17 23:06:44 +03:00
parent d123f3ce84
commit 961de327fe

View File

@ -49,17 +49,19 @@ pub fn build(b: *std.Build) void {
const run_unit_tests = b.addRunArtifact(unit_tests); const run_unit_tests = b.addRunArtifact(unit_tests);
if (setcap and sudo == null) { // TODO learn `zig build` and complain only during unit tests.
std.log.warn("non-null setcap and no sudo command probably won't work. Add sudo.", .{});
}
if (setcap) { if (setcap) {
if (sudo == null) {
std.log.warn("non-null setcap and no sudo command probably won't work. Add sudo.", .{});
}
const set_cap_cmd = b.addSystemCommand(if (sudo) |cmd| const set_cap_cmd = b.addSystemCommand(if (sudo) |cmd|
&.{ cmd, "setcap", "cap_net_admin=+ep" } &.{ cmd, "setcap", "cap_net_admin=+ep" }
else else
&.{ "setcap", "cap_net_admin=+ep" }); &.{ "setcap", "cap_net_admin=+ep" });
set_cap_cmd.addArtifactArg(unit_tests); set_cap_cmd.addArtifactArg(unit_tests);
run_unit_tests.step.dependOn(&set_cap_cmd.step); run_unit_tests.step.dependOn(&set_cap_cmd.step);
} else {
std.log.warn("-Dsetcap not set. Unit tests will probably fail.", .{});
} }
// Similar to creating the run step earlier, this exposes a `test` step to // Similar to creating the run step earlier, this exposes a `test` step to