XD/build.zig
Squibid eb0f31daa7
complete rewrite in zig...
upon release v5.0 I introduced a regression through my caching system in
which I naively thought that the mtime of a directory was updated by
child directories when it actually only updates for child files.

This rewrite introduces a new caching system where instead of relying on
mtime of the index file I simply store the path to, at most, 10
untracked paths and check those before anything else. This results in
slower, but more reliable caching. However due to Zig's ease of use I
was able to bring down the overall use when statically linked to libgit2
so overall XD should be faster \o/.

I also added a visor? (O) to represent an in progress rebase.
2026-02-22 17:33:43 -05:00

67 lines
2.8 KiB
Zig

const std = @import("std");
const pkg = @import("build.zig.zon");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const git = b.option(bool, "git", "Enable git support") orelse true;
const explain = b.option(bool, "explain", "Explain what the emojitcon means") orelse true;
const perf = b.option(bool, "perf", "Monitor performance of functions") orelse false;
const err = b.option(bool, "err", "Print errors") orelse false;
const dynamic = b.option(bool, "dynamic", "Link XD dynamically") orelse false;
const cleanup = b.option(bool, "cleanup", "removes the old XDhash file from your git directories") orelse false;
const options = b.addOptions();
options.addOption(bool, "git", git);
options.addOption(bool, "explain", explain);
options.addOption(bool, "perf", perf);
options.addOption(bool, "err", err);
options.addOption(bool, "dynamic", dynamic);
options.addOption(bool, "cleanup", cleanup);
options.addOption([]const u8, "version", pkg.version);
var mod = b.addModule("XD", .{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const exe = b.addExecutable(.{ .name = "XD", .root_module = mod });
b.installArtifact(exe);
// add our buildtime options as a module called config
exe.root_module.addOptions("config", options);
if (git) {
if (dynamic) {
exe.root_module.linkSystemLibrary("git2", .{});
mod.link_libc = true;
} else {
// not sure if there's an easier way to do this, there's a type in
// the libgit2 bindings build.zig but I'm not sure how to access it
const libgit2_dep = if (optimize == .Debug) b.dependency("libgit2", .{
.target = target,
.optimize = optimize,
.@"enable-ssh" = false,
.@"tls-backend" = .mbedtls, // openssl doesn't work in debug mode
}) else b.dependency("libgit2", .{
.target = target,
.optimize = optimize,
.@"enable-ssh" = false,
.@"tls-backend" = .openssl, // much much faster than mbedtls
});
exe.linkLibrary(libgit2_dep.artifact("git2"));
}
}
const run_step = b.step("run", "Run the app");
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);
const tests = b.addTest(.{ .root_module = mod });
const test_step = b.step("test", "Run tests");
const test_cmd = b.addRunArtifact(tests);
test_step.dependOn(&test_cmd.step);
}