Skip to content

Commit

Permalink
feat(nsis): Windows on ARM support (#4228)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeredwolf authored and develar committed Sep 23, 2019
1 parent 8e0a57d commit d738644
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 69 deletions.
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/targets/AppxTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default class AppXTarget extends Target {
return splashScreenTag(userAssets)

case "arch":
return arch === Arch.ia32 ? "x86" : "x64"
return arch === Arch.ia32 ? "x86" : (arch === Arch.arm64 ? "arm64" : "x64")

case "resourceLanguages":
return resourceLanguageTag(asArray(options.languages))
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/targets/MsiTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class MsiTarget extends Target {

// noinspection SpellCheckingInspection
const candleArgs = [
"-arch", arch === Arch.ia32 ? "x86" : (arch === Arch.armv7l ? "arm" : "x64"),
"-arch", arch === Arch.ia32 ? "x86" : (arch === Arch.arm64 ? "arm64" : "x64"),
`-dappDir=${vm.toVmFile(appOutDir)}`,
].concat(this.getCommonWixArgs())
candleArgs.push("project.wxs")
Expand Down
6 changes: 3 additions & 3 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class NsisTarget extends Target {
let estimatedSize = 0
if (this.isPortable && options.useZip) {
for (const [arch, dir] of this.archs.entries()) {
defines[arch === Arch.x64 ? "APP_DIR_64" : "APP_DIR_32"] = dir
defines[arch === Arch.x64 ? "APP_DIR_64" : (arch === Arch.arm64 ? "APP_DIR_ARM64" : "APP_DIR_32")] = dir
}
}
else if (USE_NSIS_BUILT_IN_COMPRESSOR && this.archs.size === 1) {
Expand All @@ -203,7 +203,7 @@ export class NsisTarget extends Target {
await BluebirdPromise.map(this.archs.keys(), async arch => {
const fileInfo = await this.packageHelper.packArch(arch, this)
const file = fileInfo.path
const defineKey = arch === Arch.x64 ? "APP_64" : "APP_32"
const defineKey = arch === Arch.x64 ? "APP_64" : (Arch.arm64 ? "APP_ARM64" : "APP_32")
defines[defineKey] = file
defines[`${defineKey}_NAME`] = path.basename(file)
// nsis expect a hexadecimal string
Expand Down Expand Up @@ -674,4 +674,4 @@ async function createPackageFileInfo(file: string): Promise<PackageFileInfo> {
size: (await stat(file)).size,
sha512: await hashFile(file),
}
}
}
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/targets/nsis/nsisUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const NSIS_PATH = new Lazy(() => {
return Promise.resolve(custom.trim())
}
// noinspection SpellCheckingInspection
return getBinFromUrl("nsis", "3.0.3.2", "tUrlDPQtbjcooNbTrjUzLupttWlATLDNWqK57TVr+gAt3wkaxFxBS3k80AzEFJbmSeOWrUooO72FFOVGXcoxhA==")
return getBinFromUrl("nsis", "3.0.4", "FVF4HClUCsTZ32vYOIC7rTo1qb2pvt2nZwzb86MbKbORukMH0rS3SGBYg/MHmT58PqvRCSlEFai6impEYDYp2Q==")
})

export class AppPackageHelper {
Expand Down Expand Up @@ -100,4 +100,4 @@ export class CopyElevateHelper {
this.copied.set(appOutDir, promise)
return promise
}
}
}
23 changes: 16 additions & 7 deletions packages/app-builder-lib/templates/nsis/common.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,24 @@ Name "${PRODUCT_NAME}"
Quit
${EndIf}

!ifdef APP_64
!ifdef APP_ARM64
${If} ${RunningX64}
SetRegView 64
${Else}
!ifndef APP_32
MessageBox MB_OK|MB_ICONEXCLAMATION "$(x64WinRequired)"
Quit
!endif
${EndIf}
${If} ${IsNativeARM64}
SetRegView 64
${EndIf}
!else
!ifdef APP_64
${If} ${RunningX64}
SetRegView 64
${Else}
!ifndef APP_32
MessageBox MB_OK|MB_ICONEXCLAMATION "$(x64WinRequired)"
Quit
!endif
${EndIf}
!endif
!endif
!macroend

Expand Down Expand Up @@ -89,4 +98,4 @@ Name "${PRODUCT_NAME}"
${endif}

${StdUtils.ExecShellAsUser} $0 "$launchLink" "open" "$startAppArgs"
!macroend
!macroend
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,32 @@
Var /GLOBAL packageArch

!ifdef APP_64
!ifdef APP_ARM64
StrCpy $packageArch "ARM64"
!else
StrCpy $packageArch "64"
!endif

!ifdef APP_32
${if} ${RunningX64}
!insertmacro x64_app_files
!ifdef APP_32
!ifdef APP_ARM64
${if} ${IsNativeARM64} == true
!insertmacro arm64_app_files
${elseif} ${IsNativeAMD64} == true
!insertmacro x64_app_files
${else}
!insertmacro ia32_app_files
!insertmacro ia32_app_files
${endIf}
!else
!insertmacro x64_app_files
${if} ${RunningX64} == true
!ifdef APP_32
!insertmacro x64_app_files
!endif
${else}
!insertmacro ia32_app_files
${endIf}
!endif
!else
!insertmacro ia32_app_files
!insertmacro x64_app_files
!endif

!ifdef COMPRESS
Expand All @@ -32,7 +45,11 @@
!endif

# after decompression
${if} $packageArch == "64"
${if} $packageArch == "ARM64"
!ifmacrodef customFiles_arm64
!insertmacro customFiles_arm64
!endif
${elseif} $packageArch == "64"
!ifmacrodef customFiles_x64
!insertmacro customFiles_x64
!endif
Expand All @@ -43,6 +60,10 @@
${endIf}
!macroend

!macro arm64_app_files
File /oname=$PLUGINSDIR\app-arm64.${COMPRESSION_METHOD} "${APP_ARM64}"
!macroend

!macro x64_app_files
File /oname=$PLUGINSDIR\app-64.${COMPRESSION_METHOD} "${APP_64}"
!macroend
Expand All @@ -54,4 +75,4 @@

!macro extractUsing7za FILE
Nsis7z::Extract "${FILE}"
!macroend
!macroend
71 changes: 43 additions & 28 deletions packages/app-builder-lib/templates/nsis/include/installer.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,26 @@
${if} $packageFile == ""
!ifdef APP_64_NAME
!ifdef APP_32_NAME
${if} ${RunningX64}
StrCpy $packageFile "${APP_64_NAME}"
StrCpy $1 "${APP_64_HASH}"
${else}
StrCpy $packageFile "${APP_32_NAME}"
StrCpy $1 "${APP_32_HASH}"
${endif}
!ifdef APP_ARM64_NAME
${if} ${IsNativeARM64}
StrCpy $packageFile "${APP_ARM64_NAME}"
StrCpy $1 "${APP_ARM64_HASH}"
${elseif} ${IsNativeAMD64}
StrCpy $packageFile "${APP_64_NAME}"
StrCpy $1 "${APP_64_HASH}"
${else}
StrCpy $packageFile "${APP_32_NAME}"
StrCpy $1 "${APP_32_HASH}"
${endif}
!else
${if} ${RunningX64}
StrCpy $packageFile "${APP_64_NAME}"
StrCpy $1 "${APP_64_HASH}"
${else}
StrCpy $packageFile "${APP_32_NAME}"
StrCpy $1 "${APP_32_HASH}"
${endif}
!endif
!else
StrCpy $packageFile "${APP_64_NAME}"
StrCpy $1 "${APP_64_HASH}"
Expand Down Expand Up @@ -88,39 +101,40 @@
!macroend

!macro registryAddInstallInfo
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" InstallLocation "$INSTDIR"
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts "true"
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" InstallLocation "$INSTDIR"
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts "true"
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" ShortcutName "${SHORTCUT_NAME}"
!ifdef MENU_FILENAME
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" MenuDirectory "${MENU_FILENAME}"
!endif

${if} $installMode == "all"
StrCpy $0 "/allusers"
StrCpy $1 ""
${else}
StrCpy $0 "/currentuser"
StrCpy $1 ""
${endIf}
${if} $installMode == "all"
StrCpy $0 "/allusers"
StrCpy $1 ""
${else}
StrCpy $0 "/currentuser"
StrCpy $1 ""
${endIf}

WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" DisplayName "${UNINSTALL_DISPLAY_NAME}$1"
# https://github.com/electron-userland/electron-builder/issues/750
StrCpy $2 "$INSTDIR\${UNINSTALL_FILENAME}"
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" UninstallString '"$2" $0'
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" QuietUninstallString '"$2" $0 /S'

WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "DisplayVersion" "${VERSION}"
!ifdef UNINSTALLER_ICON
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$INSTDIR\uninstallerIcon.ico"
!else
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$appExe,0"
!endif
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "DisplayVersion" "${VERSION}"
!ifdef UNINSTALLER_ICON
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$INSTDIR\uninstallerIcon.ico"
!else
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$appExe,0"
!endif

!ifdef COMPANY_NAME
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "Publisher" "${COMPANY_NAME}"
!endif
WriteRegDWORD SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" NoModify 1
WriteRegDWORD SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" NoRepair 1
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "Publisher" "${COMPANY_NAME}"
!endif

WriteRegDWORD SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" NoModify 1
WriteRegDWORD SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" NoRepair 1

# allow user to define ESTIMATED_SIZE to avoid GetSize call
!ifdef ESTIMATED_SIZE
Expand All @@ -129,7 +143,8 @@
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
!endif
WriteRegDWORD SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "EstimatedSize" "$0"

WriteRegDWORD SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "EstimatedSize" "$0"
!macroend

!macro cleanupOldMenuDirectory
Expand Down Expand Up @@ -209,4 +224,4 @@
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
${endIf}
!endif
!macroend
!macroend
26 changes: 19 additions & 7 deletions packages/app-builder-lib/templates/nsis/include/webPackage.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
!ifdef APP_PACKAGE_URL_IS_INCOMLETE
!ifdef APP_64_NAME
!ifdef APP_32_NAME
${if} ${RunningX64}
StrCpy $packageUrl "$packageUrl/${APP_64_NAME}"
${else}
StrCpy $packageUrl "$packageUrl/${APP_32_NAME}"
${endif}
!ifdef APP_ARM64_NAME
${if} ${IsNativeARM64}
StrCpy $packageUrl "$packageUrl/${APP_ARM64_NAME}"
${elseif} ${IsNativeAMD64}
StrCpy $packageUrl "$packageUrl/${APP_64_NAME}"
${else}
StrCpy $packageUrl "$packageUrl/${APP_32_NAME}"
${endif}
!else
${if} ${IsNativeAMD64} == true
StrCpy $packageUrl "$packageUrl/${APP_64_NAME}"
${else}
StrCpy $packageUrl "$packageUrl/${APP_32_NAME}"
${endif}
!endif
!else
StrCpy $packageUrl "$packageUrl/${APP_64_NAME}"
!endif
Expand All @@ -21,7 +31,9 @@
!endif
!endif

${if} ${RunningX64}
${if} ${IsNativeARM64}
StrCpy $packageArch "ARM64"
${elseif} ${IsNativeAMD64}
StrCpy $packageArch "64"
${else}
StrCpy $packageArch "32"
Expand Down Expand Up @@ -49,4 +61,4 @@
${endif}

StrCpy $packageFile "$PLUGINSDIR\package.7z"
!macroend
!macroend
36 changes: 27 additions & 9 deletions packages/app-builder-lib/templates/nsis/portable.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,35 @@ FunctionEnd
Section
StrCpy $INSTDIR "$TEMP\${UNPACK_DIR_NAME}"
RMDir /r $INSTDIR
SetOutPath $INSTDIR
SetOutPath $INSTDIR

!ifdef APP_DIR_64
!ifdef APP_DIR_32
${if} ${RunningX64}
File /r "${APP_DIR_64}\*.*"
${else}
File /r "${APP_DIR_32}\*.*"
${endIf}
!ifdef APP_DIR_64
!ifdef APP_DIR_ARM64
!ifdef APP_DIR_32
${if} ${IsNativeARM64}
File /r "${APP_DIR_ARM64}\*.*"
${elseif} ${RunningX64}
File /r "${APP_DIR_64}\*.*"
${else}
File /r "${APP_DIR_32}\*.*"
${endIf}
!else
${if} ${IsNativeARM64}
File /r "${APP_DIR_ARM64}\*.*"
${else}
File /r "${APP_DIR_64}\*.*"
{endIf}
!endif
!else
File /r "${APP_DIR_64}\*.*"
!ifdef APP_DIR_32
${if} ${RunningX64}
File /r "${APP_DIR_64}\*.*"
${else}
File /r "${APP_DIR_32}\*.*"
${endIf}
!else
File /r "${APP_DIR_64}\*.*"
!endif
!endif
!else
!ifdef APP_DIR_32
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/testConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as os from "os"
import * as path from "path"

export const ELECTRON_VERSION = "6.0.0"
export const ELECTRON_VERSION = "6.0.8"

export function getElectronCacheDir() {
if (process.platform === "win32") {
Expand Down
4 changes: 2 additions & 2 deletions test/src/windows/webInstallerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test.ifNotCiMac("web installer", app({
}))

test.ifAll.ifNotCiMac("web installer (default github)", app({
targets: Platform.WINDOWS.createTarget(["nsis-web"], Arch.ia32, Arch.x64),
targets: Platform.WINDOWS.createTarget(["nsis-web"], Arch.ia32, Arch.x64, Arch.arm64),
config: {
publish: {
provider: "github",
Expand All @@ -38,4 +38,4 @@ test.ifAll.ifNotCiMac("web installer, safe name on github", app({
artifactName: "${productName}.${ext}",
},
},
}))
}))

0 comments on commit d738644

Please sign in to comment.