mirror of
https://github.com/mikkelam/fast-cli.git
synced 2025-12-18 04:44:05 +00:00
71 lines
2.3 KiB
Zig
71 lines
2.3 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
// library tests
|
|
const library_tests = b.addTest(.{
|
|
.root_source_file = b.path("src/test.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
const run_library_tests = b.addRunArtifact(library_tests);
|
|
|
|
const test_step = b.step("test", "Run all tests");
|
|
test_step.dependOn(&run_library_tests.step);
|
|
|
|
const dep_zli = b.dependency("zli", .{
|
|
.target = target,
|
|
});
|
|
const mod_zli = dep_zli.module("zli");
|
|
|
|
const dep_mvzr = b.dependency("mvzr", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
const mod_mvzr = dep_mvzr.module("mvzr");
|
|
|
|
// Create build options for version info
|
|
const build_options = b.addOptions();
|
|
|
|
// Read version from build.zig.zon at compile time
|
|
const build_zon_content = @embedFile("build.zig.zon");
|
|
const version = blk: {
|
|
// Simple parsing to extract version string
|
|
const start = std.mem.indexOf(u8, build_zon_content, ".version = \"") orelse unreachable;
|
|
const version_start = start + ".version = \"".len;
|
|
const end = std.mem.indexOfPos(u8, build_zon_content, version_start, "\"") orelse unreachable;
|
|
break :blk build_zon_content[version_start..end];
|
|
};
|
|
|
|
build_options.addOption([]const u8, "version", version);
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "fast-cli",
|
|
.root_source_file = b.path("src/main.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.strip = optimize != .Debug,
|
|
});
|
|
|
|
exe.root_module.addImport("zli", mod_zli);
|
|
exe.root_module.addImport("mvzr", mod_mvzr);
|
|
exe.root_module.addImport("build_options", build_options.createModule());
|
|
library_tests.root_module.addImport("mvzr", mod_mvzr);
|
|
|
|
// Link against the static library instead
|
|
|
|
b.installArtifact(exe);
|
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
run_cmd.step.dependOn(b.getInstallStep());
|
|
if (b.args) |args| {
|
|
run_cmd.addArgs(args);
|
|
}
|
|
|
|
const run_step = b.step("run", "Run the app");
|
|
run_step.dependOn(&run_cmd.step);
|
|
|
|
// b.default_step.dependOn(test_step); // Disabled for cross-compilation
|
|
}
|