build: package haul as a macOS .app bundle

Double-clicking the bare binary in Finder opens a Terminal window alongside
the app: Finder has no better idea what to do with a Mach-O executable than
hand it to Terminal.app, and the terminal stays up as long as the process
does. macOS has no counterpart to -H=windowsgui, so the only fix is to ship
an application bundle, which Finder launches directly.

Add `make package-darwin`, which runs a pinned `fyne package --target
darwin` to produce ./haul.app. Its metadata comes from cmd/haul/FyneApp.toml
— the app ID there must stay in step with the one app.NewWithID uses, or
macOS treats the bundle and the running app as separate applications. The
icon is a placeholder; `fyne package` will not run without one.

Note that `fyne package` rewrites FyneApp.toml in place on every run, so the
file is left in that tool's canonical formatting rather than a commented
version it would only strip again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 22:30:22 +10:00
parent b533d35f95
commit a8a60f5860
5 changed files with 87 additions and 4 deletions
+22 -2
View File
@@ -7,7 +7,12 @@ LDFLAGS := -s -w
# prefer that toolchain and fall back to whatever `go` is in PATH elsewhere.
GO ?= $(shell test -x $(HOME)/.local/go/bin/go && echo $(HOME)/.local/go/bin/go || echo go)
.PHONY: build install test vet check run run-xvfb dist clean
# The packaging tool lives outside the Fyne library repo since v2.5. Pinned and
# run through `go run` so no separate install step is needed; override with
# FYNE=/path/to/fyne if you'd rather use an installed copy.
FYNE ?= $(GO) run fyne.io/tools/cmd/fyne@v1.7.2
.PHONY: build install test vet check run run-xvfb dist package-darwin clean
build: ## Build a native binary into ./bin/haul
$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o bin/haul ./cmd/haul
@@ -60,5 +65,20 @@ dist: ## Build the release binary for this host into ./dist
$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o dist/haul-linux-amd64 ./cmd/haul
@echo "built dist/haul-linux-amd64 (see the Makefile for cross-compiling)"
# Finder hands a bare Unix executable to Terminal.app, so double-clicking the
# raw binary opens a terminal window alongside the GUI. Nothing in the code can
# stop that — the fix is to ship a .app bundle instead, which Finder launches
# directly. `fyne package` writes the Info.plist (CFBundlePackageType APPL and
# friends) and converts cmd/haul/Icon.png into Contents/Resources/icon.icns; the
# rest of the metadata comes from cmd/haul/FyneApp.toml.
#
# Run this ON a Mac: it compiles the binary with the host cgo toolchain, and it
# builds for the host architecture, so an Intel Mac gives an amd64 bundle and
# Apple silicon an arm64 one. The .app is unsigned, so first launch needs
# right-click -> Open (or `xattr -dr com.apple.quarantine haul.app`).
package-darwin: ## Package haul.app for macOS (run this on a Mac)
$(FYNE) package --target darwin --src ./cmd/haul --release
@echo "built ./haul.app — drag it into /Applications"
clean: ## Remove build artifacts
rm -rf bin dist
rm -rf bin dist haul.app