Enable VS 2026 solution generation and improve ARM64 developer experience (#14283)

- Auto-detect host architecture when TARGET_PLATFORM and CMAKE_GENERATOR_PLATFORM are unset, defaulting to ARM64 on ARM64 hosts - Fix trailing '|' in platform regex that made the else branch unreachable - Refactor Visual Studio detection to prefer VS2022 and fall back to VS2026 with a clang-format warning- Document x64 .NET 6.0 runtime setup required for WiX on ARM64 Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>

Ben Hillis committed Feb 25, 2026 at 17:32 UTC 2856dc3d882d944d610e7a8b282f8bac55a29606
2 files changed +61 -12
CMakeLists.txt
+34 -11
@@ -4,10 +4,20 @@ set(CMAKE_SYSTEM_VERSION 10.0.26100.0)
4 project(wsl)
5
6 # Rationalize TARGET_PLATFORM
7 +# When neither CMAKE_GENERATOR_PLATFORM nor TARGET_PLATFORM is set, default to the host architecture.
8 +if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "" AND "${TARGET_PLATFORM}" STREQUAL "")
9 + if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "ARM64")
10 + set(TARGET_PLATFORM "arm64")
11 + else()
12 + set(TARGET_PLATFORM "x64")
13 + endif()
14 + message(STATUS "No platform specified, defaulting to '${TARGET_PLATFORM}' based on host architecture.")
15 +endif()
16 +
17 if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "arm64" OR "${TARGET_PLATFORM}" STREQUAL "arm64")
18 set(TARGET_PLATFORM "arm64")
19 set(TEST_DISTRO_PLATFORM "arm64")
10 -elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64|amd64|" OR "${TARGET_PLATFORM}" MATCHES "x64|amd64|")
20 +elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64|amd64" OR "${TARGET_PLATFORM}" MATCHES "x64|amd64")
21 set(TARGET_PLATFORM "x64")
22 set(TEST_DISTRO_PLATFORM "amd64")
23 else()
@@ -258,18 +268,31 @@ else()
268 message(FATAL_ERROR "Unsupported platform: '${TARGET_PLATFORM}'")
269 endif()
270
261 -# Determine the Visual Studio installation directory which contains LLVM tools
262 -# N.B. The version is set to VS2022 to ensure local runs match pipeline behavior
263 -# Require that Clang be installed in the product to potentially de-deduplicate
264 -execute_process(
265 - COMMAND "${VSWHERE_SOURCE_DIR}/vswhere.exe" -version "[17.0,18.0)" -products * -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang -property installationPath
266 - OUTPUT_VARIABLE VS_INSTALL_DIR
267 - OUTPUT_STRIP_TRAILING_WHITESPACE
268 - COMMAND_ERROR_IS_FATAL ANY
269 -)
271 +# Determine the Visual Studio installation directory which contains LLVM tools.
272 +# Supported versions: VS2022 and VS2026.
273 +# Prefer VS2022 to keep local clang-format output aligned with pipeline expectations.
274 +function(find_vs_install_dir VERSION_RANGE OUTPUT_VAR)
275 + execute_process(
276 + COMMAND "${VSWHERE_SOURCE_DIR}/vswhere.exe" -version "${VERSION_RANGE}" -products * -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang -property installationPath -prerelease -latest
277 + OUTPUT_VARIABLE _vs_install_dir
278 + OUTPUT_STRIP_TRAILING_WHITESPACE
279 + COMMAND_ERROR_IS_FATAL ANY
280 + )
281 +
282 + set(${OUTPUT_VAR} "${_vs_install_dir}" PARENT_SCOPE)
283 +endfunction()
284 +
285 +find_vs_install_dir("[17.0,18.0)" VS_INSTALL_DIR)
286 +
287 +if (NOT VS_INSTALL_DIR)
288 + find_vs_install_dir("[18.0,19.0)" VS_INSTALL_DIR)
289 + if (VS_INSTALL_DIR)
290 + message(WARNING "Visual Studio 2022 was not found; using Visual Studio 2026 instead. clang-format output may differ from pipeline expectations.")
291 + endif()
292 +endif()
293
294 if (NOT VS_INSTALL_DIR)
272 - message(FATAL_ERROR "Could not determine Visual Studio 2022 installation directory.")
295 + message(FATAL_ERROR "Could not determine Visual Studio installation directory.")
296 endif()
297
298 if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
doc/docs/dev-loop.md
+27 -1
@@ -18,7 +18,33 @@ The following tools are required to build WSL:
18 - .NET WinUI app development tools
19
20 - Building WSL requires support for symbolic links. To ensure this capability, enable [Developer Mode](https://learn.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) in Windows Settings or execute the build process with Administrator privileges.
21 -
21 +
22 +### ARM64 development
23 +
24 +When building on ARM64 Windows, the [WiX](https://wixtoolset.org/) toolset (`wix.exe`) requires the **x64 .NET 6.0 runtime** because it is an x64 binary. The ARM64 .NET runtime alone is not sufficient.
25 +
26 +To install the x64 .NET 6.0 runtime, run the following commands in PowerShell:
27 +
28 +```powershell
29 +# Download the official dotnet-install script
30 +Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile "$env:TEMP\dotnet-install.ps1"
31 +
32 +# Install the x64 .NET 6.0 runtime
33 +powershell -ExecutionPolicy Bypass -File "$env:TEMP\dotnet-install.ps1" -Channel 6.0 -Runtime dotnet -Architecture x64 -InstallDir "C:\Program Files\dotnet\x64"
34 +```
35 +
36 +Then set the `DOTNET_ROOT_X64` environment variable so the runtime is discoverable:
37 +
38 +```powershell
39 +# Set for the current session
40 +$env:DOTNET_ROOT_X64 = "C:\Program Files\dotnet\x64"
41 +
42 +# Set permanently for your user
43 +[System.Environment]::SetEnvironmentVariable("DOTNET_ROOT_X64", "C:\Program Files\dotnet\x64", "User")
44 +```
45 +
46 +> **Note:** You may need to restart VS Code or open a new terminal for the environment variable to take effect.
47 +
48 ## Building WSL
49
50 Once you have cloned the repository, generate the Visual Studio solution by running: