地圖 (Jido) is a lightweight Unix TUI file explorer designed for speed and simplicity.
1const std = @import("std");
2const builtin = @import("builtin");
3
4///Must match the `version` in `build.zig.zon`.
5const version = std.SemanticVersion{ .major = 1, .minor = 4, .patch = 0 };
6
7const targets: []const std.Target.Query = &.{
8 .{ .cpu_arch = .aarch64, .os_tag = .macos },
9 .{ .cpu_arch = .aarch64, .os_tag = .linux },
10 .{ .cpu_arch = .x86_64, .os_tag = .linux },
11 .{ .cpu_arch = .x86_64, .os_tag = .macos },
12};
13
14fn createExe(
15 b: *std.Build,
16 exe_name: []const u8,
17 target: std.Build.ResolvedTarget,
18 optimize: std.builtin.OptimizeMode,
19 build_options: *std.Build.Module,
20) !*std.Build.Step.Compile {
21 const libvaxis = b.dependency("vaxis", .{ .target = target, .optimize = optimize }).module("vaxis");
22 const fuzzig = b.dependency("fuzzig", .{ .target = target, .optimize = optimize }).module("fuzzig");
23 const zeit = b.dependency("zeit", .{ .target = target, .optimize = optimize }).module("zeit");
24 const zuid = b.dependency("zuid", .{ .target = target, .optimize = optimize }).module("zuid");
25
26 const exe = b.addExecutable(.{
27 .name = exe_name,
28 .root_module = b.createModule(.{
29 .root_source_file = b.path("src/main.zig"),
30 .target = target,
31 .optimize = optimize,
32 }),
33 });
34
35 exe.root_module.addImport("options", build_options);
36 exe.root_module.addImport("vaxis", libvaxis);
37 exe.root_module.addImport("fuzzig", fuzzig);
38 exe.root_module.addImport("zeit", zeit);
39 exe.root_module.addImport("zuid", zuid);
40
41 return exe;
42}
43
44pub fn build(b: *std.Build) !void {
45 const target = b.standardTargetOptions(.{});
46 const optimize = b.standardOptimizeOption(.{});
47
48 const build_options = b.addOptions();
49 build_options.step.name = "build options";
50 build_options.addOption(std.SemanticVersion, "version", version);
51 const build_options_module = build_options.createModule();
52
53 // Building targets for release.
54 const build_all = b.option(bool, "all-targets", "Build all targets in ReleaseSafe mode.") orelse false;
55 if (build_all) {
56 try buildTargets(b, build_options_module);
57 return;
58 }
59
60 const exe = try createExe(b, "jido", target, optimize, build_options_module);
61 b.installArtifact(exe);
62
63 const run_cmd = b.addRunArtifact(exe);
64 run_cmd.step.dependOn(b.getInstallStep());
65 if (b.args) |args| {
66 run_cmd.addArgs(args);
67 }
68 const run_step = b.step("run", "Run the app");
69 run_step.dependOn(&run_cmd.step);
70}
71
72fn buildTargets(b: *std.Build, build_options: *std.Build.Module) !void {
73 for (targets) |t| {
74 const target = b.resolveTargetQuery(t);
75
76 const exe = try createExe(b, "jido", target, .ReleaseSafe, build_options);
77 b.installArtifact(exe);
78
79 const target_output = b.addInstallArtifact(exe, .{
80 .dest_dir = .{
81 .override = .{
82 .custom = try t.zigTriple(b.allocator),
83 },
84 },
85 });
86
87 b.getInstallStep().dependOn(&target_output.step);
88 }
89}