From 4b6f66fd512c254b5a82220dc77411fe391dd258 Mon Sep 17 00:00:00 2001 From: David Czihak Date: Sat, 9 May 2026 13:01:50 +0200 Subject: Chore: Rework examples for thorough extension testing --- examples/multi-step/build.zig | 96 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 examples/multi-step/build.zig (limited to 'examples/multi-step/build.zig') diff --git a/examples/multi-step/build.zig b/examples/multi-step/build.zig new file mode 100644 index 0000000..f9a2d3d --- /dev/null +++ b/examples/multi-step/build.zig @@ -0,0 +1,96 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const lib_mod = b.addModule("multi_step", .{ + .root_source_file = b.path("src/lib.zig"), + .target = target, + }); + + const exe = b.addExecutable(.{ + .name = "multi-step", + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + .imports = &.{ + .{ .name = "multi_step", .module = lib_mod }, + }, + }), + }); + b.installArtifact(exe); + + // ── Step: run ────────────────────────────────────────────────────────────── + const run_cmd = b.addRunArtifact(exe); + if (b.args) |args| run_cmd.addArgs(args); + const run_step = b.step("run", "Build and run the multi-step demo"); + run_step.dependOn(&run_cmd.step); + + // ── Step: test ───────────────────────────────────────────────────────────── + const lib_tests = b.addTest(.{ .root_module = lib_mod }); + const run_tests = b.addRunArtifact(lib_tests); + const test_step = b.step("test", "Run all unit tests"); + test_step.dependOn(&run_tests.step); + + // ── Step: check-fmt (hyphenated) ─────────────────────────────────────────── + const fmt_check = b.addFmt(.{ + .paths = &.{ "src", "build.zig" }, + .check = true, + }); + const fmt_step = b.step("check-fmt", "Verify source formatting without modifying files"); + fmt_step.dependOn(&fmt_check.step); + + // ── Step: gen-docs (hyphenated) ──────────────────────────────────────────── + const docs = b.addInstallDirectory(.{ + .source_dir = exe.getEmittedDocs(), + .install_dir = .prefix, + .install_subdir = "docs", + }); + const docs_step = b.step("gen-docs", "Generate and install HTML documentation"); + docs_step.dependOn(&docs.step); + + // ── Step: run_server (underscore) ────────────────────────────────────────── + const server_cmd = b.addRunArtifact(exe); + server_cmd.addArg("--server"); + const server_step = b.step("run_server", "Run the executable in server mode"); + server_step.dependOn(&server_cmd.step); + + // ── Step: bench (short name, ReleaseFast) ────────────────────────────────── + const bench_exe = b.addExecutable(.{ + .name = "bench", + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = .ReleaseFast, + .imports = &.{ + .{ .name = "multi_step", .module = lib_mod }, + }, + }), + }); + const bench_cmd = b.addRunArtifact(bench_exe); + bench_cmd.addArg("--bench"); + const bench_step = b.step("bench", "Build and run benchmarks (ReleaseFast)"); + bench_step.dependOn(&bench_cmd.step); + + // ── Step: release-macos (compound hyphenated, cross-compile) ─────────────── + const macos_target = b.resolveTargetQuery(.{ + .cpu_arch = .aarch64, + .os_tag = .macos, + }); + const release_exe = b.addExecutable(.{ + .name = "multi-step", + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = macos_target, + .optimize = .ReleaseSmall, + .imports = &.{ + .{ .name = "multi_step", .module = lib_mod }, + }, + }), + }); + const release_install = b.addInstallArtifact(release_exe, .{}); + const release_step = b.step("release-macos", "Build a ReleaseSmall binary for aarch64-macos"); + release_step.dependOn(&release_install.step); +} -- cgit v1.3