From 73f751b42f9b7a9b636d9ae39fc340d6b2890c3b Mon Sep 17 00:00:00 2001 From: cocktailpeanut Date: Tue, 7 Mar 2023 13:31:03 -0500 Subject: [PATCH] fix: cross-platform build for native modules using prebuild The `rebuild()` method has not been passing the platform to the electron-rebuild, which meant, electron-rebuild has been using the `process.platform` no matter what platform you specify, which means no cross-platform build if an app includes native modules that include prebuilt binaries. --- packages/app-builder-lib/src/util/yarn.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/app-builder-lib/src/util/yarn.ts b/packages/app-builder-lib/src/util/yarn.ts index 9ee80189e2d..f15401cebc9 100644 --- a/packages/app-builder-lib/src/util/yarn.ts +++ b/packages/app-builder-lib/src/util/yarn.ts @@ -26,7 +26,7 @@ export async function installOrRebuild(config: Configuration, appDir: string, op } await installDependencies(appDir, effectiveOptions) } else { - await rebuild(appDir, config.buildDependenciesFromSource === true, options.arch) + await rebuild(appDir, config.buildDependenciesFromSource === true, options) } } @@ -149,18 +149,19 @@ export interface RebuildOptions { } /** @internal */ -export async function rebuild(appDir: string, buildFromSource: boolean, arch = process.arch) { - log.info({ appDir, arch }, "executing @electron/rebuild") - const options: electronRebuild.RebuildOptions = { +export async function rebuild(appDir: string, buildFromSource: boolean, options: RebuildOptions) { + log.info({ appDir, arch: options.arch, platform: options.platform }, "executing @electron/rebuild") + const effectiveOptions: electronRebuild.RebuildOptions = { buildPath: appDir, electronVersion: await getElectronVersion(appDir), - arch, + arch: options.arch, + platform: options.platform, force: true, debug: log.isDebugEnabled, projectRootPath: await searchModule.getProjectRootPath(appDir), } if (buildFromSource) { - options.prebuildTagPrefix = "totally-not-a-real-prefix-to-force-rebuild" + effectiveOptions.prebuildTagPrefix = "totally-not-a-real-prefix-to-force-rebuild" } - return electronRebuild.rebuild(options) + return electronRebuild.rebuild(effectiveOptions) }