diff --git a/.github/workflows/build-windows-vs2022.yaml b/.github/workflows/build-windows-vs2022.yaml index b28aa1515..222e32e67 100644 --- a/.github/workflows/build-windows-vs2022.yaml +++ b/.github/workflows/build-windows-vs2022.yaml @@ -29,13 +29,13 @@ jobs: - name: Checkout uses: actions/checkout@v4 - continue-on-error: true - name: Build env: SKIP_ARM_BUILD: 1 SKIP_ARM64_BUILD: 1 + SKIP_NET40_BUILD: 1 PlatformToolset: v143 VSTOOLS_VERSION: vs2022 shell: cmd - run: build-all.bat + run: build-all-windows.bat diff --git a/build-all-v142.bat b/build-all-v142.bat index 4ae0364bc..72776a978 100644 --- a/build-all-v142.bat +++ b/build-all-v142.bat @@ -2,4 +2,4 @@ set VSTOOLS_VERSION=vs2019 set PlatformToolset=v142 -call build-all.bat +call "%~dp0build-all-windows.bat" %* diff --git a/build-all-v143.bat b/build-all-v143.bat index 6ff46738d..8d5ebbfa9 100644 --- a/build-all-v143.bat +++ b/build-all-v143.bat @@ -2,4 +2,5 @@ set VSTOOLS_VERSION=vs2022 set PlatformToolset=v143 -call build-all.bat +set SKIP_NET40_BUILD=1 +call "%~dp0build-all-windows.bat" %* diff --git a/build-all-v145.bat b/build-all-v145.bat new file mode 100644 index 000000000..54f6b4e9a --- /dev/null +++ b/build-all-v145.bat @@ -0,0 +1,6 @@ +@echo off + +set VSTOOLS_VERSION=vs2026 +set PlatformToolset=v145 +set SKIP_NET40_BUILD=1 +call "%~dp0build-all-windows.bat" %* diff --git a/build-all-windows.bat b/build-all-windows.bat new file mode 100644 index 000000000..4ea3808e9 --- /dev/null +++ b/build-all-windows.bat @@ -0,0 +1,111 @@ +@echo off + +cd /d "%~dp0" +@setlocal ENABLEEXTENSIONS + +set CUSTOM_PROPS= +if not "%~1"=="" ( + if not exist "%~f1" ( + goto custom_props_missing + ) + if /I not "%~x1"==".props" ( + if /I not "%~x1"==".targets" ( + goto custom_props_invalid_type + ) + ) + set CUSTOM_PROPS="/p:ForceImportBeforeCppTargets=%~f1" + echo Using custom properties file for the build: + echo "/p:ForceImportBeforeCppTargets=%~f1" +) + +goto after_custom_props_validation + +:custom_props_missing +echo ERROR: Custom build input not found: %~1 +echo Pass an existing MSBuild .props or .targets file to ForceImportBeforeCppTargets. +exit /b 1 + +:custom_props_invalid_type +echo ERROR: Custom build input must be an MSBuild .props or .targets file: %~1 +echo Pass the MSBuild import file, not the CONFIG_CUSTOM_H header. +exit /b 1 + +:after_custom_props_validation +call tools\gen-version.cmd + +set NET40_MD_TARGETS=,net40:Rebuild +set NET40_SAMPLE_TARGETS=,Samples\cs\SampleCsNet40:Rebuild +if DEFINED SKIP_NET40_BUILD ( + echo Skipping legacy .NET Framework 4.0 targets. + set NET40_MD_TARGETS= + set NET40_SAMPLE_TARGETS= +) + +echo Update all public submodules... +git -c submodule."lib/modules".update=none submodule update --init --recursive + +if DEFINED GIT_PULL_TOKEN ( + rd /s /q lib\modules + git clone https://%GIT_PULL_TOKEN%:x-oauth-basic@github.com/microsoft/cpp_client_telemetry_modules.git lib\modules +) + +set GTEST_PATH=third_party\googletest +if NOT EXIST %GTEST_PATH%\CMakeLists.txt ( + git clone --depth 1 --branch release-1.12.1 https://github.com/google/googletest %GTEST_PATH% +) + +if NOT DEFINED SKIP_MD_BUILD ( + REM DLL and static /MD build + REM Release + call tools\RunMsBuild.bat Win32 Release "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild%NET40_MD_TARGETS%,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild,Tests\gmock:Rebuild,Tests\gtest:Rebuild,Tests\UnitTests:Rebuild,Tests\FuncTests:Rebuild%NET40_SAMPLE_TARGETS%" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + call tools\RunMsBuild.bat x64 Release "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild%NET40_MD_TARGETS%,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild,Tests\gmock:Rebuild,Tests\gtest:Rebuild,Tests\UnitTests:Rebuild,Tests\FuncTests:Rebuild%NET40_SAMPLE_TARGETS%" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + REM Debug + if NOT DEFINED SKIP_DEBUG_BUILD ( + call tools\RunMsBuild.bat Win32 Debug "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild%NET40_MD_TARGETS%,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild,Tests\gmock:Rebuild,Tests\gtest:Rebuild,Tests\UnitTests:Rebuild,Tests\FuncTests:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + call tools\RunMsBuild.bat x64 Debug "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild%NET40_MD_TARGETS%,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild,Tests\gmock:Rebuild,Tests\gtest:Rebuild,Tests\UnitTests:Rebuild,Tests\FuncTests:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + ) +) + +if NOT DEFINED SKIP_MT_BUILD ( + REM Static /MT build + REM Release + call tools\RunMsBuild.bat Win32 Release.vc14x.MT-sqlite "sqlite:Rebuild,zlib:Rebuild,win32-lib:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + call tools\RunMsBuild.bat x64 Release.vc14x.MT-sqlite "sqlite:Rebuild,zlib:Rebuild,win32-lib:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + REM Debug + if NOT DEFINED SKIP_DEBUG_BUILD ( + call tools\RunMsBuild.bat Win32 Debug.vc14x.MT-sqlite "sqlite:Rebuild,zlib:Rebuild,win32-lib:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + call tools\RunMsBuild.bat x64 Debug.vc14x.MT-sqlite "sqlite:Rebuild,zlib:Rebuild,win32-lib:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + ) +) + +if NOT DEFINED SKIP_ARM_BUILD ( + REM ARM DLL build + REM Release + call tools\RunMsBuild.bat ARM Release "zlib:Rebuild,sqlite-uwp:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + if NOT DEFINED SKIP_DEBUG_BUILD ( + REM Debug + call tools\RunMsBuild.bat ARM Debug "zlib:Rebuild,sqlite-uwp:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + ) +) + +if NOT DEFINED SKIP_ARM64_BUILD ( + REM ARM64 DLL build + REM Release + call tools\RunMsBuild.bat ARM64 Release "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + if NOT DEFINED SKIP_DEBUG_BUILD ( + REM Debug + call tools\RunMsBuild.bat ARM64 Debug "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild" %CUSTOM_PROPS% + if errorlevel 1 exit /b 1 + ) +) diff --git a/build-all.bat b/build-all.bat index 5b535bc08..547594ff6 100644 --- a/build-all.bat +++ b/build-all.bat @@ -1,91 +1,3 @@ @echo off - -cd %~dp0 -@setlocal ENABLEEXTENSIONS - -set CUSTOM_PROPS= -if not "%~1"=="" ( - if not exist "%~f1" ( - goto custom_props_missing - ) - if /I not "%~x1"==".props" ( - if /I not "%~x1"==".targets" ( - goto custom_props_invalid_type - ) - ) - set CUSTOM_PROPS="/p:ForceImportBeforeCppTargets=%~f1" - echo Using custom properties file for the build: - echo %CUSTOM_PROPS% -) - -goto after_custom_props_validation - -:custom_props_missing -echo ERROR: Custom build input not found: %~1 -echo Pass an existing MSBuild .props or .targets file to ForceImportBeforeCppTargets. -exit /b 1 - -:custom_props_invalid_type -echo ERROR: Custom build input must be an MSBuild .props or .targets file: %~1 -echo Pass the MSBuild import file, not the CONFIG_CUSTOM_H header. -exit /b 1 - -:after_custom_props_validation -call tools\gen-version.cmd - -echo Update all public submodules... -git -c submodule."lib/modules".update=none submodule update --init --recursive - -if DEFINED GIT_PULL_TOKEN ( - rd /s /q lib\modules - git clone https://%GIT_PULL_TOKEN%:x-oauth-basic@github.com/microsoft/cpp_client_telemetry_modules.git lib\modules -) - -set GTEST_PATH=third_party\googletest -if NOT EXIST %GTEST_PATH%\CMakeLists.txt ( - git clone --depth 1 --branch release-1.12.1 https://github.com/google/googletest %GTEST_PATH% -) - -if NOT DEFINED SKIP_MD_BUILD ( - REM DLL and static /MD build - REM Release - call tools\RunMsBuild.bat Win32 Release "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild,net40:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild,Tests\gmock:Rebuild,Tests\gtest:Rebuild,Tests\UnitTests:Rebuild,Tests\FuncTests:Rebuild,Samples\cs\SampleCsNet40:Rebuild" %CUSTOM_PROPS% - call tools\RunMsBuild.bat x64 Release "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild,net40:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild,Tests\gmock:Rebuild,Tests\gtest:Rebuild,Tests\UnitTests:Rebuild,Tests\FuncTests:Rebuild,Samples\cs\SampleCsNet40:Rebuild" %CUSTOM_PROPS% - REM Debug - if NOT DEFINED SKIP_DEBUG_BUILD ( - call tools\RunMsBuild.bat Win32 Debug "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild,net40:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild,Tests\gmock:Rebuild,Tests\gtest:Rebuild,Tests\UnitTests:Rebuild,Tests\FuncTests:Rebuild" %CUSTOM_PROPS% - call tools\RunMsBuild.bat x64 Debug "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild,net40:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild,Tests\gmock:Rebuild,Tests\gtest:Rebuild,Tests\UnitTests:Rebuild,Tests\FuncTests:Rebuild" %CUSTOM_PROPS% - ) -) - -if NOT DEFINED SKIP_MT_BUILD ( - REM Static /MT build - REM Release - call tools\RunMsBuild.bat Win32 Release.vc14x.MT-sqlite "sqlite:Rebuild,zlib:Rebuild,win32-lib:Rebuild" %CUSTOM_PROPS% - call tools\RunMsBuild.bat x64 Release.vc14x.MT-sqlite "sqlite:Rebuild,zlib:Rebuild,win32-lib:Rebuild" %CUSTOM_PROPS% - REM Debug - if NOT DEFINED SKIP_DEBUG_BUILD ( - call tools\RunMsBuild.bat Win32 Debug.vc14x.MT-sqlite "sqlite:Rebuild,zlib:Rebuild,win32-lib:Rebuild" %CUSTOM_PROPS% - call tools\RunMsBuild.bat x64 Debug.vc14x.MT-sqlite "sqlite:Rebuild,zlib:Rebuild,win32-lib:Rebuild" %CUSTOM_PROPS% - ) -) - -if NOT DEFINED SKIP_ARM_BUILD ( - REM ARM DLL build - REM Release - call tools\RunMsBuild.bat ARM Release "zlib:Rebuild,sqlite-uwp:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild" %CUSTOM_PROPS% - if NOT DEFINED SKIP_DEBUG_BUILD ( - REM Debug - call tools\RunMsBuild.bat ARM Debug "zlib:Rebuild,sqlite-uwp:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild" %CUSTOM_PROPS% - ) -) - -if NOT DEFINED SKIP_ARM64_BUILD ( - REM ARM64 DLL build - REM Release - call tools\RunMsBuild.bat ARM64 Release "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild" %CUSTOM_PROPS% - if NOT DEFINED SKIP_DEBUG_BUILD ( - REM Debug - call tools\RunMsBuild.bat ARM64 Debug "sqlite:Rebuild,zlib:Rebuild,sqlite-uwp:Rebuild,win32-dll:Rebuild,win32-lib:Rebuild,win10-cs:Rebuild,win10-dll:Rebuild,win10-lib:Rebuild" %CUSTOM_PROPS% - ) -) +echo build-all.bat is a compatibility wrapper. Use build-all-windows.bat for Windows Visual Studio builds. +call "%~dp0build-all-windows.bat" %* diff --git a/docs/building-custom-SKU.md b/docs/building-custom-SKU.md index 0668fbe3f..a68d6a681 100644 --- a/docs/building-custom-SKU.md +++ b/docs/building-custom-SKU.md @@ -39,12 +39,12 @@ Build recipe must contain the following preprocessor definitions: Command: ```console -build-all.bat %CD%\Solutions\build.compact.props +build-all-windows.bat %CD%\Solutions\build.compact.props ``` produces a custom compact SDK build. -The argument passed to `build-all.bat` must be an MSBuild `.props` or `.targets` file that sets the required preprocessor definitions. Do not pass the `config-*.h` header directly to `ForceImportBeforeCppTargets`. +The argument passed to `build-all-windows.bat` must be an MSBuild `.props` or `.targets` file that sets the required preprocessor definitions. Do not pass the `config-*.h` header directly to `ForceImportBeforeCppTargets`. `build-all.bat` remains as a compatibility wrapper for existing automation. How it works: diff --git a/docs/cpp-start-windows.md b/docs/cpp-start-windows.md index ef5850d84..6f6189056 100644 --- a/docs/cpp-start-windows.md +++ b/docs/cpp-start-windows.md @@ -16,17 +16,24 @@ If your project requires the Universal Telemetry Client (a.k.a. UTC) to send tel ## **Windows prerequisites and dependencies for building from source** -* Visual Studio 2019 or 2022 (2022 is recommended). +* Visual Studio 2019, 2022, or 2026 (2022 or newer is recommended). * C++ Dev Tools ## **Option 1: Build the SDK from source using Visual Studio** * Open the *cpp_client_telemetry/Solutions/MSTelemetrySDK.sln* solution in Visual Studio. -* Alternatively you can use *build-all.bat* located in workspace root folder to build from command line +* Alternatively, build from the workspace root with the script that matches your Visual Studio toolset: + * Visual Studio 2019: `build-all-v142.bat` + * Visual Studio 2022: `build-all-v143.bat` + * Visual Studio 2026: `build-all-v145.bat` + +The version-specific scripts set `VSTOOLS_VERSION` and `PlatformToolset` before calling `build-all-windows.bat`, which builds the Windows Visual Studio solution matrix. `build-all.bat` remains as a compatibility wrapper for existing automation; if you call either script directly, set both values yourself so `tools\vcvars.cmd` selects the same Visual Studio installation as your requested toolset. + +Visual Studio 2022 and newer may report the legacy .NET Framework 4.0 projects (`net40` and `SampleCsNet40`) as unsupported. They are only needed for the legacy .NET Framework wrapper; the VS2022 and VS2026 command-line wrappers skip those projects, and you can unload them in the IDE when building the native SDK. If your build fails, then you most likely missing the following optional Visual Studio components: -* ATL support +* MFC/ATL support (for example, `SampleCppMini` uses static MFC in its Visual Studio project) * ARM64 support * Spectre mitigation libraries diff --git a/tools/.vsconfig.vs2022 b/tools/.vsconfig.vs2022 new file mode 100644 index 000000000..48e609352 --- /dev/null +++ b/tools/.vsconfig.vs2022 @@ -0,0 +1,23 @@ +{ + "version": "1.0", + "components": [ + "Microsoft.VisualStudio.Component.Windows10SDK", + "Microsoft.VisualStudio.Component.Windows11SDK.22621", + "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", + "Microsoft.VisualStudio.Component.VC.Tools.ARM", + "Microsoft.VisualStudio.Component.VC.Tools.ARM64", + "Microsoft.VisualStudio.Component.VC.Redist.14.Latest", + "Microsoft.VisualStudio.Component.VC.CMake.Project", + "Microsoft.VisualStudio.Component.VC.ATL", + "Microsoft.VisualStudio.Component.VC.ATL.ARM", + "Microsoft.VisualStudio.Component.VC.ATL.ARM64", + "Microsoft.VisualStudio.Component.VC.ATLMFC", + "Microsoft.VisualStudio.Component.VC.CLI.Support", + "Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset", + "Microsoft.VisualStudio.Component.VC.Llvm.Clang", + "Microsoft.Component.VC.Runtime.UCRTSDK", + "Microsoft.VisualStudio.Workload.NativeDesktop", + "Microsoft.VisualStudio.ComponentGroup.UWP.VC", + "Microsoft.VisualStudio.Workload.Universal" + ] +} diff --git a/tools/.vsconfig.vs2026 b/tools/.vsconfig.vs2026 new file mode 100644 index 000000000..48e609352 --- /dev/null +++ b/tools/.vsconfig.vs2026 @@ -0,0 +1,23 @@ +{ + "version": "1.0", + "components": [ + "Microsoft.VisualStudio.Component.Windows10SDK", + "Microsoft.VisualStudio.Component.Windows11SDK.22621", + "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", + "Microsoft.VisualStudio.Component.VC.Tools.ARM", + "Microsoft.VisualStudio.Component.VC.Tools.ARM64", + "Microsoft.VisualStudio.Component.VC.Redist.14.Latest", + "Microsoft.VisualStudio.Component.VC.CMake.Project", + "Microsoft.VisualStudio.Component.VC.ATL", + "Microsoft.VisualStudio.Component.VC.ATL.ARM", + "Microsoft.VisualStudio.Component.VC.ATL.ARM64", + "Microsoft.VisualStudio.Component.VC.ATLMFC", + "Microsoft.VisualStudio.Component.VC.CLI.Support", + "Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset", + "Microsoft.VisualStudio.Component.VC.Llvm.Clang", + "Microsoft.Component.VC.Runtime.UCRTSDK", + "Microsoft.VisualStudio.Workload.NativeDesktop", + "Microsoft.VisualStudio.ComponentGroup.UWP.VC", + "Microsoft.VisualStudio.Workload.Universal" + ] +} diff --git a/tools/RunMsBuild.bat b/tools/RunMsBuild.bat index 38bab739c..2e6b9bf7a 100644 --- a/tools/RunMsBuild.bat +++ b/tools/RunMsBuild.bat @@ -4,18 +4,46 @@ set TARGETPLATFORM=%1 set CONFIGURATION=%2 set TARGETS=%~3 +call :NormalizeTargets "%TARGETS%" set CUSTOM_PROPS= -if ("%~4" == "") goto endCustomProps +if "%~4" == "" goto endCustomProps set CUSTOM_PROPS=%4 echo Using custom properties file for the build: echo %CUSTOM_PROPS% :endCustomProps call tools\vcvars.cmd +if "%VSTOOLS_NOTFOUND%"=="1" ( + echo. + echo ERROR: Visual Studio was not detected, so the build cannot continue. + echo Install Visual Studio 2019, 2022, or 2026 with the Desktop development with C++ workload, + echo or run tools\setup-buildtools.cmd to install the required build tools and components. + echo To target a specific installed version, set VSTOOLS_VERSION first, for example: + echo set VSTOOLS_VERSION=vs2022 + echo. + exit /b 1 +) set MAXCPUCOUNT=%NUMBER_OF_PROCESSORS% set platform= set SOLUTION=Solutions\MSTelemetrySDK.sln -msbuild %SOLUTION% /target:%TARGETS% /p:BuildProjectReferences=true /maxcpucount:%MAXCPUCOUNT% /detailedsummary /p:Configuration=%CONFIGURATION% /p:Platform=%TARGETPLATFORM% %CUSTOM_PROPS% \ No newline at end of file +msbuild %SOLUTION% /target:%TARGETS% /p:BuildProjectReferences=true /maxcpucount:%MAXCPUCOUNT% /detailedsummary /p:Configuration=%CONFIGURATION% /p:Platform=%TARGETPLATFORM% %CUSTOM_PROPS% +exit /b %ERRORLEVEL% + +:NormalizeTargets +setlocal ENABLEDELAYEDEXPANSION +set "TARGETS_IN=%~1" +set "NORMALIZED_TARGETS=" +for %%T in ("!TARGETS_IN:,=" "!") do ( + set "TARGET=%%~T" + if /I "!TARGET:~-6!"==":Build" set "TARGET=!TARGET:~0,-6!" + if defined NORMALIZED_TARGETS ( + set "NORMALIZED_TARGETS=!NORMALIZED_TARGETS!,!TARGET!" + ) else ( + set "NORMALIZED_TARGETS=!TARGET!" + ) +) +endlocal & set "TARGETS=%NORMALIZED_TARGETS%" +exit /b 0 \ No newline at end of file diff --git a/tools/build-Win10-compact-exp.cmd b/tools/build-Win10-compact-exp.cmd index 96b7f41ac..9b2509aad 100644 --- a/tools/build-Win10-compact-exp.cmd +++ b/tools/build-Win10-compact-exp.cmd @@ -1,3 +1,2 @@ @echo off -cd .. -build-all.bat %CD%\Solutions\build.compact-exp.props +call "%~dp0..\build-all-windows.bat" "%~dp0..\Solutions\build.compact-exp.props" diff --git a/tools/setup-buildtools.cmd b/tools/setup-buildtools.cmd index 890467256..d8a143697 100644 --- a/tools/setup-buildtools.cmd +++ b/tools/setup-buildtools.cmd @@ -38,10 +38,10 @@ if NOT exist "%VSINSTALLER%" ( echo Visual Studio installer: echo %VSINSTALLER% -REM Install optional components required for ARM build - vs2017-BuildTools +REM Install optional components required for supported Windows build targets. if exist "%VSINSTALLDIR%" ( echo Running Visual Studio installer.. - "%VSINSTALLER%" modify --installPath "%VSINSTALLDIR%" --config "%~dp0\.vsconfig.%VSVERSION%" --force --quiet --norestart + "%VSINSTALLER%" modify --installPath "%VSINSTALLDIR%" --config "%~dp0\.vsconfig.vs%VSVERSION%" --force --quiet --norestart ) where /Q vcpkg.exe diff --git a/tools/vcvars.cmd b/tools/vcvars.cmd index 18ae09e0a..ea0ec1c38 100644 --- a/tools/vcvars.cmd +++ b/tools/vcvars.cmd @@ -8,9 +8,34 @@ REM 2. Visual Studio 2017 BuildTools REM 3. Visual Studio 2019 Enterprise REM 4. Visual Studio 2019 Community REM 5. Visual Studio 2019 BuildTools +REM 6. Visual Studio 2022 Enterprise +REM 7. Visual Studio 2022 Professional +REM 8. Visual Studio 2022 Community +REM 9. Visual Studio 2022 BuildTools +REM 10. Visual Studio 2026 Enterprise +REM 11. Visual Studio 2026 Professional +REM 12. Visual Studio 2026 Community +REM 13. Visual Studio 2026 BuildTools REM REM 1st parameter - Visual Studio version + +REM Start from a clean detection state so values left in the shell by a previous +REM run (or the caller environment) can't be mistaken for the result of this run. +REM Only the matching detection path below sets these again; in particular this +REM prevents a stale VSINSTALLDIR/VSVERSION from making callers such as +REM tools\setup-buildtools.cmd act on the wrong install after a failed detection. +set "VSTOOLS_NOTFOUND=" +set "VSINSTALLDIR=" +set "VSDEVCMD=" +set "VSVERSION=" + +REM Remember an explicit version request so we can warn later if detection falls +REM back to a different Visual Studio install than the one that was asked for. +set "VSTOOLS_REQUESTED=" +if "%1" neq "" set "VSTOOLS_REQUESTED=%1" +if not defined VSTOOLS_REQUESTED if "%VSTOOLS_VERSION%" neq "" set "VSTOOLS_REQUESTED=%VSTOOLS_VERSION%" + if "%1" neq "" ( goto %1 ) @@ -84,6 +109,16 @@ if exist "%VSDEVCMD%" ( goto tools_configured ) +:vs2022_professional +SET VSVERSION=2022 +set "VSDEVCMD=%ProgramFiles%\Microsoft Visual Studio\2022\Professional\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles%\Microsoft Visual Studio\2022\Professional" + echo Building with vs2022 Professional... + call "%VSDEVCMD%" + goto tools_configured +) + :vs2022_community SET VSVERSION=2022 set "VSDEVCMD=%ProgramFiles%\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" @@ -94,6 +129,89 @@ if exist "%VSDEVCMD%" ( goto tools_configured ) +:vs2022_buildtools +SET VSVERSION=2022 +set "VSDEVCMD=%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" + echo Building with vs2022 BuildTools... + call "%VSDEVCMD%" + goto tools_configured +) + +:vs2026 +:vs2026_enterprise +SET VSVERSION=2026 +set "VSDEVCMD=%ProgramFiles%\Microsoft Visual Studio\2026\Enterprise\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles%\Microsoft Visual Studio\2026\Enterprise" + echo Building with vs2026 Enterprise... + call "%VSDEVCMD%" + goto tools_configured +) + +set "VSDEVCMD=%ProgramFiles%\Microsoft Visual Studio\18\Enterprise\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles%\Microsoft Visual Studio\18\Enterprise" + echo Building with vs2026 Enterprise... + call "%VSDEVCMD%" + goto tools_configured +) + +:vs2026_professional +SET VSVERSION=2026 +set "VSDEVCMD=%ProgramFiles%\Microsoft Visual Studio\2026\Professional\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles%\Microsoft Visual Studio\2026\Professional" + echo Building with vs2026 Professional... + call "%VSDEVCMD%" + goto tools_configured +) + +set "VSDEVCMD=%ProgramFiles%\Microsoft Visual Studio\18\Professional\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles%\Microsoft Visual Studio\18\Professional" + echo Building with vs2026 Professional... + call "%VSDEVCMD%" + goto tools_configured +) + +:vs2026_community +SET VSVERSION=2026 +set "VSDEVCMD=%ProgramFiles%\Microsoft Visual Studio\2026\Community\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles%\Microsoft Visual Studio\2026\Community" + echo Building with vs2026 Community... + call "%VSDEVCMD%" + goto tools_configured +) + +set "VSDEVCMD=%ProgramFiles%\Microsoft Visual Studio\18\Community\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles%\Microsoft Visual Studio\18\Community" + echo Building with vs2026 Community... + call "%VSDEVCMD%" + goto tools_configured +) + +:vs2026_buildtools +SET VSVERSION=2026 +set "VSDEVCMD=%ProgramFiles(x86)%\Microsoft Visual Studio\2026\BuildTools\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2026\BuildTools" + echo Building with vs2026 BuildTools... + call "%VSDEVCMD%" + goto tools_configured +) + +set "VSDEVCMD=%ProgramFiles(x86)%\Microsoft Visual Studio\18\BuildTools\Common7\Tools\VsDevCmd.bat" +if exist "%VSDEVCMD%" ( + set "VSINSTALLDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\18\BuildTools" + echo Building with vs2026 BuildTools... + call "%VSDEVCMD%" + goto tools_configured +) + echo WARNING:********************************************* echo WARNING: cannot auto-detect Visual Studio version !!! echo WARNING:********************************************* @@ -102,3 +220,20 @@ set VSVERSION= exit /b 0 :tools_configured + +REM Warn if an explicit version was requested but detection fell back to a +REM different Visual Studio install (the label cascade silently moves forward, +REM e.g. a vs2022 request can end up on vs2026), which can lead to a confusing +REM toolset mismatch later when PlatformToolset is pinned to the requested version. +if not defined VSTOOLS_REQUESTED goto :tools_configured_done +if not defined VSVERSION goto :tools_configured_done +echo "%VSTOOLS_REQUESTED%" | findstr /I /C:"%VSVERSION%" >nul +if errorlevel 1 ( + echo WARNING: Requested Visual Studio "%VSTOOLS_REQUESTED%" was not found; using Visual Studio %VSVERSION% instead. + echo WARNING: If a specific toolset is required, install that Visual Studio version or set VSTOOLS_VERSION/PlatformToolset to match what is installed. +) + +:tools_configured_done +REM Visual Studio was configured; callers rely on VSTOOLS_NOTFOUND rather than +REM this script's exit code, so return success regardless of the version probe. +exit /b 0