summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-11-25 09:04:56 -0700
committert <t@tjp.lol>2026-11-25 09:41:17 -0700
commitcf346b519a7f2e9b285c32c107b8777b2a13cab0 (patch)
tree776798c526e665211f1548385ba42179bc6b7211 /build.zig
parent2f1d226f6baaafec34b5b3623ba6c9df9aaa003b (diff)
Pin libpantograph, target macOS 13, and add an About dialog
Fetch libpantograph from Codeberg by commit and hash, so a clone can build without a sibling checkout. Always target arm64 macOS 13 instead of the build machine, whose own version would otherwise become the minimum. Copy the version from build.zig.zon into Info.plist, where the standard About panel reads it, and run the app from inside its bundle so that it has one.
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig36
1 files changed, 31 insertions, 5 deletions
diff --git a/build.zig b/build.zig
index 0c52f42..e8ad6b3 100644
--- a/build.zig
+++ b/build.zig
@@ -1,7 +1,18 @@
const std = @import("std");
+/// The one place the version is written. `mise run version` rewrites it.
+const version = @import("build.zig.zon").version;
+
+/// The oldest macOS the app says it runs on, in the binary and in Info.plist.
+const min_macos: std.SemanticVersion = .{ .major = 13, .minor = 0, .patch = 0 };
+
pub fn build(b: *std.Build) void {
- const target = b.standardTargetOptions(.{});
+ // Not the native target: that would require whatever macOS the build machine runs.
+ const target = b.resolveTargetQuery(.{
+ .cpu_arch = .aarch64, // see src/objc.zig
+ .os_tag = .macos,
+ .os_version_min = .{ .semver = min_macos },
+ });
const optimize = b.standardOptimizeOption(.{});
const mod = b.createModule(.{
@@ -10,18 +21,33 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.link_libc = true,
});
+ // Zig looks for the SDK by itself only when the target is native.
+ const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.io, &target.result) orelse
+ @panic("no macOS SDK: run xcode-select --install");
+ mod.addFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "System/Library/Frameworks" }) });
+ mod.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "usr/lib" }) });
mod.linkFramework("AppKit", .{});
mod.addImport("panto", b.dependency("libpantograph", .{ .target = target, .optimize = optimize }).module("panto"));
const exe = b.addExecutable(.{ .name = "write_away", .root_module = mod });
+ // AppKit's own About panel reads the version from Info.plist.
+ var plist: []const u8 = @embedFile("Info.plist");
+ for ([_][2][]const u8{
+ .{ "@VERSION@", version },
+ .{ "@MIN_MACOS@", b.fmt("{f}", .{min_macos}) },
+ }) |sub| plist = std.mem.replaceOwned(u8, b.allocator, plist, sub[0], sub[1]) catch @panic("OOM");
+
// Installed as an app bundle: zig-out/Write_Away.app
const bundle = "Write_Away.app/Contents";
+ const install = b.getInstallStep();
const bin = b.addInstallArtifact(exe, .{ .dest_dir = .{ .override = .{ .custom = bundle ++ "/MacOS" } } });
- b.getInstallStep().dependOn(&bin.step);
- b.getInstallStep().dependOn(&b.addInstallFile(b.path("Info.plist"), bundle ++ "/Info.plist").step);
- b.getInstallStep().dependOn(&b.addInstallFile(b.path("assets/Write_Away.icns"), bundle ++ "/Resources/Write_Away.icns").step);
+ install.dependOn(&bin.step);
+ install.dependOn(&b.addInstallFile(b.addWriteFiles().add("Info.plist", plist), bundle ++ "/Info.plist").step);
+ install.dependOn(&b.addInstallFile(b.path("assets/Write_Away.icns"), bundle ++ "/Resources/Write_Away.icns").step);
- const run = b.addRunArtifact(exe);
+ // From inside the bundle, or the app has no Info.plist, and so no version or icon.
+ const run = b.addSystemCommand(&.{b.getInstallPath(.prefix, bundle ++ "/MacOS/write_away")});
+ run.step.dependOn(install);
if (b.args) |args| run.addArgs(args);
b.step("run", "Run the editor (zig build run -- file.md)").dependOn(&run.step);