Skip to content

Commit

Permalink
feat(msi): build emulated arm64 MSI installers (#8086)
Browse files Browse the repository at this point in the history
Build x64 MSI installers when targeting the arm64 architecture. This
results in an x64 MSI installer that installs an arm64 version of the
application.

An x64 MSI installer is an improvement because building arm64 MSI
targets errors with:
```
error CNDL0264 : The parameter 'arch' is missing or has an invalid value arm64.
Possible values are x86, x64, or ia64.
```

This is a stopgap until the electron-builder-binaries wix version is upgraded
to a version that supports arm64 which is currently blocked by a number of
breaking changes between 4.0.0.5512.2 and 4.0.1. This upgrade is
discussed in #6077.
  • Loading branch information
Allan-Kerr authored Mar 1, 2024
1 parent 79df542 commit e6f1beb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-dolphins-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": minor
---

feat(msi): build emulated arm64 MSI installers
14 changes: 10 additions & 4 deletions packages/app-builder-lib/src/targets/MsiTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,23 @@ export default class MsiTarget extends Target {

const commonOptions = getEffectiveOptions(this.options, this.packager)

// wix 4.0.0.5512.2 doesn't support the arm64 architecture so default to x64 when building for arm64.
// This will result in an x64 MSI installer that installs an arm64 version of the application. This is a
// stopgap until the electron-builder-binaries wix version is upgraded to a version that supports arm64:
// https://github.com/electron-userland/electron-builder/issues/6077
const wixArch = arch == Arch.arm64 ? Arch.x64 : arch;

Check warning on line 82 in packages/app-builder-lib/src/targets/MsiTarget.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `;`

Check warning on line 82 in packages/app-builder-lib/src/targets/MsiTarget.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `;`

const projectFile = stageDir.getTempFile("project.wxs")
const objectFiles = ["project.wixobj"]
await writeFile(projectFile, await this.writeManifest(appOutDir, arch, commonOptions))
await writeFile(projectFile, await this.writeManifest(appOutDir, wixArch, commonOptions))

await packager.info.callMsiProjectCreated(projectFile)

// noinspection SpellCheckingInspection
const vendorPath = await getBinFromUrl("wix", "4.0.0.5512.2", "/X5poahdCc3199Vt6AP7gluTlT1nxi9cbbHhZhCMEu+ngyP1LiBMn+oZX7QAZVaKeBMc2SjVp7fJqNLqsUnPNQ==")

// noinspection SpellCheckingInspection
const candleArgs = ["-arch", arch === Arch.ia32 ? "x86" : arch === Arch.arm64 ? "arm64" : "x64", `-dappDir=${vm.toVmFile(appOutDir)}`].concat(this.getCommonWixArgs())
const candleArgs = ["-arch", wixArch === Arch.ia32 ? "x86" : "x64", `-dappDir=${vm.toVmFile(appOutDir)}`].concat(this.getCommonWixArgs())
candleArgs.push("project.wxs")
await vm.exec(vm.toVmFile(path.join(vendorPath, "candle.exe")), candleArgs, {
cwd: stageDir.dir,
Expand Down Expand Up @@ -150,7 +156,7 @@ export default class MsiTarget extends Target {
return args
}

protected async writeManifest(appOutDir: string, arch: Arch, commonOptions: FinalCommonWindowsInstallerOptions) {
protected async writeManifest(appOutDir: string, wixArch: Arch, commonOptions: FinalCommonWindowsInstallerOptions) {
const appInfo = this.packager.appInfo
const { files, dirs } = await this.computeFileDeclaration(appOutDir)
const options = this.options
Expand All @@ -160,7 +166,7 @@ export default class MsiTarget extends Target {
isCreateDesktopShortcut: commonOptions.isCreateDesktopShortcut !== DesktopShortcutCreationPolicy.NEVER,
isRunAfterFinish: options.runAfterFinish !== false,
// https://stackoverflow.com/questions/1929038/compilation-error-ice80-the-64bitcomponent-uses-32bitdirectory
programFilesId: arch === Arch.x64 ? "ProgramFiles64Folder" : "ProgramFilesFolder",
programFilesId: wixArch === Arch.x64 ? "ProgramFiles64Folder" : "ProgramFilesFolder",
// wix in the name because special wix format can be used in the name
installationDirectoryWixName: getWindowsInstallationDirName(appInfo, commonOptions.isAssisted || commonOptions.isPerMachine === true),
dirs,
Expand Down

0 comments on commit e6f1beb

Please sign in to comment.