Skip to content

Commit

Permalink
build: Build with latest master (#8)
Browse files Browse the repository at this point in the history
ziglang/zig#18160 introduces a few breaking
changes to the build APIs.

This handles those differences where relevant,
building with both, 0.11 and the latest master.
  • Loading branch information
abhinav authored Jan 6, 2024
1 parent 12ce636 commit 08c5be1
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ pub fn build(b: *std.Build) void {
"Output directory for coverage data",
) orelse b.pathFromRoot("cover");

_ = b.addModule("txtar", .{
.source_file = .{ .path = "src/txtar.zig" },
});
if (@hasDecl(std.Build, "CreateModuleOptions")) {
// Zig 0.11
_ = b.addModule("txtar", .{
.source_file = .{ .path = "src/txtar.zig" },
});
} else {
// Zig 0.12
_ = b.addModule("txtar", .{
.root_source_file = .{ .path = "src/txtar.zig" },
});
}

const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/txtar.zig" },
Expand All @@ -24,9 +32,15 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Run tests");
const run_unit_tests = b.addRunArtifact(unit_tests);

const RunStep = if (@hasDecl(std, "build") and @hasDecl(std.build, "RunStep"))
std.build.RunStep // Zig 0.11
else
std.Build.Step.Run // Zig 0.12
;

if (cover) {
run_unit_tests.has_side_effects = true;
run_unit_tests.argv.insertSlice(0, &[_]std.build.RunStep.Arg{
run_unit_tests.argv.insertSlice(0, &[_]RunStep.Arg{
.{ .bytes = b.dupe("kcov") },
.{ .bytes = b.fmt("--include-path={s}", .{b.pathFromRoot("src")}) },
.{ .bytes = b.fmt("--strip-path={s}", .{b.pathFromRoot(".")}) },
Expand Down

0 comments on commit 08c5be1

Please sign in to comment.