zfin/build.zig

109 lines
3.5 KiB
Zig

const std = @import("std");
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,
});
// 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_dep.module("srf") },
},
});
// TUI module (imported by the unified binary)
const tui_mod = b.addModule("tui", .{
.root_source_file = b.path("src/tui/main.zig"),
.target = target,
.imports = &.{
.{ .name = "zfin", .module = mod },
.{ .name = "srf", .module = srf_dep.module("srf") },
.{ .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/cli/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zfin", .module = mod },
.{ .name = "srf", .module = srf_dep.module("srf") },
.{ .name = "tui", .module = tui_mod },
},
}),
});
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
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 exe_tests = b.addTest(.{ .root_module = exe.root_module });
test_step.dependOn(&b.addRunArtifact(exe_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 = &.{
.{ .name = "zfin", .module = mod },
.{ .name = "srf", .module = srf_dep.module("srf") },
.{ .name = "vaxis", .module = vaxis_dep.module("vaxis") },
.{ .name = "z2d", .module = z2d_dep.module("z2d") },
},
}) });
test_step.dependOn(&b.addRunArtifact(tui_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_dep.module("srf") },
},
}),
});
const docs_step = b.step("docs", "Generate documentation");
docs_step.dependOn(&b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
}).step);
}