Skip to content

feat(packaging): ship command-line programs beside desktop apps - #2203

Merged
houko merged 1 commit into
nsgo-dev:mainfrom
txchen:feat/companion-executables
Nov 23, 2026
Merged

houko merged 1 commit into
nsgo-dev:mainfrom
txchen:feat/companion-executables

Conversation

@txchen

@txchen txchen commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Why

Builds on #2199, whose Path ownership windows.path reuses; review that first. This branch is stacked on it and will be rebased once it merges. Until then this PR also shows #2199's commit; only the last commit (feat(cli): ship command-line programs beside desktop apps) is new here.

Some desktop apps ship a command-line program next to the GUI, for example a CLI that works on the same data. Today nsgo build can add one only as a resource:

  • On macOS it lands unsigned in Contents/Resources, so notarization rejects the app.
  • On Linux and Windows nothing puts it on PATH.

There is no supported way to ship a signed helper executable and make it callable from a terminal.

What changed

A new top-level commands list in nsgo.yaml. Each entry is a name and a Go main package, which nsgo build builds for each desktop target with:

  • CGO_ENABLED=0 and build.tags;
  • build.ldflags, then an optional per-command ldflags;
  • the app's identity, so core.App() reports the app's version.
commands:
  - name: hello-cli
    package: ./cmd/hello-cli
windows:
  path: true   # optional: put the install folder on the user's Path

Per platform:

  • macOS: Contents/MacOS/<command>, signed before the bundle with identifier <id>.<command>, using the app's ad hoc or sign.identity signature with the hardened runtime and a timestamp when notarizing. It carries none of the app's entitlements. macos_universal joins the two architectures as it does for the app. The Homebrew cask gets a binary stanza per command.
  • Linux: the command sits beside the app in /opt/<slug>. The .deb and Arch packages own a /usr/bin/<command> link, which is removed with the package. The AppImage carries the command but changes nothing on PATH.
  • Windows: <command>.exe beside the app, signed like the app's executable.
    • windows.path: true makes the installer put the install folder on the user's Path, following fix(packaging): remove only the Path folder the Windows installer added #2199's ownership rules, so consoles find the commands.
    • Without windows.path, the commands are still installed but not on PATH.
    • The existing windows.command_line already puts the folder on Path, but it also adds the .com console wrapper for the GUI executable; windows.path exposes the commands without that wrapper.
  • Store packages (Mac App Store, MSIX, Flatpak) leave commands out.
  • Validation: names must be portable file names that clash neither with each other nor with the app's executable, its Linux command, the Windows uninstaller or the AppImage's entry point. A package that is not main fails the build.
  • Dev builds: nsgo dev watches the commands' packages, so editing a command rebuilds the app.

Scope

  • Targets: the nsgo tool (build, signing, Linux packages, NSIS installer, Homebrew cask) for macOS, Linux and Windows.
  • Screenshots: none; nothing visible changes.
  • Follow-up, not in this PR: Prebuilt command executables per target, for commands not written in Go, would need copying and per-format validation. They are left out to keep this change small.

Tradeoffs

  • Nothing changes for apps that don't set commands or windows.path, with one exception: the NSIS script used to exclude every *-setup.exe from the package. It now excludes only its own installer file, so a program named like helper-setup.exe is installed. Package directories are recreated on each build, so no stale installer can be picked up.
  • Documented limitation: a command that an update renames or drops stays in the Windows install folder. The uninstaller removes only files its own version installed, as for any file an app stops shipping.

Blast Radius

Only apps that set commands or windows.path get new files, signatures, links or Path entries. For every Windows installer, the NSIS file exclusion now names the generated setup file exactly instead of *-setup.exe. Store packages and other targets are unaffected.

Verification

  • On macOS:
    • go tool nsgo check, including -target macos,windows,linux;
    • the changelog check and TestSkills;
    • the command, signing, Linux package, NSIS, Windows signing and Homebrew tests in ./cmd/nsgo.
  • New tests in cmd/nsgo/commands_test.go cover:
    • config validation;
    • building commands for Linux, Windows and macOS;
    • rejection of a non-main package, a missing package or a name collision;
    • leaving commands out of store builds;
    • command linker flags, checked by running the built command;
    • macOS signing order, arguments and identifiers, for Developer ID and universal ad hoc signing;
    • Linux package members and links, and the AppDir;
    • the NSIS script with and without windows.path;
    • Windows signing of commands;
    • the Homebrew binary lines.
  • By hand on macOS, a sample app's bundle passed codesign --verify --deep --strict, ad hoc and with a Developer ID, hardened runtime and timestamp.
  • Not run: notarization, real Windows and Linux installs, and installing the Homebrew cask.

Checklist: the title is a Conventional Commit; the docs whose facts change are updated; the change has a changelog.d/ fragment; no new third-party code, assets or dependencies.

