Skip to content

Commit 89c87b0

Browse files
template/zig: refactor zig build
1 parent 824b38e commit 89c87b0

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

template/zig/build.zig

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@ pub fn build(b: *std.Build) void {
44
const target = b.standardTargetOptions(.{});
55
const optimize = b.standardOptimizeOption(.{});
66

7-
const exe = b.addExecutable(.{
8-
.name = "zigproject",
9-
.root_source_file = b.path("src/main.zig"),
10-
.target = target,
11-
.optimize = optimize,
12-
});
13-
14-
b.installArtifact(exe);
15-
16-
const run_exe = b.addRunArtifact(exe);
177
const run_step = b.step("run", "Run the application");
18-
run_step.dependOn(&run_exe.step);
19-
20-
const unit_tests = b.addTest(.{
21-
.root_source_file = b.path("src/main.zig"),
22-
.target = target,
23-
.optimize = optimize,
24-
});
8+
{
9+
const exe = b.addExecutable(.{
10+
.name = "zigproject",
11+
.root_module = b.createModule(.{
12+
.root_source_file = b.path("src/main.zig"),
13+
.target = target,
14+
.optimize = optimize,
15+
}),
16+
});
17+
run_step.dependOn(&b.addRunArtifact(exe).step);
18+
}
2519

26-
const run_unit_tests = b.addRunArtifact(unit_tests);
2720
const test_step = b.step("test", "Run unit tests");
28-
test_step.dependOn(&run_unit_tests.step);
21+
{
22+
const unit_test = b.addTest(.{
23+
.root_module = b.createModule(.{
24+
.root_source_file = b.path("src/main.zig"),
25+
.target = target,
26+
.optimize = optimize,
27+
}),
28+
});
29+
test_step.dependOn(&b.addRunArtifact(unit_test).step);
30+
}
2931
}

0 commit comments

Comments
 (0)