62 lines
2.2 KiB
PowerShell
62 lines
2.2 KiB
PowerShell
param()
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$repositoryRoot = Split-Path -Parent $PSScriptRoot
|
|
$runtime = [System.Runtime.InteropServices.RuntimeInformation]
|
|
$runningWindows = $runtime::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)
|
|
$runningLinux = $runtime::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Linux)
|
|
|
|
if ($runtime::OSArchitecture -ne [System.Runtime.InteropServices.Architecture]::X64) {
|
|
throw "protoc bootstrap supports x64 only"
|
|
}
|
|
|
|
if ($runningWindows) {
|
|
$asset = "protoc-35.0-win64.zip"
|
|
$expectedHash = "d1cede9e308cc3eb072392af1c02ccae4bdd3d2f374ec2970dbd8cdfdaa91363"
|
|
$executableName = "protoc.exe"
|
|
}
|
|
elseif ($runningLinux) {
|
|
$asset = "protoc-35.0-linux-x86_64.zip"
|
|
$expectedHash = "a45cda0989c17dd950db55f6fbe1e5814c50fda08e87aa422980ac1f89dddbbc"
|
|
$executableName = "protoc"
|
|
}
|
|
else {
|
|
throw "protoc bootstrap supports Windows x64 and Linux x64 only"
|
|
}
|
|
|
|
$cacheDirectory = Join-Path $repositoryRoot ".tmp-proto/downloads"
|
|
$installationDirectory = Join-Path $repositoryRoot ".tmp-proto/protoc-35.0"
|
|
$archivePath = Join-Path $cacheDirectory $asset
|
|
$downloadURL = "https://github.com/protocolbuffers/protobuf/releases/download/v35.0/$asset"
|
|
New-Item -ItemType Directory -Force -Path $cacheDirectory | Out-Null
|
|
|
|
$needsDownload = -not (Test-Path -LiteralPath $archivePath)
|
|
if (-not $needsDownload) {
|
|
$actualHash = (Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
$needsDownload = $actualHash -ne $expectedHash
|
|
}
|
|
if ($needsDownload) {
|
|
Invoke-WebRequest -Uri $downloadURL -OutFile $archivePath
|
|
}
|
|
|
|
$actualHash = (Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
if ($actualHash -ne $expectedHash) {
|
|
throw "protoc archive SHA-256 mismatch"
|
|
}
|
|
|
|
New-Item -ItemType Directory -Force -Path $installationDirectory | Out-Null
|
|
Expand-Archive -LiteralPath $archivePath -DestinationPath $installationDirectory -Force
|
|
|
|
$protocPath = Join-Path $installationDirectory "bin/$executableName"
|
|
if (-not (Test-Path -LiteralPath $protocPath)) {
|
|
throw "protoc executable was not extracted"
|
|
}
|
|
|
|
$version = (& $protocPath --version).Trim()
|
|
if ($version -ne "libprotoc 35.0") {
|
|
throw "protoc version mismatch: $version"
|
|
}
|
|
|
|
(Resolve-Path -LiteralPath $protocPath).Path
|