@github-actions github-actions Bot added size/XL enhancement New feature or request documentation Improvements or additions to documentation cli and removed enhancement New feature or request labels Nov 23, 2026
@txchen
txchen force-pushed the feat/companion-executables branch from 80d8569 to db2dd1e Compare November 23, 2026 02:24
@github-actions github-actions Bot added the enhancement New feature or request label Nov 23, 2026
@houko

houko commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Reviewed. The commands change looks good. Here is what I checked:

  • Validation covers reserved Windows names, case-insensitive clashes with the executable, the Linux command, Uninstall and AppRun, and non-main packages.
  • Commands are built with the app's tags, build.ldflags (which includes -ldflags from the command line) and identity.
  • On macOS, commands are signed before the bundle in all three paths: ad hoc, universal and sign.identity. They get their own identifier and none of the app's entitlements.
  • The Linux packages own the /usr/bin links.
  • Windows signs the commands, and windows.path reuses fix(packaging): remove only the Path folder the Windows installer added #2199's Path ownership.
  • The NSIS exclusion now names only the generated setup file.

On a local rebase onto main, the full ./cmd/nsgo and ./internal/moduletest suites pass on Linux, and so do go vet ./... and GOOS=windows go vet ./cmd/nsgo. The command, NSIS, Homebrew and signing tests also pass on macOS with makensis and codesign.

It can't be merged yet. The branch still carries #2199's original commit (2421f91), and main already has that change as 8556e95, so GitHub reports the PR as conflicting. git rebase origin/main drops that commit automatically and applies feat(cli): ship command-line programs beside desktop apps cleanly. Please rebase and push, and it's ready to merge.

@txchen
txchen force-pushed the feat/companion-executables branch from db2dd1e to a38483a Compare November 23, 2026 04:05
@txchen

txchen commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Rebased onto main; the rebase dropped the #2199 commit, so the PR is now the single commands commit. go vet (host and GOOS=windows) and the command, NSIS, Homebrew and signing tests pass.

@github-actions github-actions Bot added size/L and removed size/XL labels Nov 23, 2026
@txchen

txchen commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

The failing test and windows jobs are TestX11PointerLock (X11) and TestConsumedAltChordKeepsMenusClosed (Windows menus). Both fail the same way in many unrelated PR runs from the last few hours, for example run 45107909461 (ci-windows-logic-tests) and run 45104839143 (fix/harmony-input-style-1597). The command tests (TestAddCommands, TestAddCommandsRefuses) pass in this run, and this PR changes only build and packaging, so I don't think the failures come from it.

An app that ships a command-line program next to its GUI, such as a CLI working on the same data, could only add it as a resource: unsigned in a macOS app's Resources, where notarization refuses it, and on no PATH.

nsgo.yaml's commands lists such programs, each a Go main package nsgo builds for the target, with the app's linker flags, its identity in core.App and its own ldflags. macOS apps hold them in Contents/MacOS, signed before the bundle as <id>.<name>, ad hoc or with sign.identity, the hardened runtime and a timestamp; universal apps join them as they join the app. Windows and Linux packages hold them beside the executable and Windows signs them as it signs the app. The Debian and Arch packages own a /usr/bin link to each, Homebrew's cask links each with a binary stanza, and windows.path has the NSIS installer put the app's folder on the user's Path, with the ownership windows.command_line has. The installer leaves out its own setup program by name rather than every *-setup.exe, which a command may be. nsgo dev watches the commands' packages. Store packages leave them out.
@txchen

txchen commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main after #2200 merged. The conflicts were in the Linux package comment, docs/architecture/tool.md and the shipping skill reference; each now keeps both the linux.share text from #2200 and the commands text. go vet (host and GOOS=windows), the command, NSIS, Homebrew, signing, Linux, AppImage and Flatpak tests, and the changelog check pass.

@txchen
txchen force-pushed the feat/companion-executables branch from a38483a to dd35924 Compare November 23, 2026 05:49
@houko

houko commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Reviewed. The rebase after #2200 keeps both the linux.share text and the commands text in the Linux package comment, docs/architecture/tool.md and the shipping reference, and the code is what I reviewed before. Rebased onto current main, go vet ./... (Linux, plus GOOS=windows and GOOS=darwin for ./cmd/nsgo) and the command, NSIS, Homebrew, signing, Linux, AppImage and Flatpak tests pass; the full ./cmd/nsgo and ./internal/moduletest suites passed on the same resolution.

@houko
houko merged commit b49264e into nsgo-dev:main Nov 23, 2026
23 of 25 checks passed
@txchen
txchen deleted the feat/companion-executables branch November 23, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli documentation Improvements or additions to documentation enhancement New feature or request size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants