Skip to content

Commit

Permalink
fix: use electron-rebuilder API directly so as to override the platfo…
Browse files Browse the repository at this point in the history
…rm for cross-platform prebuild compilations (#7629)
  • Loading branch information
mmaietta committed Jun 24, 2023
1 parent 98f535e commit 285aa76
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/forty-ways-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
"electron-builder": patch
---

fix: use electron/rebuild Rebuilder directly for cross-platform builds
2 changes: 1 addition & 1 deletion packages/app-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@develar/schema-utils": "~2.6.5",
"@electron/notarize": "^1.2.3",
"@electron/osx-sign": "^1.0.4",
"@electron/rebuild": "^3.2.13",
"@electron/rebuild": "3.2.13",
"@electron/universal": "1.3.4",
"@malept/flatpak-bundler": "^0.4.0",
"@types/fs-extra": "9.0.13",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ export class Packager {
const frameworkInfo = { version: this.framework.version, useCustomDist: true }
const config = this.config
if (config.nodeGypRebuild === true) {
await nodeGypRebuild(frameworkInfo, arch)
await nodeGypRebuild(frameworkInfo, arch, platform)
}

if (config.npmRebuild === false) {
Expand Down
24 changes: 15 additions & 9 deletions packages/app-builder-lib/src/util/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { pathExists } from "fs-extra"
import { homedir } from "os"
import * as path from "path"
import { Configuration } from "../configuration"
import * as electronRebuild from "@electron/rebuild"
import * as electronRebuild from "@electron/rebuild/lib/rebuild"
import * as searchModule from "@electron/rebuild/lib/search-module"
import { EventEmitter } from "events"
import { Platform } from "../core"

export async function installOrRebuild(config: Configuration, appDir: string, options: RebuildOptions, forceInstall = false) {
let isDependenciesInstalled = false
Expand All @@ -24,7 +26,8 @@ export async function installOrRebuild(config: Configuration, appDir: string, op
await installDependencies(appDir, effectiveOptions)
} else {
const arch = archFromString(options.arch || process.arch)
await rebuild(appDir, config.buildDependenciesFromSource === true, options.frameworkInfo, arch)
const platform = Platform.fromString(options.platform || process.platform)
await rebuild(appDir, config.buildDependenciesFromSource === true, options.frameworkInfo, arch, platform)
}
}

Expand Down Expand Up @@ -117,8 +120,8 @@ function installDependencies(appDir: string, options: RebuildOptions): Promise<a
})
}

export async function nodeGypRebuild(frameworkInfo: DesktopFrameworkInfo, arch: Arch) {
return rebuild(process.cwd(), false, frameworkInfo, arch)
export async function nodeGypRebuild(frameworkInfo: DesktopFrameworkInfo, arch: Arch, platform: Platform) {
return rebuild(process.cwd(), false, frameworkInfo, arch, platform)
}

function getPackageToolPath() {
Expand Down Expand Up @@ -146,18 +149,21 @@ export interface RebuildOptions {
}

/** @internal */
export async function rebuild(appDir: string, buildFromSource: boolean, frameworkInfo: DesktopFrameworkInfo, arch: Arch) {
log.info({ arch: Arch[arch], version: frameworkInfo.version, appDir }, "executing @electron/rebuild")
export async function rebuild(appDir: string, buildFromSource: boolean, frameworkInfo: DesktopFrameworkInfo, arch: Arch, platform: Platform) {
log.info({ arch: Arch[arch], platform: platform.name, version: frameworkInfo.version, appDir }, "executing @electron/rebuild")
const rootPath = await searchModule.getProjectRootPath(appDir)
const options: electronRebuild.RebuildOptions = {
const rebuilderOptions: electronRebuild.RebuilderOptions = {
buildPath: appDir,
electronVersion: frameworkInfo.version,
arch: Arch[arch],
projectRootPath: rootPath,
disablePreGypCopy: true,
lifecycle: new EventEmitter(),
}
if (buildFromSource) {
options.prebuildTagPrefix = "totally-not-a-real-prefix-to-force-rebuild"
rebuilderOptions.prebuildTagPrefix = "totally-not-a-real-prefix-to-force-rebuild"
}
return electronRebuild.rebuild(options)
const rebuilder = new electronRebuild.Rebuilder(rebuilderOptions)
rebuilder.platform = platform.nodeName
return rebuilder.rebuild()
}
2 changes: 1 addition & 1 deletion packages/electron-builder/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ async function checkIsOutdated() {
async function rebuildAppNativeCode(args: any) {
const projectDir = process.cwd()
// this script must be used only for electron
return nodeGypRebuild({ version: await getElectronVersion(projectDir), useCustomDist: true }, args.arch)
return nodeGypRebuild({ version: await getElectronVersion(projectDir), useCustomDist: true }, args.arch, args.platform)
}
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 285aa76

Please sign in to comment.