build: Add "zig build examples" command to build all examples

This commit is contained in:
2026-05-23 17:28:28 +02:00
parent fe0f3c671d
commit d2ec7d68be
+16 -1
View File
@@ -10,6 +10,8 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});
const examples_step = b.step("examples", "Build all examples");
const exe = b.addExecutable(.{
.name = "example",
.root_module = b.createModule(.{
@@ -19,7 +21,8 @@ pub fn build(b: *std.Build) void {
}),
});
exe.root_module.addImport("zigmulator", zigmulator);
b.installArtifact(exe);
const install_exe = b.addInstallArtifact(exe, .{});
examples_step.dependOn(&install_exe.step);
const run_cmd = b.addRunArtifact(exe);
if (b.args) |args| {
@@ -28,4 +31,16 @@ pub fn build(b: *std.Build) void {
const run_step = b.step("run", "Run the example");
run_step.dependOn(&run_cmd.step);
const open_file_exe = b.addExecutable(.{
.name = "open_file",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/open_file.zig"),
.target = target,
.optimize = optimize,
}),
});
open_file_exe.root_module.addImport("zigmulator", zigmulator);
const install_open_file_exe = b.addInstallArtifact(open_file_exe, .{});
examples_step.dependOn(&install_open_file_exe.step);
}