From e013bdc9e0a8e94ffc91be5e6a887673f875a5e6 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Thu, 1 Feb 2024 14:52:26 -0500 Subject: [PATCH] Generate MSI for `win-arm64` installer (#20516) --- assets/wix/Product.wxs | 9 +++ assets/wix/bundle.wxs | 9 +++ tools/ci.psm1 | 60 ++++++++++++++++++- tools/packaging/packaging.psm1 | 37 +++++++++--- .../PowerShellPackage.ps1 | 7 +-- .../templates/windows-package-signing.yml | 2 +- .../templates/windows-packaging.yml | 2 +- 7 files changed, 110 insertions(+), 16 deletions(-) diff --git a/assets/wix/Product.wxs b/assets/wix/Product.wxs index 6f34a33849e..b2cb57dbdd2 100644 --- a/assets/wix/Product.wxs +++ b/assets/wix/Product.wxs @@ -20,6 +20,15 @@ + + + + + + + + + diff --git a/assets/wix/bundle.wxs b/assets/wix/bundle.wxs index dc577cb36b0..a2d93b47099 100644 --- a/assets/wix/bundle.wxs +++ b/assets/wix/bundle.wxs @@ -9,6 +9,15 @@ + + + + + + + + + diff --git a/tools/ci.psm1 b/tools/ci.psm1 index 060519d30a6..751b5fd4146 100644 --- a/tools/ci.psm1 +++ b/tools/ci.psm1 @@ -541,9 +541,11 @@ function Invoke-CIFinish } 'win-arm.*' { $runPackageTest = $false - $packageTypes = 'zip', 'zip-pdb', 'msix' + $packageTypes = 'msi', 'zip', 'zip-pdb', 'msix' } } + + Install-WixArmZip $packages = Start-PSPackage -Type $packageTypes -ReleaseTag $preReleaseVersion -SkipReleaseChecks -WindowsRuntime $Runtime foreach ($package in $packages) { @@ -620,6 +622,62 @@ function Invoke-CIFinish } } +function Install-WixArmZip +{ + # cleanup previous install + if((Test-Path "${env:ProgramFiles(x86)}\Arm Support WiX Toolset xcopy")) { + Remove-Item "${env:ProgramFiles(x86)}\Arm Support WiX Toolset xcopy" -Recurse -Force + } + + # This URI is for wix 3.14 which supports generating msi for arm architecures. + $wixUriArmSupport = 'https://aka.ms/ps-wix-3-14-zip' + $zipArmSupport = "$env:TEMP\wixArmSupport.zip" + $targetRoot = "${env:ProgramFiles(x86)}\Arm Support WiX Toolset xcopy" + Invoke-RestMethod -Uri $wixUriArmSupport -OutFile $zipArmSupport + + $binPath = Join-Path -Path $targetRoot -ChildPath 'bin' + Write-Verbose "Expanding $zipArmSupport to $binPath ..." -Verbose + Expand-Archive -Path $zipArmSupport -DestinationPath $binPath -Force + $docExpandPath = Join-Path -Path $binPath -ChildPath 'doc' + $sdkExpandPath = Join-Path -Path $binPath -ChildPath 'sdk' + $docTargetPath = Join-Path -Path $targetRoot -ChildPath 'doc' + $sdkTargetPath = Join-Path -Path $targetRoot -ChildPath 'sdk' + Write-Verbose "Fixing folder structure ..." -Verbose + Move-Item -Path $docExpandPath -Destination $docTargetPath + Move-Item -Path $sdkExpandPath -Destination $sdkTargetPath + Set-Path -Append -Path $binPath + Write-Verbose "Done installing WIX for arm!" +} + +function Set-Path +{ + param + ( + [Parameter(Mandatory)] + [string] + $Path, + + [Parameter(Mandatory)] + [switch] + $Append + ) + + $machinePathString = [System.Environment]::GetEnvironmentVariable('path',[System.EnvironmentVariableTarget]::Machine) + $machinePath = $machinePathString -split ';' + + if($machinePath -inotcontains $path) + { + $newPath = "$machinePathString;$path" + Write-Verbose "Adding $path to path..." -Verbose + [System.Environment]::SetEnvironmentVariable('path',$newPath,[System.EnvironmentVariableTarget]::Machine) + Write-Verbose "Added $path to path." -Verbose + } + else + { + Write-Verbose "$path already in path." -Verbose + } +} + # Bootstrap script for Linux and macOS function Invoke-BootstrapStage { diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index a6575088090..298b9fef35b 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -477,6 +477,12 @@ function Start-PSPackage { $TargetArchitecture = "x86" $r2rArchitecture = "i386" } + elseif ($Runtime -match "-arm64") + { + $TargetArchitecture = "arm64" + $r2rArchitecture = "arm64" + } + Write-Verbose "TargetArchitecture = $TargetArchitecture" -Verbose $Arguments = @{ @@ -3206,12 +3212,23 @@ function Get-NugetSemanticVersion # Get the paths to various WiX tools function Get-WixPath { - $wixToolsetBinPath = "${env:ProgramFiles(x86)}\WiX Toolset *\bin" + [CmdletBinding()] + param ( + [bool] $IsProductArchitectureArm = $false + ) - Write-Verbose "Ensure Wix Toolset is present on the machine @ $wixToolsetBinPath" + $wixToolsetBinPath = $IsProductArchitectureArm ? "${env:ProgramFiles(x86)}\Arm Support WiX Toolset *\bin" : "${env:ProgramFiles(x86)}\WiX Toolset *\bin" + + Write-Verbose -Verbose "Ensure Wix Toolset is present on the machine @ $wixToolsetBinPath" if (-not (Test-Path $wixToolsetBinPath)) { - throw "The latest version of Wix Toolset 3.11 is required to create MSI package. Please install it from https://github.com/wixtoolset/wix3/releases" + if (!$IsProductArchitectureArm) + { + throw "The latest version of Wix Toolset 3.11 is required to create MSI package. Please install it from https://github.com/wixtoolset/wix3/releases" + } + else { + throw "The latest version of Wix Toolset 3.14 is required to create MSI package for arm. Please install it from https://aka.ms/ps-wix-3-14-zip" + } } ## Get the latest if multiple versions exist. @@ -3235,7 +3252,6 @@ function Get-WixPath WixLightExePath = $wixLightExePath WixInsigniaExePath = $wixInsigniaExePath } - } <# @@ -3287,7 +3303,7 @@ function New-MSIPackage # Architecture to use when creating the MSI [Parameter(Mandatory = $true)] - [ValidateSet("x86", "x64")] + [ValidateSet("x86", "x64", "arm64")] [ValidateNotNullOrEmpty()] [string] $ProductTargetArchitecture, @@ -3297,7 +3313,7 @@ function New-MSIPackage [string] $CurrentLocation = (Get-Location) ) - $wixPaths = Get-WixPath + $wixPaths = Get-WixPath -IsProductArchitectureArm ($ProductTargetArchitecture -eq "arm64") $windowsNames = Get-WindowsNames -ProductName $ProductName -ProductNameSuffix $ProductNameSuffix -ProductVersion $ProductVersion $productSemanticVersionWithName = $windowsNames.ProductSemanticVersionWithName @@ -3335,6 +3351,11 @@ function New-MSIPackage $fileArchitecture = 'x86' $ProductProgFilesDir = "ProgramFilesFolder" } + elseif ($ProductTargetArchitecture -eq "arm64") + { + $fileArchitecture = 'arm64' + $ProductProgFilesDir = "ProgramFiles64Folder" + } $wixFragmentPath = Join-Path $env:Temp "Fragment.wxs" @@ -3449,7 +3470,7 @@ function New-ExePackage { # Architecture to use when creating the MSI [Parameter(Mandatory = $true)] - [ValidateSet("x86", "x64")] + [ValidateSet("x86", "x64", "arm64")] [ValidateNotNullOrEmpty()] [string] $ProductTargetArchitecture, @@ -3571,7 +3592,7 @@ function Start-MsiBuild { $outDir = $env:Temp - $wixPaths = Get-WixPath + $wixPaths = Get-WixPath -IsProductArchitectureArm ($ProductTargetArchitecture -eq "arm64") $extensionArgs = @() foreach ($extensionName in $Extension) { diff --git a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 index ae0bc4f2b10..41ec53fa495 100644 --- a/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 +++ b/tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1 @@ -153,11 +153,8 @@ try if (!$Symbols -and $Runtime -notlike 'fxdependent*' -and !$ForMinimalSize) { - if ($Runtime -notmatch 'arm') - { - Write-Verbose "Starting powershell packaging(msi)..." -Verbose - Start-PSPackage @pspackageParams @releaseTagParam - } + Write-Verbose "Starting powershell packaging(msi)..." -Verbose + Start-PSPackage @pspackageParams @releaseTagParam $pspackageParams['Type']='msix' Write-Verbose "Starting powershell packaging(msix)..." -Verbose diff --git a/tools/releaseBuild/azureDevOps/templates/windows-package-signing.yml b/tools/releaseBuild/azureDevOps/templates/windows-package-signing.yml index fdff7af73b1..75153ce0592 100644 --- a/tools/releaseBuild/azureDevOps/templates/windows-package-signing.yml +++ b/tools/releaseBuild/azureDevOps/templates/windows-package-signing.yml @@ -99,7 +99,7 @@ jobs: parameters: architecture: arm64 version: $(version) - msi: no + msi: yes - template: upload.yml parameters: diff --git a/tools/releaseBuild/azureDevOps/templates/windows-packaging.yml b/tools/releaseBuild/azureDevOps/templates/windows-packaging.yml index 4d1273d135d..915db9301ac 100644 --- a/tools/releaseBuild/azureDevOps/templates/windows-packaging.yml +++ b/tools/releaseBuild/azureDevOps/templates/windows-packaging.yml @@ -270,7 +270,7 @@ jobs: displayName: Upload unsigned packages retryCountOnTaskFailure: 2 - - ${{ if and(ne(variables['BuildConfiguration'],'minSize'), in(variables['Architecture'], 'x64', 'x86')) }}: + - ${{ if and(ne(variables['BuildConfiguration'],'minSize'), in(variables['Architecture'], 'x64', 'x86', 'arm64')) }}: - template: EsrpSign.yml@ComplianceRepo parameters: buildOutputPath: $(System.ArtifactsDirectory)\pkgSigned