112 lines
6.0 KiB
PowerShell
112 lines
6.0 KiB
PowerShell
param(
|
|
[switch]$SkipCmake,
|
|
[switch]$SkipSources,
|
|
[switch]$OnlyFfmpeg
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
. (Join-Path $PSScriptRoot "native_dep_versions.ps1")
|
|
|
|
New-Item -ItemType Directory -Force $SourceRoot, $BuildRoot, $InstallRoot, $ToolsRoot | Out-Null
|
|
|
|
if (-not (Test-Path -LiteralPath (Join-Path $NasmRoot "nasm.exe"))) {
|
|
$nasmArchiveName = "nasm-$NasmVersion-win64.zip"
|
|
$nasmArchivePath = Join-Path $ToolsRoot $nasmArchiveName
|
|
if (-not (Test-Path -LiteralPath $nasmArchivePath)) {
|
|
& curl.exe -fL --retry 5 --connect-timeout 20 `
|
|
-o $nasmArchivePath `
|
|
"https://www.nasm.us/pub/nasm/releasebuilds/$NasmVersion/win64/$nasmArchiveName"
|
|
if ($LASTEXITCODE -ne 0) { throw "NASM download failed" }
|
|
}
|
|
tar.exe -xf $nasmArchivePath -C $ToolsRoot
|
|
if ($LASTEXITCODE -ne 0 -or
|
|
-not (Test-Path -LiteralPath (Join-Path $NasmRoot "nasm.exe"))) {
|
|
throw "NASM extraction failed: $nasmArchivePath"
|
|
}
|
|
}
|
|
|
|
if (-not $OnlyFfmpeg -and -not $SkipCmake -and
|
|
-not (Test-Path -LiteralPath (Join-Path $CmakeRoot "bin\cmake.exe"))) {
|
|
$archiveName = "cmake-$CmakeVersion-windows-x86_64.zip"
|
|
$archivePath = Join-Path $ToolsRoot $archiveName
|
|
$hashListPath = Join-Path $ToolsRoot "cmake-$CmakeVersion-SHA-256.txt"
|
|
$releaseBase = "https://cmake.org/files/v3.24"
|
|
|
|
& curl.exe -fL --retry 3 -o $archivePath "$releaseBase/$archiveName"
|
|
if ($LASTEXITCODE -ne 0) { throw "CMake download failed" }
|
|
& curl.exe -fL --retry 3 -o $hashListPath "$releaseBase/cmake-$CmakeVersion-SHA-256.txt"
|
|
if ($LASTEXITCODE -ne 0) { throw "CMake checksum download failed" }
|
|
|
|
$hashLine = Select-String -LiteralPath $hashListPath -Pattern ([regex]::Escape($archiveName)) | Select-Object -First 1
|
|
if (-not $hashLine) { throw "CMake checksum entry not found" }
|
|
$expectedHash = ($hashLine.Line -split '\s+')[0].ToUpperInvariant()
|
|
$actualHash = (Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash
|
|
if ($actualHash -ne $expectedHash) { throw "CMake archive checksum mismatch" }
|
|
|
|
tar.exe -xf $archivePath -C $ToolsRoot
|
|
if ($LASTEXITCODE -ne 0) { throw "CMake extraction failed" }
|
|
}
|
|
|
|
function Install-GitHubArchive(
|
|
[string]$Repository,
|
|
[string]$Revision,
|
|
[string]$Destination,
|
|
[string]$Marker
|
|
) {
|
|
if (Test-Path -LiteralPath (Join-Path $Destination $Marker)) { return }
|
|
|
|
$cacheRoot = Join-Path $ToolsRoot "archive-cache"
|
|
New-Item -ItemType Directory -Force $cacheRoot | Out-Null
|
|
$safeName = ($Repository.Replace("/", "-") + "-" + $Revision).Replace("/", "-")
|
|
$archivePath = Join-Path $cacheRoot "$safeName.zip"
|
|
if (-not (Test-Path -LiteralPath $archivePath)) {
|
|
& curl.exe -fL --retry 5 --connect-timeout 20 `
|
|
-o $archivePath "https://codeload.github.com/$Repository/zip/$Revision"
|
|
if ($LASTEXITCODE -ne 0) { throw "Archive download failed: $Repository@$Revision" }
|
|
}
|
|
|
|
$resolvedSourceRoot = [System.IO.Path]::GetFullPath($SourceRoot)
|
|
$resolvedDestination = [System.IO.Path]::GetFullPath($Destination)
|
|
if (-not $resolvedDestination.StartsWith($resolvedSourceRoot, [System.StringComparison]::OrdinalIgnoreCase)) {
|
|
throw "Refusing to replace a path outside dependency sources: $Destination"
|
|
}
|
|
if (Test-Path -LiteralPath $Destination) { Remove-Item -LiteralPath $Destination -Recurse -Force }
|
|
New-Item -ItemType Directory -Force $Destination | Out-Null
|
|
tar.exe -xf $archivePath -C $Destination --strip-components=1
|
|
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath (Join-Path $Destination $Marker))) {
|
|
throw "Archive extraction failed: $archivePath"
|
|
}
|
|
}
|
|
|
|
if (-not $SkipSources) {
|
|
if (-not $OnlyFfmpeg) {
|
|
Install-GitHubArchive "grpc/grpc" $GrpcVersion $GrpcSource "CMakeLists.txt"
|
|
|
|
$grpcModules = @(
|
|
@{ Repo = "abseil/abseil-cpp"; Revision = "273292d1cfc0a94a65082ee350509af1d113344d"; Path = "third_party\abseil-cpp"; Marker = "CMakeLists.txt" },
|
|
@{ Repo = "google/boringssl"; Revision = "6195bf8242156c9a2fa75702eee058f91b86a88b"; Path = "third_party\boringssl-with-bazel"; Marker = "CMakeLists.txt" },
|
|
@{ Repo = "c-ares/c-ares"; Revision = "6654436a307a5a686b008c1d4c93b0085da6e6d8"; Path = "third_party\cares\cares"; Marker = "CMakeLists.txt" },
|
|
@{ Repo = "envoyproxy/data-plane-api"; Revision = "9c42588c956220b48eb3099d186487c2f04d32ec"; Path = "third_party\envoy-api"; Marker = "envoy" },
|
|
@{ Repo = "googleapis/googleapis"; Revision = "2f9af297c84c55c8b871ba4495e01ade42476c92"; Path = "third_party\googleapis"; Marker = "google" },
|
|
@{ Repo = "census-instrumentation/opencensus-proto"; Revision = "4aa53e15cbf1a47bc9087e6cfdca214c1eea4e89"; Path = "third_party\opencensus-proto"; Marker = "src" },
|
|
@{ Repo = "protocolbuffers/protobuf"; Revision = "b464cfbee18c71c40e761a5273ad369f3547294b"; Path = "third_party\protobuf"; Marker = "cmake\CMakeLists.txt" },
|
|
@{ Repo = "google/re2"; Revision = "8e08f47b11b413302749c0d8b17a1c94777495d5"; Path = "third_party\re2"; Marker = "CMakeLists.txt" },
|
|
@{ Repo = "cncf/xds"; Revision = "cb28da3451f158a947dfc45090fe92b07b243bc1"; Path = "third_party\xds"; Marker = "xds" },
|
|
@{ Repo = "madler/zlib"; Revision = "04f42ceca40f73e2978b50e93806c2a18c1281fc"; Path = "third_party\zlib"; Marker = "CMakeLists.txt" }
|
|
)
|
|
foreach ($module in $grpcModules) {
|
|
Install-GitHubArchive $module.Repo $module.Revision (Join-Path $GrpcSource $module.Path) $module.Marker
|
|
}
|
|
}
|
|
|
|
Install-GitHubArchive "FFmpeg/FFmpeg" $FfmpegVersion $FfmpegSource "configure"
|
|
if (-not $OnlyFfmpeg) {
|
|
Install-GitHubArchive "ros/urdfdom" $UrdfdomVersion $UrdfdomSource "CMakeLists.txt"
|
|
Install-GitHubArchive "ros/urdfdom_headers" $UrdfdomHeadersVersion $UrdfdomHeadersSource "CMakeLists.txt"
|
|
Install-GitHubArchive "ros/console_bridge" $ConsoleBridgeVersion $ConsoleBridgeSource "CMakeLists.txt"
|
|
Install-GitHubArchive "leethomason/tinyxml2" $TinyXml2Version $TinyXml2Source "CMakeLists.txt"
|
|
}
|
|
}
|
|
|
|
Write-Host "Dependency sources and tools are ready under $DepsRoot"
|