param([string]$BuildDirectory = '.starlet_msvc2') $ErrorActionPreference = 'Stop' $repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path $cacheRoot = Join-Path $repoRoot '.starlet_network' $runtimeRoot = Join-Path $repoRoot "$BuildDirectory\Binaries\Network" $packages = Get-Content -Raw (Join-Path $repoRoot 'Externals\libslirp\runtime-msys2.json') | ConvertFrom-Json New-Item -ItemType Directory -Force -Path $cacheRoot, $runtimeRoot | Out-Null foreach ($package in $packages) { $archive = Join-Path $cacheRoot ([Uri]$package.url).Segments[-1] if (-not (Test-Path -LiteralPath $archive)) { Write-Host "Downloading $($package.name)..." Invoke-WebRequest -Uri $package.url -OutFile $archive } if ((Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash -ne $package.sha256) { throw "SHA256 mismatch: $archive (preserved for inspection)" } # Extract only DLLs and licenses from verified packages; no installer or global PATH changes. $entries = @(tar -tf $archive) if ($LASTEXITCODE -ne 0) { throw "Cannot list $archive" } $selected = @($entries | Where-Object { $_ -match '^ucrt64/bin/[^/]+\.dll$' -or $_ -match '^ucrt64/share/licenses/[^/]+/[^/]+$' }) if ($selected.Count -eq 0) { throw "No runtime files in $archive" } $extracted = Join-Path $cacheRoot $package.name New-Item -ItemType Directory -Force -Path $extracted | Out-Null tar -xf $archive -C $extracted @selected if ($LASTEXITCODE -ne 0) { throw "Cannot extract $archive" } Get-ChildItem -LiteralPath (Join-Path $extracted 'ucrt64\bin') -Filter '*.dll' -File | Copy-Item -Destination $runtimeRoot $licenses = Join-Path $extracted 'ucrt64\share\licenses' if (Test-Path -LiteralPath $licenses) { $licenseDestination = Join-Path $runtimeRoot "licenses\$($package.name)" New-Item -ItemType Directory -Force -Path $licenseDestination | Out-Null Get-ChildItem -LiteralPath $licenses -File -Recurse | Copy-Item -Destination $licenseDestination } } Write-Host "Local libslirp runtime ready: $runtimeRoot"