|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Checks that all prerequisites for building WSL are installed. |
| 4 | +.DESCRIPTION |
| 5 | + Validates the development environment and reports missing tools |
| 6 | + with installation instructions. Run this before your first build. |
| 7 | +.EXAMPLE |
| 8 | + .\tools\setup-dev-env.ps1 |
| 9 | +#> |
| 10 | + |
| 11 | +Set-StrictMode -Version Latest |
| 12 | +$ErrorActionPreference = "Stop" |
| 13 | + |
| 14 | +$script:Errors = 0 |
| 15 | + |
| 16 | +function Check($Name, $Result, $Fix, [switch]$Optional) |
| 17 | +{ |
| 18 | + if ($Result) |
| 19 | + { |
| 20 | + Write-Host " [OK] $Name" -ForegroundColor Green |
| 21 | + } |
| 22 | + elseif ($Optional) |
| 23 | + { |
| 24 | + Write-Host " [OPTIONAL] $Name" -ForegroundColor DarkYellow |
| 25 | + Write-Host " -> $Fix" -ForegroundColor Yellow |
| 26 | + } |
| 27 | + else |
| 28 | + { |
| 29 | + Write-Host " [MISSING] $Name" -ForegroundColor Red |
| 30 | + Write-Host " -> $Fix" -ForegroundColor Yellow |
| 31 | + $script:Errors++ |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +Write-Host "" |
| 36 | +Write-Host "WSL Development Environment Check" -ForegroundColor Cyan |
| 37 | +Write-Host "==================================" -ForegroundColor Cyan |
| 38 | +Write-Host "" |
| 39 | + |
| 40 | +# --- CMake --- |
| 41 | +Write-Host "Build Tools:" -ForegroundColor White |
| 42 | +$cmake = Get-Command "cmake" -ErrorAction SilentlyContinue |
| 43 | +$cmakeVersion = $null |
| 44 | +$cmakeOk = $false |
| 45 | +if ($cmake) |
| 46 | +{ |
| 47 | + $cmakeVersion = [version]((cmake --version | Select-Object -First 1) -replace '[^0-9.]', '') |
| 48 | + $cmakeOk = $cmakeVersion -ge [version]"3.25" |
| 49 | +} |
| 50 | +Check "CMake >= 3.25$(if ($cmakeVersion) { " (found $cmakeVersion)" })" $cmakeOk "winget install Kitware.CMake" |
| 51 | + |
| 52 | +# --- Visual Studio --- |
| 53 | +$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" |
| 54 | +$vsInstall = $null |
| 55 | +if (Test-Path $vswhere) |
| 56 | +{ |
| 57 | + $vsInstall = & $vswhere -latest -property installationPath 2>$null |
| 58 | +} |
| 59 | +Check "Visual Studio 2022+" ($null -ne $vsInstall) "Install Visual Studio 2022: https://visualstudio.microsoft.com/" |
| 60 | + |
| 61 | +# --- VS Components (only check if VS is found) --- |
| 62 | +if ($vsInstall) |
| 63 | +{ |
| 64 | + Write-Host "" |
| 65 | + Write-Host "Visual Studio Components:" -ForegroundColor White |
| 66 | + |
| 67 | + $installedComponents = @(& $vswhere -latest -property catalog_productLineVersion 2>$null) |
| 68 | + $vsComponents = & $vswhere -latest -format json 2>$null | ConvertFrom-Json |
| 69 | + |
| 70 | + # Check for specific required components via their markers |
| 71 | + $clangPath = Join-Path $vsInstall "VC\Tools\Llvm\x64\bin\clang-format.exe" |
| 72 | + Check "C++ Clang Compiler for Windows" (Test-Path $clangPath) "VS Installer -> Modify -> Individual Components -> C++ Clang Compiler for Windows" |
| 73 | + |
| 74 | + $atlPath = Get-ChildItem -Path (Join-Path $vsInstall "VC\Tools\MSVC") -Filter "atlbase.h" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 |
| 75 | + Check "C++ ATL for latest v143 tools" ($null -ne $atlPath) "VS Installer -> Modify -> Individual Components -> C++ ATL for latest v143 build tools" |
| 76 | + |
| 77 | + $msbuild = Get-Command "msbuild" -ErrorAction SilentlyContinue |
| 78 | + if (-not $msbuild) |
| 79 | + { |
| 80 | + $msbuild = Get-ChildItem -Path $vsInstall -Filter "MSBuild.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 |
| 81 | + } |
| 82 | + Check "MSBuild" ($null -ne $msbuild) "VS Installer -> Modify -> Individual Components -> MSBuild" |
| 83 | +} |
| 84 | + |
| 85 | +# --- Windows SDK --- |
| 86 | +Write-Host "" |
| 87 | +Write-Host "Windows SDK:" -ForegroundColor White |
| 88 | +$sdkPath = "${env:ProgramFiles(x86)}\Windows Kits\10\Include\10.0.26100.0" |
| 89 | +Check "Windows SDK 26100" (Test-Path $sdkPath) "VS Installer -> Modify -> Individual Components -> Windows 11 SDK (10.0.26100.0)" |
| 90 | + |
| 91 | +# --- Developer Mode / Symlinks --- |
| 92 | +Write-Host "" |
| 93 | +Write-Host "System Configuration:" -ForegroundColor White |
| 94 | + |
| 95 | +$devMode = $false |
| 96 | +try |
| 97 | +{ |
| 98 | + $devModeReg = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" -Name "AllowDevelopmentWithoutDevLicense" -ErrorAction SilentlyContinue |
| 99 | + $devMode = $devModeReg -and $devModeReg.AllowDevelopmentWithoutDevLicense -eq 1 |
| 100 | +} |
| 101 | +catch {} |
| 102 | + |
| 103 | +$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) |
| 104 | +Check "Developer Mode or Admin$(if ($devMode) { ' (Developer Mode)' } elseif ($isAdmin) { ' (Administrator)' })" ($devMode -or $isAdmin) "Settings -> System -> For developers -> Developer Mode" |
| 105 | + |
| 106 | +# --- Optional tools --- |
| 107 | +Write-Host "" |
| 108 | +Write-Host "Optional Tools:" -ForegroundColor White |
| 109 | + |
| 110 | +$windbg = Get-Command "WinDbgX.exe" -ErrorAction SilentlyContinue |
| 111 | +Check "WinDbg (for /attachdebugger)" ($null -ne $windbg) "winget install Microsoft.WinDbg" -Optional |
| 112 | + |
| 113 | +$python = Get-Command "python3" -ErrorAction SilentlyContinue |
| 114 | +if (-not $python) { $python = Get-Command "python" -ErrorAction SilentlyContinue } |
| 115 | +Check "Python 3 (for validation scripts)" ($null -ne $python) "winget install Python.Python.3.13" -Optional |
| 116 | + |
| 117 | +# --- Summary --- |
| 118 | +Write-Host "" |
| 119 | +if ($script:Errors -eq 0) |
| 120 | +{ |
| 121 | + Write-Host "All prerequisites found. Ready to build!" -ForegroundColor Green |
| 122 | + Write-Host "" |
| 123 | + Write-Host " cmake ." |
| 124 | + Write-Host " cmake --build . -- -m" |
| 125 | + Write-Host "" |
| 126 | +} |
| 127 | +else |
| 128 | +{ |
| 129 | + Write-Host "$($script:Errors) prerequisite(s) missing. Install them and re-run this script." -ForegroundColor Red |
| 130 | + Write-Host "" |
| 131 | + exit 1 |
| 132 | +} |
0 commit comments