build: find version of Clang installed on Windows

PR-URL: https://github.com/nodejs/node/pull/53228
Refs: https://github.com/nodejs/node/issues/52809
Reviewed-By: Michaël Zasso <targos@protonmail.com>
pull/53592/head
Stefan Stojanovic 2024-06-11 19:37:26 +02:00 committed by Michaël Zasso
parent 24c7a9415b
commit c7d44ba1f3
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
3 changed files with 37 additions and 5 deletions

View File

@ -642,7 +642,7 @@ Optional requirements to build the MSI installer package:
* The .NET SDK component from [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/)
* This component can be installed via the Visual Studio Installer Application
Optional requirements for compiling for Windows 10 on ARM (ARM64):
Optional requirements for compiling for Windows on ARM (ARM64):
* Visual Studio 17.6.0 or newer
* Visual Studio optional components
@ -650,6 +650,14 @@ Optional requirements for compiling for Windows 10 on ARM (ARM64):
* Visual C++ ATL for ARM64
* Windows 10 SDK 10.0.17763.0 or newer
Optional requirements for compiling with ClangCL:
* Visual Studio optional components
* C++ Clang Compiler for Windows
* MSBuild support for LLVM toolset
NOTE: Currently we only support compiling with Clang that comes from Visual Studio.
##### Option 2: Automated install with Boxstarter
A [Boxstarter](https://boxstarter.org/) script can be used for easy setup of

View File

@ -13,11 +13,16 @@ if not exist "%InstallerPath%" goto :no-vswhere
set "Path=%Path%;%InstallerPath%"
where vswhere 2> nul > nul
if errorlevel 1 goto :no-vswhere
:: VC.Tools are needed even when using clang because of the vcvarsall.bat usage
if "%2"=="arm64" (
set VSWHERE_REQ=-requires Microsoft.VisualStudio.Component.VC.Tools.ARM64
) else (
set VSWHERE_REQ=-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64
)
if "%4"=="1" (
set VSWHERE_REQ=%VSWHERE_REQ% -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang
set VSWHERE_REQ=%VSWHERE_REQ% -requires Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset
)
set VSWHERE_PRP=-property installationPath
set VSWHERE_LMT=-version %1
vswhere -prerelease > nul

View File

@ -187,8 +187,6 @@ if defined nosnapshot set configure_flags=%configure_flags% --without-snap
if defined nonpm set configure_flags=%configure_flags% --without-npm
if defined nocorepack set configure_flags=%configure_flags% --without-corepack
if defined ltcg set configure_flags=%configure_flags% --with-ltcg
:: If clang-cl build is requested, set it to 17.0, which is the version shipped with VS 2022.
if defined clang_cl set configure_flags=%configure_flags% --clang-cl=17.0
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
if defined download_arg set configure_flags=%configure_flags% %download_arg%
if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
@ -254,7 +252,7 @@ echo Looking for Visual Studio 2022
@rem cleared first as vswhere_usability_wrapper.cmd doesn't when it fails to
@rem detect the version searched for
if not defined target_env set "VCINSTALLDIR="
call tools\msvs\vswhere_usability_wrapper.cmd "[17.6,18.0)" %target_arch% "prerelease"
call tools\msvs\vswhere_usability_wrapper.cmd "[17.6,18.0)" %target_arch% "prerelease" %clang_cl%
if "_%VCINSTALLDIR%_" == "__" goto msbuild-not-found
@rem check if VS2022 is already setup, and for the requested arch
if "_%VisualStudioVersion%_" == "_17.0_" if "_%VSCMD_ARG_TGT_ARCH%_"=="_%target_arch%_" goto found_vs2022
@ -274,13 +272,34 @@ set PLATFORM_TOOLSET=v143
goto msbuild-found
:msbuild-not-found
echo Failed to find a suitable Visual Studio installation.
set "clang_echo="
if defined clang_cl set "clang_echo= or Clang compiler/LLVM toolset"
echo Failed to find a suitable Visual Studio installation%clang_echo%.
echo Try to run in a "Developer Command Prompt" or consult
echo https://github.com/nodejs/node/blob/HEAD/BUILDING.md#windows
goto exit
:msbuild-found
@rem check if the clang-cl build is requested
if not defined clang_cl goto clang-skip
@rem x64 is hard coded as it is used for both cross and native compilation.
set "clang_path=%VCINSTALLDIR%\Tools\Llvm\x64\bin\clang.exe"
for /F "tokens=3" %%i in ('"%clang_path%" --version') do (
set clang_version=%%i
goto clang-found
)
:clang-not-found
echo Failed to find Clang compiler in %clang_path%.
goto exit
:clang-found
echo Found Clang version %clang_version%
set configure_flags=%configure_flags% --clang-cl=%clang_version%
:clang-skip
set project_generated=
:project-gen
@rem Skip project generation if requested.