From be72707042c4b237e5f9a5c8695e579cc57a5024 Mon Sep 17 00:00:00 2001 From: Aleksey Shakhmatov Date: Thu, 21 May 2026 08:12:45 +0300 Subject: [PATCH] chore: project scaffold and build wiring Initial Zig 0.16 build script wiring the public `zbench` module, the `zbench_build` helper module for downstream `build.zig` files, an internal `test` step, and an `example` step that compiles and runs the bundled benchmark suite. --- .gitignore | 2 ++ build.zig | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ build.zig.zon | 13 +++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100644 build.zig create mode 100644 build.zig.zon diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3389c86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.zig-cache/ +zig-out/ diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..89daf72 --- /dev/null +++ b/build.zig @@ -0,0 +1,48 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + // The public `zbench` module: what dependents @import. + const zbench_module = b.addModule("zbench", .{ + .root_source_file = b.path("src/root.zig"), + .target = target, + .optimize = optimize, + }); + + // The `zbench_build` module: build-time helpers (add_bench_step). + // Dependents @import("zbench_build") from their build.zig. + _ = b.addModule("zbench_build", .{ + .root_source_file = b.path("src/build_helper.zig"), + }); + + // Internal unit tests: `zig build test`. + const tests = b.addTest(.{ + .root_module = b.createModule(.{ + .root_source_file = b.path("src/root.zig"), + .target = target, + .optimize = optimize, + }), + }); + const run_tests = b.addRunArtifact(tests); + const test_step = b.step("test", "Run zbench unit tests"); + test_step.dependOn(&run_tests.step); + + // Convenience: build the bundled example. + const example_exe = b.addExecutable(.{ + .name = "zbench-example", + .root_module = b.createModule(.{ + .root_source_file = b.path("examples/bench/main.zig"), + .target = target, + .optimize = .ReleaseFast, + }), + }); + example_exe.root_module.addImport("zbench", zbench_module); + b.installArtifact(example_exe); + + const run_example = b.addRunArtifact(example_exe); + if (b.args) |args| run_example.addArgs(args); + const example_step = b.step("example", "Run the bundled example benchmarks"); + example_step.dependOn(&run_example.step); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..8fa82fc --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,13 @@ +.{ + .name = .zbench, + .version = "0.1.0", + .fingerprint = 0xbb819b3c1603b711, + .minimum_zig_version = "0.16.0", + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + "examples", + }, + .dependencies = .{}, +}