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); }