manwhere/build.zig
Jeremie Fraeys c1fde4ff77
All checks were successful
Create Release / release (push) Successful in 43s
Simplify build.zig to Zig 0.15 best practices
2026-02-10 20:33:13 -05:00

88 lines
2.5 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Module
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// Executable
const exe = b.addExecutable(.{
.name = "manwhere",
.root_module = exe_mod,
});
b.installArtifact(exe);
// Run step
const run_cmd = b.addRunArtifact(exe);
if (b.args) |args| run_cmd.addArgs(args);
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
// Test step
const unit_tests = b.addTest(.{
.root_module = exe_mod,
});
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
// Check step
const check_exe = b.addExecutable(.{
.name = "check-compile",
.root_module = exe_mod,
});
const check_step = b.step("check", "Check compilation");
check_step.dependOn(&check_exe.step);
// Format step
const fmt_step = b.step("fmt", "Format source code");
const fmt_cmd = b.addFmt(.{
.paths = &.{ "src", "build.zig" },
.check = false,
});
fmt_step.dependOn(&fmt_cmd.step);
// Clean step
const clean_step = b.step("clean", "Remove build artifacts");
const clean_cmd = b.addSystemCommand(&.{
"rm", "-rf", ".zig-cache", "zig-out",
});
clean_step.dependOn(&clean_cmd.step);
// Release step
const release_step = b.step("release", "Build and install to ~/.local/bin");
const release_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = .ReleaseFast,
});
const release_exe = b.addExecutable(.{
.name = "manwhere",
.root_module = release_mod,
});
// Get install path
const home = std.process.getEnvVarOwned(b.allocator, "HOME") catch {
std.debug.print("Error: HOME not set\n", .{});
return;
};
defer b.allocator.free(home);
const bin_path = b.pathJoin(&.{ home, ".local", "bin" });
// Create directory
const mkdir_cmd = b.addSystemCommand(&.{ "mkdir", "-p", bin_path });
// Install the binary
const install_bin = b.addInstallBinFile(release_exe.getEmittedBin(), "manwhere");
install_bin.step.dependOn(&mkdir_cmd.step);
release_step.dependOn(&install_bin.step);
}