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 downstream consumers of zfin. // Internal code (CLI, TUI) uses file-path imports instead. _ = b.addModule("zfin", .{ .root_source_file = b.path("src/root.zig"), .target = target, .imports = &.{ .{ .name = "srf", .module = srf_mod }, }, }); // Shared imports for the unified module (CLI + TUI + lib in one module). // Only external deps -- internal imports use file paths so that Zig's // test runner can discover tests across the entire source tree. const imports: []const std.Build.Module.Import = &.{ .{ .name = "srf", .module = srf_mod }, .{ .name = "vaxis", .module = vaxis_dep.module("vaxis") }, .{ .name = "z2d", .module = z2d_dep.module("z2d") }, }; // Unified executable (CLI + TUI in one binary) const exe = b.addExecutable(.{ .name = "zfin", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = imports, }), }); b.installArtifact(exe); // Run step: `zig build run -- ` 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: single binary, single module. refAllDeclsRecursive in // main.zig discovers all tests via file imports. const test_step = b.step("test", "Run all tests"); const tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = imports, }) }); test_step.dependOn(&b.addRunArtifact(tests).step); // Docs (still uses the library module for clean public API 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) { var cov = Coverage.init(b); _ = cov.addModule(b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = imports, }), "zfin"); } }