| 1 | # Set up Windows build dependencies. |
| 2 | # |
| 3 | # This script first sees if msys is installed. If so, it just uses it. If not, it tries to bootstrap it with chocolatey or winget. |
| 4 | |
| 5 | #Requires -Version 4.0 |
| 6 | |
| 7 | $ErrorActionPreference = "Stop" |
| 8 | |
| 9 | . "$PSScriptRoot\functions.ps1" |
| 10 | |
| 11 | $msysprefix = Get-MSYS2Prefix |
| 12 | |
| 13 | function Check-FileHash { |
| 14 | $file_path = $args[0] |
| 15 | |
| 16 | Write-Host "Checking SHA256 hash of $file_path" |
| 17 | |
| 18 | $actual_hash = (Get-FileHash -Algorithm SHA256 -Path $file_path).Hash.toLower() |
| 19 | $expected_hash = (Get-Content "$file_path.sha256").split()[0] |
| 20 | |
| 21 | if ($actual_hash -ne $expected_hash) { |
| 22 | Write-Host "SHA256 hash mismatch!" |
| 23 | Write-Host "Expected: $expected_hash" |
| 24 | Write-Host "Actual: $actual_hash" |
| 25 | exit 1 |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | function Install-MSYS2 { |
| 30 | $repo = 'msys2/msys2-installer' |
| 31 | $uri = "https://api.github.com/repos/$repo/releases" |
| 32 | $headers = @{ |
| 33 | 'Accept' = 'application/vnd.github+json' |
| 34 | 'X-GitHub-API-Version' = '2022-11-28' |
| 35 | } |
| 36 | $installer_path = "$env:TEMP\msys2-base.exe" |
| 37 | |
| 38 | if ($env:PROCESSOR_ARCHITECTURE -ne "AMD64") { |
| 39 | Write-Host "We can only install MSYS2 for 64-bit x86 systems, but you appear to have a different processor architecture ($env:PROCESSOR_ARCHITECTURE)." |
| 40 | Write-Host "You will need to install MSYS2 yourself instead." |
| 41 | exit 1 |
| 42 | } |
| 43 | |
| 44 | Write-Host "Determining latest release" |
| 45 | $release_list = Invoke-RestMethod -Uri $uri -Headers $headers -TimeoutSec 30 |
| 46 | |
| 47 | $release = $release_list[0] |
| 48 | $release_name = $release.name |
| 49 | $version = $release.tag_name.Replace('-', '') |
| 50 | $installer_url = "https://github.com/$repo/releases/download/$release_name/msys2-x86_64-$version.exe" |
| 51 | |
| 52 | Write-Host "Fetching $installer_url" |
| 53 | Invoke-WebRequest $installer_url -OutFile $installer_path |
| 54 | Write-Host "Fetching $installer_url.sha256" |
| 55 | Invoke-WebRequest "$installer_url.sha256" -OutFile "$installer_path.sha256" |
| 56 | |
| 57 | Write-Host "Checking file hash" |
| 58 | Check-FileHash $installer_path |
| 59 | |
| 60 | Write-Host "Installing" |
| 61 | & $installer_path in --confirm-command --accept-messages --root C:/msys64 |
| 62 | |
| 63 | return "C:\msys64" |
| 64 | } |
| 65 | |
| 66 | if (-Not ($msysprefix)) { |
| 67 | Write-Host "Could not find MSYS2, attempting to install it" |
| 68 | $msysprefix = Install-MSYS2 |
| 69 | } |
| 70 | |
| 71 | $msysbash = Get-MSYS2Bash "$msysprefix" |
| 72 | $env:CHERE_INVOKING = 'yes' |
| 73 | |
| 74 | & $msysbash -l "$PSScriptRoot\msys2-dependencies.sh" |
| 75 | |
| 76 | if ($LastExitcode -ne 0) { |
| 77 | Write-Host "First update attempt failed. This is expected if the msys-runtime package needed updated, trying again." |
| 78 | |
| 79 | & $msysbash -l "$PSScriptRoot\msys2-dependencies.sh" |
| 80 | |
| 81 | if ($LastExitcode -ne 0) { |
| 82 | exit 1 |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | $wixVersion = "5.0.2" |
| 87 | |
| 88 | Write-Host "Installing WiX toolset" |
| 89 | dotnet tool install -g wix --version $wixVersion |
| 90 | |
| 91 | if ($LastExitcode -ne 0) { |
| 92 | exit 1 |
| 93 | } |
| 94 | |
| 95 | Write-Host "Adding WiX extensions" |
| 96 | |
| 97 | wix extension -g add WixToolset.Util.wixext/$wixVersion |
| 98 | |
| 99 | if ($LastExitcode -ne 0) { |
| 100 | exit 1 |
| 101 | } |
| 102 | |
| 103 | wix extension -g add WixToolset.UI.wixext/$wixVersion |
| 104 | |
| 105 | if ($LastExitcode -ne 0) { |
| 106 | exit 1 |
| 107 | } |