@@ -187,8 +187,6 @@ if defined nosnapshot set configure_flags=%configure_flags% --without-snap
187187if defined nonpm set configure_flags = %configure_flags% --without-npm
188188if defined nocorepack set configure_flags = %configure_flags% --without-corepack
189189if defined ltcg set configure_flags = %configure_flags% --with-ltcg
190- :: If clang-cl build is requested, set it to 17.0, which is the version shipped with VS 2022.
191- if defined clang_cl set configure_flags = %configure_flags% --clang-cl=17.0
192190if defined release_urlbase set configure_flags = %configure_flags% --release-urlbase=%release_urlbase%
193191if defined download_arg set configure_flags = %configure_flags% %download_arg%
194192if defined enable_vtune_arg set configure_flags = %configure_flags% --enable-vtune-profiling
@@ -254,7 +252,7 @@ echo Looking for Visual Studio 2022
254252@ rem cleared first as vswhere_usability_wrapper.cmd doesn't when it fails to
255253@ rem detect the version searched for
256254if not defined target_env set " VCINSTALLDIR = "
257- call tools\msvs\vswhere_usability_wrapper.cmd " [17.6,18.0)" %target_arch% " prerelease"
255+ call tools\msvs\vswhere_usability_wrapper.cmd " [17.6,18.0)" %target_arch% " prerelease" %clang_cl%
258256if " _%VCINSTALLDIR% _" == " __" goto msbuild-not-found
259257@ rem check if VS2022 is already setup, and for the requested arch
260258if " _%VisualStudioVersion% _" == " _17.0_" if " _%VSCMD_ARG_TGT_ARCH% _" == " _%target_arch% _" goto found_vs2022
@@ -274,13 +272,34 @@ set PLATFORM_TOOLSET=v143
274272goto msbuild-found
275273
276274:msbuild-not-found
277- echo Failed to find a suitable Visual Studio installation.
275+ set " clang_echo = "
276+ if defined clang_cl set " clang_echo = or Clang compiler/LLVM toolset"
277+ echo Failed to find a suitable Visual Studio installation%clang_echo% .
278278echo Try to run in a " Developer Command Prompt" or consult
279279echo https://github.com/nodejs/node/blob/HEAD/BUILDING.md#windows
280280goto exit
281281
282282:msbuild-found
283283
284+ @ rem check if the clang-cl build is requested
285+ if not defined clang_cl goto clang-skip
286+ @ rem x64 is hard coded as it is used for both cross and native compilation.
287+ set " clang_path = %VCINSTALLDIR% \Tools\Llvm\x64\bin\clang.exe"
288+ for /F " tokens=3" %%i in ('" %clang_path% " --version') do (
289+ set clang_version = %%i
290+ goto clang-found
291+ )
292+
293+ :clang-not-found
294+ echo Failed to find Clang compiler in %clang_path% .
295+ goto exit
296+
297+ :clang-found
298+ echo Found Clang version %clang_version%
299+ set configure_flags = %configure_flags% --clang-cl=%clang_version%
300+
301+ :clang-skip
302+
284303set project_generated =
285304:project-gen
286305@ rem Skip project generation if requested.
0 commit comments