diff options
| author | t <t@tjp.lol> | 2026-11-25 09:04:56 -0700 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-11-25 09:41:17 -0700 |
| commit | cf346b519a7f2e9b285c32c107b8777b2a13cab0 (patch) | |
| tree | 776798c526e665211f1548385ba42179bc6b7211 | |
| parent | 2f1d226f6baaafec34b5b3623ba6c9df9aaa003b (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-- | .gitignore | 5 | ||||
| -rw-r--r-- | Info.plist | 4 | ||||
| -rw-r--r-- | build.zig | 36 | ||||
| -rw-r--r-- | build.zig.zon | 8 | ||||
| -rw-r--r-- | src/main.zig | 8 |
5 files changed, 52 insertions, 9 deletions
@@ -1,2 +1,7 @@ zig-out/ .zig-cache/ +zig-pkg/ +mise.local.toml +.panto/local/ +AGENTS.local.md +CLAUDE.local.md @@ -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> @@ -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); |
