Skip to content

fix(build): compile native Swift helpers as universal arm64+x86_64 binaries - #638

Open
YuriNachos wants to merge 1 commit into
SuperCmdLabs:mainfrom
YuriNachos:YuriNachos/r3-supercmd
Open

YuriNachos wants to merge 1 commit into
SuperCmdLabs:mainfrom
YuriNachos:YuriNachos/r3-supercmd

Conversation

@YuriNachos

@YuriNachos YuriNachos commented Aug 8, 2026 •

Copy link
Copy Markdown

Problem

The 15 native Swift helper binaries built by scripts/build-native.mjs (get-selected-text, color-picker, screen-ocr, snippet-expander, …) were compiled as single-arch arm64 executables, so on Intel Macs every feature that shells out to one of them fails with bad CPU type in executable (#634). The HyperKey monitor binary that src/main/main.ts compiles at runtime had the same single-arch problem.

Solution

Swift's driver rejects the -arch flag, so the usual "compile once with multiple -arch flags" path does not work for Swift sources. Instead, scripts/build-native.mjs now:

  1. Compiles each helper twice — once targeting arm64-apple-macos11, once targeting x86_64-apple-macos11 (the Swift sources themselves are unchanged; only the deployment target and the second arch slice are added).
  2. Merges the two slices with lipo -create into the final universal (arm64 + x86_64) Mach-O binary.
  3. Cleans up the per-arch intermediate files in a finally, so a failed arch build doesn't leave stale slices behind.

ensureHyperKeyMonitorBinary in src/main/main.ts gets the same slice-and-lipo treatment, with one difference: the host-arch slice is mandatory, while the second slice is best-effort — on a toolchain that cannot cross-compile (e.g. an Intel Mac with only Command Line Tools) it falls back to a working host-arch binary instead of disabling HyperKey.

macos11 (Big Sur) is the deployment floor — the arm64 minimum and a broad floor for Intel Macs.

Testing

  • npm test (node --test scripts/test-*.mjs) — 96 passed, 0 failed, including the new scripts/test-native-universal-arch.mjs, which asserts that each built helper is universal (lipo -archs reports both arm64 and x86_64). The new tests skip on non-macOS hosts, where the native binaries are not built and lipo does not exist.
  • node scripts/build-native.mjs (build:native) — completes clean; the produced helpers are universal.
  • npm run build (full build:main + build:renderer + build:native) — green.

Notes

  • The Node native addon (native_helpers.node) is unaffected — it is already handled by the existing arch-aware build path; only the Swift helper binaries needed the universal treatment.
  • Binaries that come from separate build pipelines (whisper-transcriber, soulver, parakeet) are out of scope here.

@YuriNachos

Copy link
Copy Markdown
Author

I've had this one in mind since #463 sorted esbuild's native binary for both architectures — the Swift helpers were the remaining piece building single-arch, and this PR closes that gap for arm64+x86_64. Is there anything you'd like from my side to move it toward review, such as a verified Intel build or a rebase onto the latest main? Whatever helps, I'm on it. If a smaller change is an easier entry point, #639, #640 and #642 are open as well, and I'd gladly prioritise whichever is most useful.

…naries

The Swift-driver build emitted single-arch arm64 slices, so Intel Macs
hit 'bad CPU type in executable' (SuperCmdLabs#634). Swift's driver rejects -arch,
so compile arm64 and x86_64 as separate slices (targeted to macos11)
and merge them with lipo -create into a universal Mach-O. Per-arch
slices are cleaned up in a finally.
@YuriNachos
YuriNachos force-pushed the YuriNachos/r3-supercmd branch from 47fd5e9 to 3131260 Compare August 13, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant