install-dependencies.ps1 2.9 KB

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