nice-data/build.zig
torque ad73ea6508
build: update for 0.12.0-dev.2208+4debd4338
I am hoping that by starting to roll over to zig 0.12 now it will be
easier to migrate when the release actually happens. Unfortunately,
the build system API changed fairly significantly and supporting both
0.11 and 0.12-dev is not very interesting.
2024-01-15 22:10:15 -08:00

63 lines
1.7 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const nice = b.addModule("nice", .{
.root_source_file = .{ .path = "src/nice.zig" },
});
const tests = b.addTest(.{
.name = "nice-unit-tests",
.root_source_file = .{ .path = "tests/main.zig" },
.target = target,
.optimize = optimize,
});
tests.root_module.addImport("nice", nice);
const run_main_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&b.addInstallArtifact(tests, .{}).step);
test_step.dependOn(&run_main_tests.step);
add_examples(b, .{
.target = target,
.nice_mod = nice,
});
}
const ExampleOptions = struct {
target: std.Build.ResolvedTarget,
nice_mod: *std.Build.Module,
};
const Example = struct {
name: []const u8,
file: []const u8,
};
const examples = [_]Example{
.{ .name = "parse", .file = "examples/parse.zig" },
.{ .name = "stream", .file = "examples/stream.zig" },
.{ .name = "reify", .file = "examples/reify.zig" },
};
pub fn add_examples(b: *std.Build, options: ExampleOptions) void {
const example_step = b.step("examples", "build examples");
inline for (examples) |example| {
const ex_exe = b.addExecutable(.{
.name = example.name,
.root_source_file = .{ .path = example.file },
.target = options.target,
.optimize = .Debug,
});
ex_exe.root_module.addImport("nice", options.nice_mod);
const install = b.addInstallArtifact(ex_exe, .{});
example_step.dependOn(&install.step);
}
}