| param( | |
| [string]$DownloadDirectory = '.dependencies', | |
| [switch]$Mingw | |
| ) | |
| $ErrorActionPreference = 'Stop' | |
| $ProgressPreference = 'SilentlyContinue' | |
| $GitVersion = '2.54.0.windows.1' | |
| $MesonVersion = '1.11.0' | |
| $RustVersion = '1.96.0' | |
| New-Item -Path $DownloadDirectory -ItemType Directory -Force | Out-Null | |
| New-Item -Path .git/info -ItemType Directory -Force | Out-Null | |
| if (-not (Test-Path .git/info/exclude)) { | |
| New-Item -Path .git/info/exclude -ItemType File | Out-Null | |
| } | |
| Add-Content -Path .git/info/exclude -Value "/$DownloadDirectory" | |
| function Get-Installer { | |
| param( | |
| [Parameter(Mandatory = $true)][string]$Name, | |
| [Parameter(Mandatory = $true)][string]$Url | |
| ) | |
| $path = Join-Path $DownloadDirectory $Name | |
| if (-not (Test-Path $path)) { | |
| Write-Host "Downloading $Url" | |
| Invoke-WebRequest $Url -OutFile $path -TimeoutSec 300 | |
| } | |
| return $path | |
| } | |
| function Invoke-Installer { | |
| param( | |
| [Parameter(Mandatory = $true)][string]$FilePath, | |
| [Parameter(Mandatory = $true)][string[]]$ArgumentList | |
| ) | |
| Write-Host "Running $FilePath $($ArgumentList -join ' ')" | |
| $process = Start-Process -Wait -PassThru -FilePath $FilePath -ArgumentList $ArgumentList | |
| if ($process.ExitCode -ne 0) { | |
| throw "$FilePath failed with exit code $($process.ExitCode)" | |
| } | |
| } | |
| $rustTarget = if ($Mingw) { 'gnu' } else { 'msvc' } | |
| $rustMsi = Get-Installer "rust-$rustTarget.msi" ( | |
| "https://static.rust-lang.org/dist/" + | |
| "rust-$RustVersion-x86_64-pc-windows-$rustTarget.msi") | |
| Invoke-Installer msiexec.exe @('/i', $rustMsi, 'INSTALLDIR=C:\Rust', | |
| "ADDLOCAL=Rustc,Cargo,Std$(if ($Mingw) { ',Gcc' })", '/quiet', '/norestart') | |
| if ($Mingw) { | |
| return | |
| } | |
| $gitAssetVersion = $GitVersion -replace '\.windows\.\d+$', '' | |
| $gitInstaller = Get-Installer "Git-Installer.exe" ` | |
| "https://github.com/git-for-windows/git/releases/download/v$GitVersion/PortableGit-$gitAssetVersion-64-bit.7z.exe" | |
| Invoke-Installer $gitInstaller @('-y', '-o"C:\Program Files\Git"') | |
| $mesonMsi = Get-Installer "meson.msi" ` | |
| "https://github.com/mesonbuild/meson/releases/download/$MesonVersion/meson-$MesonVersion-64.msi" | |
| Invoke-Installer msiexec.exe @('/i', $mesonMsi, 'INSTALLDIR=C:\Meson', '/quiet', '/norestart') | |
| # Disable Git Credential Manager, which is auto-configured by PortableGit. | |
| # GitLab's runner picks up this Git in its cleanup stage and runs `git | |
| # credential reject`, which hangs in GCM and makes the job time out. | |
| & "C:\Program Files\Git\bin\git.exe" config unset --all --system credential.helper | |
| if ($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne 5) { | |
| throw "Failed to unset credential.helper with exit code $LASTEXITCODE" | |
| } |