zfin/build.zig

135 lines
4.2 KiB
Zig

const std = @import("std");
const Coverage = @import("build/Coverage.zig");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// External dependencies
const srf_dep = b.dependency("srf", .{
.target = target,
.optimize = optimize,
});
const vaxis_dep = b.dependency("vaxis", .{
.target = target,
.optimize = optimize,
});
const z2d_dep = b.dependency("z2d", .{
.target = target,
.optimize = optimize,
});
const srf_mod = srf_dep.module("srf");
// Library module -- the public API for consumers of zfin
const mod = b.addModule("zfin", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.imports = &.{
.{ .name = "srf", .module = srf_mod },
},
});
// Shared imports for TUI and CLI modules
const tui_imports: []const std.Build.Module.Import = &.{
.{ .name = "zfin", .module = mod },
.{ .name = "srf", .module = srf_mod },
.{ .name = "vaxis", .module = vaxis_dep.module("vaxis") },
.{ .name = "z2d", .module = z2d_dep.module("z2d") },
};
const tui_mod = b.addModule("tui", .{
.root_source_file = b.path("src/tui/main.zig"),
.target = target,
.imports = tui_imports,
});
const cli_imports: []const std.Build.Module.Import = &.{
.{ .name = "zfin", .module = mod },
.{ .name = "srf", .module = srf_mod },
.{ .name = "tui", .module = tui_mod },
};
// Unified executable (CLI + TUI in one binary)
const exe = b.addExecutable(.{
.name = "zfin",
.root_module = b.createModule(.{
.root_source_file = b.path("src/cli/main.zig"),
.target = target,
.optimize = optimize,
.imports = cli_imports,
}),
});
b.installArtifact(exe);
// Run step: `zig build run -- <args>`
const run_step = b.step("run", "Run the zfin CLI");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
// Tests: Zig test discovery doesn't cross module boundaries, so each
// module (lib, TUI, CLI) needs its own test target.
const test_step = b.step("test", "Run all tests");
const mod_tests = b.addTest(.{ .root_module = mod });
test_step.dependOn(&b.addRunArtifact(mod_tests).step);
const tui_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/tui/main.zig"),
.target = target,
.optimize = optimize,
.imports = tui_imports,
}) });
test_step.dependOn(&b.addRunArtifact(tui_tests).step);
const cli_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/cli/main.zig"),
.target = target,
.optimize = optimize,
.imports = cli_imports,
}) });
test_step.dependOn(&b.addRunArtifact(cli_tests).step);
// Docs
const lib = b.addLibrary(.{
.name = "zfin",
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "srf", .module = srf_mod },
},
}),
});
const docs_step = b.step("docs", "Generate documentation");
docs_step.dependOn(&b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
}).step);
// Coverage: `zig build coverage` (uses kcov, Linux x86_64/aarch64 only)
{
const cov = Coverage.init(b);
_ = cov.addModule(mod, "zfin-lib");
_ = cov.addModule(b.createModule(.{
.root_source_file = b.path("src/tui/main.zig"),
.target = target,
.optimize = optimize,
.imports = tui_imports,
}), "zfin-tui");
_ = cov.addModule(b.createModule(.{
.root_source_file = b.path("src/cli/main.zig"),
.target = target,
.optimize = optimize,
.imports = cli_imports,
}), "zfin-cli");
}
}