From 200825c1e01e69c2dccb54510a7d9ea28470c8dd Mon Sep 17 00:00:00 2001 From: Nucleic Date: Tue, 28 Jul 2026 20:19:42 -0700 Subject: [PATCH] Merge nucleic/humble-fern-egret-60xo into dev --- build.ps1 | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/build.ps1 b/build.ps1 index aa8f931..a19b9d2 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,6 +33,12 @@ .PARAMETER Test Run the leg's tests instead of just building it. +.PARAMETER VcpkgRoot + An existing vcpkg checkout to use. Otherwise the script looks at %VCPKG_INSTALLATION_ROOT%, + the %LOCALAPPDATA%\vcpkg\vcpkg.path.txt breadcrumb, %LOCALAPPDATA%\Programs\vcpkg, + %USERPROFILE%\vcpkg and C:\vcpkg, and clones one into %LOCALAPPDATA%\Programs\vcpkg if none + of those hold a vcpkg.exe. + .PARAMETER Persist Also save CPATH to your *user* environment, so future shells and editors resolve sqlite3.h without going through this script. @@ -70,22 +76,44 @@ function Initialize-SQLite { $script:Triplet = "$arch-windows-static-md" } - $root = $VcpkgRoot - if (-not $root) { $root = $env:VCPKG_INSTALLATION_ROOT } - if (-not $root -or -not (Test-Path (Join-Path $root 'vcpkg.exe'))) { - $root = Join-Path $env:LOCALAPPDATA 'vcpkg' - } + # `%LOCALAPPDATA%\vcpkg` is NOT a candidate install root, and must never be a clone target: + # that path is vcpkg's own per-user DATA directory (registries, downloads, and the + # `vcpkg.path.txt` breadcrumb naming the real root), so it exists — non-empty, no `.git` — + # on any machine where vcpkg has merely *run* once. Cloning into it fails with "destination + # path already exists and is not an empty directory". We only ever read it, for that + # breadcrumb; a clone of our own goes to the conventional per-user install location. + $breadcrumb = Join-Path $env:LOCALAPPDATA 'vcpkg\vcpkg.path.txt' + $known = @( + $VcpkgRoot + $env:VCPKG_INSTALLATION_ROOT + $(if (Test-Path $breadcrumb) { (Get-Content $breadcrumb -Raw).Trim() }) + (Join-Path $env:LOCALAPPDATA 'Programs\vcpkg') + (Join-Path $env:USERPROFILE 'vcpkg') + 'C:\vcpkg' + ) + $root = $known | Where-Object { $_ -and (Test-Path (Join-Path $_ 'vcpkg.exe')) } | Select-Object -First 1 - if (-not (Test-Path (Join-Path $root '.git'))) { - Write-Step "Cloning vcpkg to $root (one time)" - git clone --depth 1 https://github.com/microsoft/vcpkg $root | Out-Host - if ($LASTEXITCODE -ne 0) { throw "vcpkg clone failed" } - } - if (-not (Test-Path (Join-Path $root 'vcpkg.exe'))) { + if (-not $root) { + # Nothing usable found. Clone into the per-user install location — unless the caller + # named a root, in which case honour it (they may be pointing at a fresh directory). + $root = if ($VcpkgRoot) { $VcpkgRoot } else { Join-Path $env:LOCALAPPDATA 'Programs\vcpkg' } + if (-not (Test-Path (Join-Path $root '.git'))) { + # `git clone` refuses a non-empty destination, and the resulting error says nothing + # about what to do — so diagnose it here, where the remedy is known. + if ((Test-Path $root) -and (Get-ChildItem $root -Force | Select-Object -First 1)) { + throw ("$root exists, is not empty, and holds neither vcpkg.exe nor a git " + + "checkout. Point the script at your vcpkg with -VcpkgRoot , or " + + "remove that directory.") + } + Write-Step "Cloning vcpkg to $root (one time)" + git clone --depth 1 https://github.com/microsoft/vcpkg $root | Out-Host + if ($LASTEXITCODE -ne 0) { throw "vcpkg clone failed" } + } Write-Step 'Bootstrapping vcpkg (one time)' & (Join-Path $root 'bootstrap-vcpkg.bat') -disableMetrics | Out-Host if ($LASTEXITCODE -ne 0) { throw "vcpkg bootstrap failed" } } + Write-Note "vcpkg root: $root" $prefix = Join-Path $root "installed\$Triplet" if (-not (Test-Path (Join-Path $prefix 'include\sqlite3.h'))) {