@@ -7,13 +7,14 @@ $SkipSystem = $false
77$NoVerify = $false
88$WithBundle = $false
99$Warnings = New-Object System.Collections.Generic.List[string ]
10+ $MinVerifyFreeBytes = [int64 ](10 GB )
1011
1112$ScriptDir = Split-Path - Parent $MyInvocation.MyCommand.Path
1213$Root = Split-Path - Parent (Split-Path - Parent $ScriptDir )
1314
1415function Show-Usage {
1516 @"
16- Usage: powershell -ExecutionPolicy Bypass -File scripts/setup-windows.ps1 [options]
17+ Usage: powershell -ExecutionPolicy Bypass -File scripts/setup/setup -windows.ps1 [options]
1718
1819Set up BLXCode after a git clone on Windows.
1920
@@ -77,6 +78,34 @@ function Test-Command([string]$Name) {
7778 return $null -ne (Get-Command $Name - ErrorAction SilentlyContinue)
7879}
7980
81+ function Format-ByteSize ([int64 ]$Bytes ) {
82+ if ($Bytes -ge 1 GB ) {
83+ return " {0:N1} GiB" -f ($Bytes / 1 GB )
84+ }
85+ if ($Bytes -ge 1 MB ) {
86+ return " {0:N0} MiB" -f ($Bytes / 1 MB )
87+ }
88+ return " $Bytes bytes"
89+ }
90+
91+ function Assert-FreeDiskSpace ([string ]$Path , [int64 ]$MinBytes , [string ]$Purpose ) {
92+ $Resolved = Resolve-Path - LiteralPath $Path - ErrorAction Stop
93+ $Qualifier = Split-Path - Qualifier $Resolved.Path
94+ if (-not $Qualifier ) {
95+ return
96+ }
97+ $DriveName = $Qualifier.TrimEnd (" :\" )
98+ $Drive = Get-PSDrive - Name $DriveName - ErrorAction SilentlyContinue
99+ if ($null -eq $Drive ) {
100+ return
101+ }
102+ if ($Drive.Free -lt $MinBytes ) {
103+ $FreeText = Format-ByteSize $Drive.Free
104+ $NeedText = Format-ByteSize $MinBytes
105+ throw " Not enough free disk space for $Purpose on $Qualifier . Free: $FreeText ; required: $NeedText . Run 'cargo clean', delete old build artifacts, or re-run with --no-verify after installing prerequisites."
106+ }
107+ }
108+
80109function Invoke-Step ([string ]$Description , [scriptblock ]$Action ) {
81110 Write-Host " + $Description " - ForegroundColor DarkGray
82111 if ($script :CheckOnly ) {
@@ -303,6 +332,10 @@ function Run-Verification {
303332 return
304333 }
305334
335+ if (-not $script :CheckOnly ) {
336+ Assert-FreeDiskSpace $Root $script :MinVerifyFreeBytes " cargo/trunk verification"
337+ }
338+
306339 Push-Location $Root
307340 try {
308341 Invoke-Step " cargo check -p blxcode" {
0 commit comments