Skip to content

Commit

Permalink
feat(msi): build emulated arm64 MSI installers
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 committed Feb 29, 2024
1 parent 63a0044 commit c3937e2
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
@@ -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
Expand Up @@ -70,17 +70,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;

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))

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 `;`
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 @@ -145,7 +151,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 @@ -155,7 +161,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 c3937e2

Please sign in to comment.