diff --git a/package-lock.json b/package-lock.json index bb66bd2..e5d6f3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@next2d/builder", - "version": "0.5.25", + "version": "0.5.26", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@next2d/builder", - "version": "0.5.25", + "version": "0.5.26", "license": "MIT", "bin": { "builder": "dist/index.js" diff --git a/package.json b/package.json index b7947e6..e295e76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@next2d/builder", - "version": "0.5.25", + "version": "0.5.26", "description": "A multiplatform builder for the Next2d Framework. It supports exporting to a variety of platforms, including Steam, macOS, Windows, Linux, iOS, Android, Xbox, Nintendo Switch, and the web (HTML).", "author": "Toshiyuki Ienaga ", "license": "MIT", diff --git a/src/electron-config.ts b/src/electron-config.ts index 45cb2ac..95937ae 100644 --- a/src/electron-config.ts +++ b/src/electron-config.ts @@ -171,12 +171,14 @@ export const readElectronConfig = (root: string): IElectronConfig => { * Electron fuses for a packaged game (names of @electron/fuses FuseV1Options). * ASAR integrity validation exists on macOS and Windows only. */ -export const createElectronFuses = (platform: string, arch: string): { +export const createElectronFuses = (platform: string, arch: string, universalSlice = false): { resetAdHocDarwinSignature: boolean; options: Record; } => ({ // Changing the binary invalidates the ad-hoc signature Apple silicon requires; a real signature replaces it later. - "resetAdHocDarwinSignature": platform === "darwin" && arch === "arm64", + // Not for the slices of a universal build: the deep re-sign adds _CodeSignature files to the arm64 slice only, + // and @electron/universal refuses to merge slices whose files differ. The merged app is signed instead. + "resetAdHocDarwinSignature": platform === "darwin" && arch === "arm64" && !universalSlice, "options": { "RunAsNode": false, "EnableNodeOptionsEnvironmentVariable": false, diff --git a/src/electron.ts b/src/electron.ts index aac7702..8760437 100644 --- a/src/electron.ts +++ b/src/electron.ts @@ -79,7 +79,7 @@ export const buildElectron = async (): Promise => { // from being replaced or bypassed: Electron validates it against the hash the packager embeds in // the executable, loads the app only from it, and ignores the switches that run other code. const lockRuntime = async ({ buildPath, platform, arch }: { buildPath: string; platform: string; arch: string }): Promise => { - const fuses = createElectronFuses(platform, arch); + const fuses = createElectronFuses(platform, arch, target.arch === "universal"); const electron = path.join(buildPath, platform === "darwin" ? "Electron.app" : platform === "win32" ? "electron.exe" : "electron"); await flipFuses(electron, { "version": FuseVersion.V1, @@ -99,6 +99,13 @@ export const buildElectron = async (): Promise => { "prune": false }) as string[]); }, `${os}-${target.arch}`); + // The slices of a universal build skip the ad-hoc re-sign (see createElectronFuses). Without a real + // signature the merged app would carry an invalid one that Apple silicon refuses to launch. + if (target.platform === "darwin" && target.arch === "universal" && !config.macos.sign && process.env.NEXT2D_STEAM_RELEASE !== "1") { + for (const content of outputPaths) { + await run("codesign", ["--sign", "-", "--force", "--deep", path.join(content, `${config.appName}.app`)], root); + } + } if (steam) { for (const content of outputPaths) { recordSteamPackage(content, ctx.platform, target.arch, config, version); diff --git a/tests/integrity.test.ts b/tests/integrity.test.ts index f759453..0474a6b 100644 --- a/tests/integrity.test.ts +++ b/tests/integrity.test.ts @@ -66,6 +66,8 @@ test("packaged Electron runtimes load only the validated ASAR and ignore switche ]) { const fuses = createElectronFuses(platform, arch); assert.equal(fuses.resetAdHocDarwinSignature, adHoc); + // The slices of a universal build are merged first and signed afterwards + assert.equal(createElectronFuses(platform, arch, true).resetAdHocDarwinSignature, false); assert.deepEqual(fuses.options, { RunAsNode: false, EnableNodeOptionsEnvironmentVariable: false,