aboutsummaryrefslogtreecommitdiff
path: root/examples/build-options/build.zig
diff options
context:
space:
mode:
authorDavid Czihak <git@dcz.at>2026-05-09 13:01:50 +0200
committerDavid Czihak <git@dcz.at>2026-05-09 13:01:50 +0200
commit4b6f66fd512c254b5a82220dc77411fe391dd258 (patch)
tree7d77d7966e9ad2e296986ea8cfeb607088028195 /examples/build-options/build.zig
parent64e9c56fc665972fdde5234c4fb2f2a882e237dc (diff)
Chore: Rework examples for thorough extension testing
Diffstat (limited to 'examples/build-options/build.zig')
-rw-r--r--examples/build-options/build.zig43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/build-options/build.zig b/examples/build-options/build.zig
new file mode 100644
index 0000000..5412e8d
--- /dev/null
+++ b/examples/build-options/build.zig
@@ -0,0 +1,43 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+ const target = b.standardTargetOptions(.{});
+ const optimize = b.standardOptimizeOption(.{});
+
+ // Boolean flag: -Dverbose
+ const verbose = b.option(bool, "verbose", "Enable verbose logging") orelse false;
+
+ // Integer option: -Dport=<n>
+ const port = b.option(u16, "port", "TCP port to listen on") orelse 8080;
+
+ // Enum option: -Dbackend=<name>
+ const Backend = enum { memory, sqlite, postgres };
+ const backend = b.option(Backend, "backend", "Storage backend") orelse .memory;
+
+ // Hyphenated key option: -Dmax-conn=<n> (tests USER_OPTION_REGEX with hyphens)
+ const max_conn = b.option(u32, "max-conn", "Maximum simultaneous connections") orelse 128;
+
+ const options = b.addOptions();
+ options.addOption(bool, "verbose", verbose);
+ options.addOption(u16, "port", port);
+ options.addOption(Backend, "backend", backend);
+ options.addOption(u32, "max_conn", max_conn);
+
+ const exe = b.addExecutable(.{
+ .name = "build-options-demo",
+ .root_module = b.createModule(.{
+ .root_source_file = b.path("src/main.zig"),
+ .target = target,
+ .optimize = optimize,
+ .imports = &.{
+ .{ .name = "build_options", .module = options.createModule() },
+ },
+ }),
+ });
+ b.installArtifact(exe);
+
+ const run_cmd = b.addRunArtifact(exe);
+ if (b.args) |args| run_cmd.addArgs(args);
+ const run_step = b.step("run", "Run the build-options demo");
+ run_step.dependOn(&run_cmd.step);
+}