@@ -22,13 +22,37 @@ for /f "usebackq tokens=*" %%i in (`%vswhere% -latest -products * -requires Micr
2222 set vs_install_dir = %%i
2323)
2424
25- call " %vs_install_dir% \Common7\Tools\vsdevcmd.bat" /no_logo
25+ if exist " %vs_install_dir% \VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" (
26+ set /p Version = < " %vs_install_dir% \VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
27+ set LatestVCToolsVersion = !Version: =!
28+ )
29+
30+
31+ set " msvc_root = %vs_install_dir% \VC\Tools\MSVC"
32+ set " chosen_minor = 0"
33+ set " chosen_patch = 0"
34+
35+ :: Iterate over all MSVC versions installed
36+ for /f " delims=" %%v in ('dir /b /ad " %msvc_root% " ') do (
37+ call :check_version " %%v "
38+ )
39+
40+ if not defined chosen_version (
41+ echo ERROR: MSVC version less than or equal to 14.43 not found
42+ exit 1
43+ )
44+
45+ echo INFO: using chosen version !chosen_version!
46+
47+ call " %vs_install_dir% \Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64 -no_logo -vcvars_ver=!chosen_version!
2648
2749if " %VCToolsInstallDir% " == " " (
2850 echo ERROR: missing VCToolsInstallDir after running vsdevcmd.bat
2951 exit 1
3052)
3153
54+ echo INFO: using vs tools %VCToolsVersion%
55+
3256set vs_tools_dir = %VCToolsInstallDir%
3357
3458if exist .cache\repos\cppfront\ (
@@ -152,3 +176,38 @@ cl /nologo "%root_dir%.cache/cpp2/source/src/main.cpp" ^
152176if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%
153177
154178echo %cpp2b_dist% .exe
179+
180+ :: -------------------------------
181+ :: Subroutine: check_version
182+ :: %1 = version string like 14.43.32706
183+ :: -------------------------------
184+ :check_version
185+ set " ver = %~1 "
186+ for /f " tokens=1-3 delims=." %%a in (" !ver! " ) do (
187+ set " major = %%a "
188+ set " minor = %%b "
189+ set " patch = %%c "
190+ )
191+
192+ if " %major% " == " 14" (
193+ set /a m = ! minor!
194+ set /a p = ! patch!
195+ if !m! LEQ 43 (
196+ if not defined chosen_version (
197+ set " chosen_version = !ver! "
198+ set " chosen_minor = !m! "
199+ set " chosen_patch = !p! "
200+ ) else (
201+ if !m! GTR !chosen_minor! (
202+ set " chosen_version = !ver! "
203+ set " chosen_minor = !m! "
204+ set " chosen_patch = !p! "
205+ ) else if !m! EQU !chosen_minor! if !p! GTR !chosen_patch! (
206+ set " chosen_version = !ver! "
207+ set " chosen_minor = !m! "
208+ set " chosen_patch = !p! "
209+ )
210+ )
211+ )
212+ )
213+ goto :eof
0 commit comments