faxenoff's picture
cloud build tools (matrix trt11.3, 5 archs); the tools bucket is read-only since 10-07
40da26e verified
Raw History Blame Contribute Delete
2.79 kB
# go.ps1 - the shortest thing that can be typed on a rented VM.
#
# RDP clipboard and the legacy PowerShell console disagree about multi-line
# pastes: the first line executes, the rest lands as garbage or not at all. So
# the multi-line bootstrap invocation moves here, and the operator types ONE
# short line plus a token.
#
# $env:HF_TOKEN='hf_...'
# irm https://cdn.code-daemon.com/tools/go.ps1 | iex
#
# TOOLS_URL is baked in because this file already lives at that URL - if you can
# fetch this, that is the base you fetched it from.
$ErrorActionPreference = "Stop"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ProgressPreference = "SilentlyContinue"
$base = "https://cdn.code-daemon.com/tools"
if (-not $env:TOOLS_URL) { $env:TOOLS_URL = $base }
if (-not $env:HF_TOKEN) {
Write-Host "HF_TOKEN is not set." -ForegroundColor Red
Write-Host "Set it first, then re-run:" -ForegroundColor Yellow
Write-Host " `$env:HF_TOKEN='hf_...'" -ForegroundColor Yellow
Write-Host " irm $base/go.ps1 | iex" -ForegroundColor Yellow
exit 1
}
Write-Host "[go] TOOLS_URL = $($env:TOOLS_URL)" -ForegroundColor Cyan
# Download and run AS A FILE, not `irm | iex`.
#
# `iex` compiles the fetched script inside the CURRENT scope, and bootstrap_win
# is large enough that PowerShell hits its call-depth ceiling partway through:
#
# The script failed due to call depth overflow.
#
# Ironically this file is itself usually run through `iex`, which is fine - it
# is small. The child process below starts with a fresh stack, so the build gets
# the whole depth budget to itself, Ctrl-C reaches the build rather than this
# wrapper, and the exit code comes back directly instead of through a pipeline.
$boot = Join-Path $env:SystemDrive "uc-bootstrap_win.ps1"
$log = Join-Path $env:SystemDrive "uc-build.log"
Invoke-WebRequest -Uri "$($env:TOOLS_URL)/bootstrap_win.ps1" -OutFile $boot -UseBasicParsing
Write-Host "[go] log: $log" -ForegroundColor DarkGray
Write-Host "[go] disconnect with the X, do NOT Sign out" -ForegroundColor Yellow
# Tee, not Start-Transcript: a transcript wraps every write and adds frames to
# the same stack the overflow came from.
# `2>&1` turns the child's stderr into error OBJECTS in this pipeline, and with
# ErrorActionPreference=Stop the first one is fatal HERE - so pip writing a
# routine notice kills the wrapper while the build itself is fine. The symptom
# is an empty "NativeCommandError" naming this line and nothing else.
#
# Continue for the duration of the build: the child's own exit code is the real
# verdict, and it is checked below.
$ErrorActionPreference = "Continue"
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $boot 2>&1 | Tee-Object -FilePath $log
exit $LASTEXITCODE