summaryrefslogtreecommitdiff
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
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.
-rw-r--r--.gitignore5
-rw-r--r--Info.plist4
-rw-r--r--build.zig36
-rw-r--r--build.zig.zon8
-rw-r--r--src/main.zig8
5 files changed, 52 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index dca1103..0325bf1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,7 @@
zig-out/
.zig-cache/
+zig-pkg/
+mise.local.toml
+.panto/local/
+AGENTS.local.md
+CLAUDE.local.md
diff --git a/Info.plist b/Info.plist
index 9afe6b2..67b0450 100644
--- a/Info.plist
+++ b/Info.plist
@@ -15,7 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
- <string>0.1.0</string>
+ <string>@VERSION@</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>@MIN_MACOS@</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSPrincipalClass</key>
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);
diff --git a/build.zig.zon b/build.zig.zon
index 1c50060..ae276b1 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -4,8 +4,12 @@
.fingerprint = 0x9ba8e9529a0c4859,
.minimum_zig_version = "0.16.0",
.dependencies = .{
- // The AI features ask their model through libpantograph, checked out beside this repo.
- .libpantograph = .{ .path = "../libpantograph" },
+ // The AI features ask their model through libpantograph. `mise run pin:libpanto` moves
+ // the pin; the `test:local` and `build:local` tasks use the checkout beside this repo.
+ .libpantograph = .{
+ .url = "git+https://codeberg.org/teepark/libpantograph.git#eafae0f611de12140fc4c549615853bb5f4d1318",
+ .hash = "libpantograph-0.0.0-7p05501tTgDTbmahhQB3krK2UICJhWo-R5rc7nLph3Ed",
+ },
},
.paths = .{ "build.zig", "build.zig.zon", "Info.plist", "README.md", "assets", "bin", "src" },
}
diff --git a/src/main.zig b/src/main.zig
index 91d611e..9854bf5 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -2566,6 +2566,8 @@ fn menus(app: id) void {
const cs = Mod.ctrl | Mod.shift;
const m_app = submenu(bar, "Write_Away");
+ item(m_app, "About Write_Away", "orderFrontStandardAboutPanel:", "", 0, null); // Info.plist has the version
+ msg(void, m_app, "addItem:", .{msg(id, objc.class("NSMenuItem"), "separatorItem", .{})});
item(m_app, "Inference…", "inference:", ",", Mod.cmd, ctl);
item(m_app, "Hide Write_Away", "hide:", "h", Mod.cmd, null);
item(m_app, "Quit Write_Away", "terminate:", "q", Mod.cmd, null);
@@ -2933,7 +2935,11 @@ fn selftest() void {
const trim_draft = "We really need this today. Keep my note.";
load(trim_draft);
_ = msg(bool, window, "makeFirstResponder:", .{page});
- const write_menu = msg(id, msg(id, msg(id, msg(id, objc.class("NSApplication"), "sharedApplication", .{}), "mainMenu", .{}), "itemAtIndex:", .{@as(isize, 3)}), "submenu", .{});
+ const shared = msg(id, objc.class("NSApplication"), "sharedApplication", .{});
+ const app_menu = msg(id, msg(id, msg(id, shared, "mainMenu", .{}), "itemAtIndex:", .{@as(isize, 0)}), "submenu", .{});
+ const about = msg(id, app_menu, "itemWithTitle:", .{str("About Write_Away")});
+ t.expect(about != null and msg(bool, shared, "respondsToSelector:", .{msg(SEL, about, "action", .{})}), "the app answers About Write_Away");
+ const write_menu = msg(id, msg(id, msg(id, shared, "mainMenu", .{}), "itemAtIndex:", .{@as(isize, 3)}), "submenu", .{});
const next_item = msg(id, write_menu, "itemWithTitle:", .{str("Lab: Next")});
t.expect(next_item != null and !validateMenuItem(null, null, next_item), "Lab review menu is disabled without a review");
toggleTools(null, null, null);