nice-data/build.zig

63 lines
1.7 KiB
Zig
Raw Normal View History

2023-09-13 00:11:45 -07:00
const std = @import("std");
pub fn build(b: *std.Build) void {
2023-09-24 14:45:01 -07:00
const target = b.standardTargetOptions(.{});
2023-12-01 22:35:18 -08:00
const optimize = b.standardOptimizeOption(.{});
2023-09-24 14:45:01 -07:00
2023-09-13 00:11:45 -07:00
const nice = b.addModule("nice", .{
2024-06-18 18:24:19 -07:00
.root_source_file = b.path("src/nice.zig"),
2023-09-13 00:11:45 -07:00
});
2023-09-24 14:45:01 -07:00
2023-12-01 22:35:18 -08:00
const tests = b.addTest(.{
.name = "nice-unit-tests",
2024-06-18 18:24:19 -07:00
.root_source_file = b.path("tests/main.zig"),
2023-12-01 22:35:18 -08:00
.target = target,
.optimize = optimize,
});
tests.root_module.addImport("nice", nice);
2023-12-01 22:35:18 -08:00
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);
2023-09-24 14:45:01 -07:00
add_examples(b, .{
.target = target,
.nice_mod = nice,
});
}
const ExampleOptions = struct {
target: std.Build.ResolvedTarget,
2023-09-24 14:45:01 -07:00
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" },
2023-09-24 14:45:01 -07:00
};
pub fn add_examples(b: *std.Build, options: ExampleOptions) void {
2023-09-24 14:45:01 -07:00
const example_step = b.step("examples", "build examples");
inline for (examples) |example| {
const ex_exe = b.addExecutable(.{
.name = example.name,
2024-06-18 18:24:19 -07:00
.root_source_file = b.path(example.file),
2023-09-24 14:45:01 -07:00
.target = options.target,
.optimize = .Debug,
});
ex_exe.root_module.addImport("nice", options.nice_mod);
2023-09-24 14:45:01 -07:00
const install = b.addInstallArtifact(ex_exe, .{});
example_step.dependOn(&install.step);
}
2023-09-13 00:11:45 -07:00
}