<# .SYNOPSIS CrowdSharp One-Click Windows Setup (Lean 4.19.0 + Lean 4.36.0 + Slices Repo) .DESCRIPTION Installs everything a new contributor or 2nd-checker needs to work on https://crowdsharp.org: 1. Git (via winget if not already installed) 2. elan (the official Lean 4 version manager) 3. Lean 4 toolchains: v4.19.0 (Archive) and v4.36.0 (Frontier) 4. Clones/updates https://github.com/crowdsharp/slices 5. Downloads prebuilt Mathlib cache (lake exe cache get) if present 6. Installs the VS Code Lean 4 extension (if VS Code CLI is on PATH) .EXAMPLE powershell -ExecutionPolicy Bypass -File .\crowdsharp-setup.ps1 .EXAMPLE irm https://crowdsharp.org/api/setup/windows.ps1 | iex #> [CmdletBinding()] param( [string]$InstallDir = (Join-Path $env:USERPROFILE "crowdsharp-slices"), [string]$DefaultToolchain = "leanprover/lean4:v4.19.0", [switch]$SkipClone, [switch]$SkipVSCode ) $ErrorActionPreference = "Stop" function Write-Step([string]$Step, [string]$Msg) { Write-Host "" Write-Host "[$Step] $Msg" -ForegroundColor Cyan } function Write-Ok([string]$Msg) { Write-Host " OK: $Msg" -ForegroundColor Green } function Write-Warn([string]$Msg) { Write-Host " WARN: $Msg" -ForegroundColor Yellow } function Refresh-SessionPath { $machinePath = [System.Environment]::GetEnvironmentVariable("Path", "Machine") $userPath = [System.Environment]::GetEnvironmentVariable("Path", "User") $elanBin = Join-Path $env:USERPROFILE ".elan\bin" $parts = @($elanBin, $userPath, $machinePath) | Where-Object { $_ -and $_.Trim() -ne "" } $env:Path = ($parts -join ";") } Write-Host "============================================================" -ForegroundColor DarkCyan Write-Host " CrowdSharp Lean 4 Contributor Setup (Windows PowerShell)" -ForegroundColor White Write-Host " https://crowdsharp.org | github.com/crowdsharp/slices" -ForegroundColor Gray Write-Host "============================================================" -ForegroundColor DarkCyan # [1/6] Git Write-Step "1/6" "Checking Git..." if (-not (Get-Command git -ErrorAction SilentlyContinue)) { if (Get-Command winget -ErrorAction SilentlyContinue) { Write-Host " Git not found. Installing Git via winget..." winget install --id Git.Git -e --source winget --accept-package-agreements --accept-source-agreements Refresh-SessionPath } if (-not (Get-Command git -ErrorAction SilentlyContinue)) { Write-Warn "Git is not on PATH yet. Install Git from https://git-scm.com/download/win, reopen PowerShell, and re-run this script." exit 1 } } Write-Ok (git --version) # [2/6] elan (Lean 4 version manager) Write-Step "2/6" "Checking elan (Lean 4 version manager)..." Refresh-SessionPath if (-not (Get-Command elan -ErrorAction SilentlyContinue)) { $elanScript = Join-Path $env:TEMP "elan-init.ps1" Write-Host " Downloading official elan installer from https://elan.lean-lang.org/elan-init.ps1..." [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Invoke-WebRequest -Uri "https://elan.lean-lang.org/elan-init.ps1" -OutFile $elanScript -UseBasicParsing Write-Host " Running elan-init.ps1 (non-interactive)..." & powershell -ExecutionPolicy Bypass -File $elanScript -NoPrompt -DefaultToolchain none Remove-Item -Path $elanScript -Force -ErrorAction SilentlyContinue Refresh-SessionPath } if (-not (Get-Command elan -ErrorAction SilentlyContinue)) { Write-Warn "elan was installed, but is not yet visible on PATH. Open a fresh PowerShell window and re-run this script." exit 1 } Write-Ok (elan --version) # [3/6] Install Lean 4 toolchains (v4.19.0 Archive + v4.36.0 Frontier) Write-Step "3/6" "Installing CrowdSharp Lean 4 toolchains (v4.19.0 Archive + v4.36.0 Frontier)..." $toolchains = @( @{ Name = "leanprover/lean4:v4.19.0"; Label = "v4.19.0 Archive" }, @{ Name = "leanprover/lean4:v4.36.0"; Label = "v4.36.0 Frontier" } ) foreach ($tc in $toolchains) { Write-Host " Installing $($tc.Label) ($($tc.Name))..." try { & elan toolchain install $tc.Name if ($LASTEXITCODE -eq 0) { Write-Ok "Installed $($tc.Name)" } else { Write-Warn "Could not install $($tc.Name) (exit $LASTEXITCODE). You can install it later with: elan toolchain install $($tc.Name)" } } catch { Write-Warn "Could not install $($tc.Name): $($_.Exception.Message)" } } Write-Host " Setting default toolchain to $DefaultToolchain..." try { & elan default $DefaultToolchain Write-Ok "Default toolchain set to $DefaultToolchain" } catch { Write-Warn "Could not set default toolchain to $DefaultToolchain." } # [4/6] Clone or update github.com/crowdsharp/slices Write-Step "4/6" "Setting up CrowdSharp slices workspace at $InstallDir..." if ($SkipClone) { Write-Host " Skipping repository clone (-SkipClone specified)." } else { if (Test-Path (Join-Path $InstallDir ".git")) { Write-Host " Existing repo found. Pulling latest main..." Push-Location $InstallDir try { & git pull --ff-only Write-Ok "Updated $InstallDir" } finally { Pop-Location } } else { Write-Host " Cloning https://github.com/crowdsharp/slices.git..." & git clone https://github.com/crowdsharp/slices.git $InstallDir Write-Ok "Cloned to $InstallDir" } } # [5/6] Prebuilt Mathlib cache (if root lakefile is present) Write-Step "5/6" "Checking for root Lakefile / Mathlib cache..." if ((-not $SkipClone) -and ((Test-Path (Join-Path $InstallDir "lakefile.toml")) -or (Test-Path (Join-Path $InstallDir "lakefile.lean")))) { Push-Location $InstallDir try { Write-Host " Fetching prebuilt Mathlib .olean cache (lake exe cache get)..." & lake exe cache get Write-Ok "Mathlib cache ready." } catch { Write-Warn "Cache fetch skipped or unavailable at repo root; run 'lake exe cache get' inside any individual slice folder." } finally { Pop-Location } } else { Write-Host " Individual slices each carry their own lakefile; run 'lake exe cache get && lake build' inside any slice folder." } # [6/6] VS Code Lean 4 extension (optional) Write-Step "6/6" "Checking VS Code Lean 4 extension..." if ($SkipVSCode) { Write-Host " Skipping VS Code check (-SkipVSCode specified)." } elseif (Get-Command code -ErrorAction SilentlyContinue) { Write-Host " VS Code detected. Installing official leanprover.lean4 extension..." try { & code --install-extension leanprover.lean4 Write-Ok "VS Code Lean 4 extension installed." } catch { Write-Warn "Could not auto-install VS Code extension; install 'leanprover.lean4' from the Extensions panel." } } else { Write-Host " VS Code CLI ('code') not found on PATH. Optional: install VS Code (https://code.visualstudio.com/) and the 'leanprover.lean4' extension." } # Final summary Write-Host "" Write-Host "============================================================" -ForegroundColor Green Write-Host " CrowdSharp Lean 4 Setup Complete!" -ForegroundColor Green Write-Host "============================================================" -ForegroundColor Green Write-Host " Lean: $(lean --version)" Write-Host " Lake: $(lake --version)" Write-Host " Workspace: $InstallDir" Write-Host "" Write-Host "Installed toolchains:" -ForegroundColor Cyan & elan toolchain list Write-Host "" Write-Host "Next steps:" -ForegroundColor Cyan Write-Host " 1. Browse 1,000 Mathlib-Bound specs at https://crowdsharp.org" Write-Host " 2. Enter a slice folder and fetch Mathlib cache:" Write-Host " cd `"$InstallDir\slices\\v4.19.0`"" Write-Host " lake exe cache get && lake build" Write-Host " 3. Independent 2nd-check (zero sorry, --trust=0):" Write-Host " lake env lean4checker --fresh" Write-Host " 4. Join Discord for help & coordination: https://discord.gg/HSksfsMCUc" Write-Host ""