Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Stop a desktop app build for an architecture other than this Node's

Fei241171b069ec056d
diff --git a/app/README.md b/app/README.md
index a14cc359..1ef59322 100644
--- a/app/README.md
+++ b/app/README.md
@@ -67,7 +67,7 @@ npm run dist # the installer: dist-pack/DeepSeek-Bot-<version>-win-x64
npm run check-packed # starts the packaged app on throwaway folders with the mock model, chats once, closes it
```
-macOS produces one DMG per architecture. Build arm64 on an Apple chip Mac and x64 on an Intel Mac. Do not cross-build: it packages native modules from `node_modules`; a combined build put 12 arm64-only native modules in its x64 app. The app is ad-hoc signed so downloaded copies are sealed. On first open, use System Settings → Privacy & Security → Open Anyway. Do not disable Gatekeeper.
+macOS produces one DMG per architecture. Build arm64 on an Apple chip Mac and x64 on an Intel Mac, or under Rosetta with an x64 Node that also ran `npm ci`. Do not cross-build: it packages native modules from `node_modules`; a combined build put 12 arm64-only native modules in its x64 app. `scripts/before-pack.mjs` stops a build whose architecture is not the one of the Node that runs it. The app is ad-hoc signed so downloaded copies are sealed. On first open, use System Settings → Privacy & Security → Open Anyway. Do not disable Gatekeeper.
`check-packed` takes another executable as its first argument, and a file for a screenshot of the window as its second. It runs an app that lies inside this checkout from a copy in its throwaway folder: from inside the checkout, Node would find a module that the package left out in the checkout's own `node_modules`.
diff --git a/app/electron-builder.yml b/app/electron-builder.yml
index 66e1ef2a..9e18a61b 100644
--- a/app/electron-builder.yml
+++ b/app/electron-builder.yml
@@ -14,6 +14,8 @@ asarUnpack:
# node-pty, sharp and koffi ship prebuilt binaries for each platform. A rebuild would compile
# node-pty from source and needs a C++ toolchain.
npmRebuild: false
+# So the binaries come from npm as it installed them; a build for another architecture stops.
+beforePack: ./scripts/before-pack.mjs
win:
target:
- target: nsis
diff --git a/app/scripts/before-pack.mjs b/app/scripts/before-pack.mjs
new file mode 100644
index 00000000..463eeced
--- /dev/null
+++ b/app/scripts/before-pack.mjs
@@ -0,0 +1,21 @@
+// electron-builder's beforePack hook. The native modules go into the package as npm installed them
+// (npmRebuild: false), so they fit only the architecture of the Node that ran npm. An app built for
+// another architecture would carry them and not start, so such a build stops here.
+import { Arch } from 'electron-builder'
+
+const WHERE = {
+ darwin: { x64: 'on an Intel Mac, or under Rosetta with an x64 Node', arm64: 'on a Mac with Apple silicon' },
+}
+
+/** @returns {string | undefined} why this Node cannot build an app for `target` */
+export function archProblem({ target, platform, host = process.arch }) {
+ if (target === host) return undefined
+ if (target === 'universal') return 'A universal app would need the native modules of both architectures. Build one app per architecture.'
+ const where = WHERE[platform]?.[target] ?? `with an ${target} Node`
+ return `This Node runs on ${host}, so npm installed ${host} native modules, and an ${target} app with them would not start. Install the dependencies and build ${where}.`
+}
+
+export async function beforePack(context) {
+ const problem = archProblem({ target: Arch[context.arch], platform: context.electronPlatformName })
+ if (problem !== undefined) throw new Error(problem)
+}
diff --git a/app/test/before-pack.test.mjs b/app/test/before-pack.test.mjs
new file mode 100644
index 00000000..eb3c0959
--- /dev/null
+++ b/app/test/before-pack.test.mjs
@@ -0,0 +1,25 @@
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+import { test } from 'node:test'
+import { Arch } from 'electron-builder'
+import { archProblem, beforePack } from '../scripts/before-pack.mjs'
+
+test('a build for the architecture of this Node goes on', async () => {
+ assert.equal(archProblem({ target: 'arm64', platform: 'darwin', host: 'arm64' }), undefined)
+ assert.equal(archProblem({ target: 'x64', platform: 'win32', host: 'x64' }), undefined)
+ await beforePack({ arch: Arch[process.arch], electronPlatformName: process.platform })
+})
+
+test('a build for another architecture stops and says where to build it', async () => {
+ assert.equal(archProblem({ target: 'x64', platform: 'darwin', host: 'arm64' }),
+ 'This Node runs on arm64, so npm installed arm64 native modules, and an x64 app with them would not start. Install the dependencies and build on an Intel Mac, or under Rosetta with an x64 Node.')
+ assert.match(archProblem({ target: 'arm64', platform: 'darwin', host: 'x64' }), /build on a Mac with Apple silicon\.$/)
+ assert.match(archProblem({ target: 'x64', platform: 'win32', host: 'arm64' }), /build with an x64 Node\.$/)
+ assert.match(archProblem({ target: 'universal', platform: 'darwin', host: 'arm64' }), /Build one app per architecture\./)
+ const other = process.arch === 'x64' ? 'arm64' : 'x64'
+ await assert.rejects(beforePack({ arch: Arch[other], electronPlatformName: process.platform }), new RegExp(`an ${other} app with them would not start`))
+})
+
+test('electron-builder runs the check before it packs', () => {
+ assert.match(readFileSync(new URL('../electron-builder.yml', import.meta.url), 'utf8'), /^beforePack: \.\/scripts\/before-pack\.mjs$/m)
+})