Repository navigation
Support building with win-clang #19630
Description
Activity
/cc @targos
/cc @nodejs/platform-windows
Official way to build V8 on Windows is to use ninja. However, gyp backend for ninja only supports MSVC.
How can we solve this?
Good question. One of the reasons for moving off gyp is scenarios like this where new toolchains are not supported. I guess implementing support for ninja with clang on Windows would be a way. It might be not all that complicated, if clang on Windows works the same way as clang on linux.
You mean implementing it in gyp?
I suspect this already works when you use clang-cl, the cl.exe compatible driver.
Untested, but configure would need to write out a make_global_settings stanza to config.gypi that looks like this and will be picked up by the ninja generator:
# ...
'make_global_settings': {
'CC': '/path/to/clang-cl', # or just 'clang-cl' if it's on the path
'CXX': '/path/to/clang-cl', # ditto
}
# ...bnoordhuis's comment is correct, except you don't need to set CXX since the ninja generator doesn't look at that in msvc compat mode (cf https://chromium.googlesource.com/external/gyp/+/e540e6ab6291d4e63f262c8169ef0d0aae11dbec / https://codereview.chromium.org/147083011 for how we hooked up clang-cl in the Chromium gyp win build back in the day).
The amazing @agrieve from the Chrome team has come up with this PR (against the fork of Node.js that V8 is maintaining) to make building with Clang on Windows work!
We could use some feedback on whether this way to build works well for everyone, similar to when I initially implemented the --build-v8-with-gn configure flag. @seishun @targos
Although as @bnoordhuis mentions there are workarounds for cmake/ninja/GYP/Windows, I'll look into getting that to work out of the box.
-
This still does not remove the VisualStudio dependency per se, since clang-win / clang-cl and the Windows SDK are still interdependent, so IMHO the more "interesting" issue IMHO is smooth integration with the Windows SDK.
1 -
There might be conflicting interests with the @nodejs/chakracore team. But IMHO that should be upstreamed to V8 & Chromium.
There might be conflicting interests with the @nodejs/chakracore team. But IMHO that should be upstreamed to V8 & Chromium.
My interpretation is that having alternatives is always great :)
So if this doesn't remove the dependency on Visual Studio, the only benefit would be that we'd have to do this at some point if V8 drop support for MSVC?
FWIW we have a fork of Node that can fully build with clang-cl on Windows.
It still requires Visual Studio and some dependencies to be installed.
The benefit of that build is that the gyp-gn bridge works on that build. I.e. gyp files do not need to be maintained when updated to a new V8 version. It is also guaranteed to build if V8 decides to deprecate MSVC support in the future. This is relevant when MSVC and Clang differ in how they interpret C++ syntax.
Dependencies:
- Git
- Python 2.7
- Pywin32
- Visual Studio 2017, "Desktop development with C++". Make sure to include:
- Windows 10 SDK (10.0.15063) for Desktop C++. This version is hardcoded in to
deps/v8/build/toolchain/win/setup_toolchain.py. - Visual C++ ATL support
- Windows 10 SDK (10.0.15063) for Desktop C++. This version is hardcoded in to
- Debugging Tools for Windows SDK (as found here)
Build steps:
python configure --build-v8-with-gn --use-clang-cl --ninja
deps\v8\_depot_tools\ninja -C out\Release node
There is obviously still a bit of a way to go here.
What also doesn't work is that add-on tests do not have a ninja target, and npm install probably doesn't work with clang-cl.
Edit: missing dependency.
The list of dependencies seems incomplete. I'm getting the following error:
Details
FAILED: obj/deps/v8/gypfiles/v8_monolith.gen/gn/build.ninja
C:\Python27\python.exe gyp-win-tool action-wrapper environment.x64 v8_monolith_target_build_with_gn_generate_build_files_f3270641800ff32515e443515bf752cc..rsp ..\..\deps\v8\gypfiles
Traceback (most recent call last):
File "C:/Users/Nikolai/node/deps/v8/build/vs_toolchain.py", line 482, in <module>
sys.exit(main())
File "C:/Users/Nikolai/node/deps/v8/build/vs_toolchain.py", line 478, in main
return commands[sys.argv[1]](*sys.argv[2:])
File "C:/Users/Nikolai/node/deps/v8/build/vs_toolchain.py", line 306, in CopyDlls
_CopyDebugger(target_dir, target_cpu)
File "C:/Users/Nikolai/node/deps/v8/build/vs_toolchain.py", line 337, in _CopyDebugger
' 10 SDK.' % (debug_file, full_path))
Exception: dbghelp.dll not found in "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll"
You must install the "Debugging Tools for Windows" feature from the Windows 10 SDK.
ERROR at //build/toolchain/win/BUILD.gn:43:3: Script returned non-zero exit code.
exec_script("../../vs_toolchain.py",
^----------
Current dir: C:/Users/Nikolai/node/out/Release/obj/deps/v8/gypfiles/v8_monolith.gen/gn/
Command: C:/Python27/python.exe -- C:/Users/Nikolai/node/deps/v8/build/vs_toolchain.py copy_dlls C:/Users/Nikolai/node/out/Release/obj/deps/v8/gypfiles/v8_monolith.gen/gn Release x64
Returned 1.
See //BUILD.gn:618:1: which caused the file to be included.
action("js2c") {
^---------------
Traceback (most recent call last):
File "..\tools\node\build_gn.py", line 141, in <module>
GenerateBuildFiles(options)
File "..\tools\node\build_gn.py", line 75, in GenerateBuildFiles
subprocess.check_call(args)
File "C:\Python27\lib\subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['C:\\Users\\Nikolai\\node\\deps\\v8\\buildtools\\win\\gn', 'gen', 'C:\\Users\\Nikolai\\node\\out\\Release\\obj\\deps\\v8\\gypfiles\\v8_monolith.gen\\gn', '-q', '--args=v8_monolithic=true is_component_build=false v8_use_external_startup_data=false use_custom_libcxx=false v8_promise_internal_field_count=true target_cpu="x64" target_os="win" v8_target_cpu="x64" v8_embedder_string="-node.4" v8_use_snapshot=true v8_optimized_debug=false v8_enable_disassembler=true v8_postmortem_support=false is_debug=false clang_base_path="C:\\Users\\Nikolai\\node\\deps\\v8\\third_party\\llvm-build\\Release+Asserts"']' returned non-zero exit status 1
I'm also getting a warning on every file, is that a known issue?
[20/664] CC obj\deps\openssl\openssl\crypto\ecdsa\openssl.ecs_err.obj
clang-cl.exe: warning: argument unused during compilation: '/GL' [-Wunused-command-line-argument]
[21/664] CC obj\deps\openssl\openssl\crypto\engine\openssl.tb_rand.obj
clang-cl.exe: warning: argument unused during compilation: '/GL' [-Wunused-command-line-argument]
[22/664] CC obj\deps\openssl\openssl\crypto\ecdh\openssl.ech_kdf.obj
clang-cl.exe: warning: argument unused during compilation: '/GL' [-Wunused-command-line-argument]
[23/664] CC obj\deps\openssl\openssl\crypto\ec\openssl.ecp_oct.obj
clang-cl.exe: warning: argument unused during compilation: '/GL' [-Wunused-command-line-argument]
20 remaining items
This is an interesting issue, I'll try to pick it...
Actually fetching Clang. This is done in V8 through python .\deps\v8\tools\clang\scripts\update.py.
IIUC non googlers can't do that. The docs say "install MSVS and set DEPOT_TOOLS_WIN_TOOLCHAIN=0"
But I'm making progress using the "official" prebuilt llvm binaries, and the ninja-msvs GYP generator.
found a bug in V8's src/base/debug/stack_trace_win.cc (mix and max MACROS breaking compilation with "official" prebuilt llvm binaries).
CL: https://chromium-review.googlesource.com/c/v8/v8/+/1297479
There's been no further activity on this and it's not clear if it's going to move forward. Closing but we can reopen if necessary
This is a very necessary feature. MSVC is not an optimized compiler. Can we open this again?
Chrome and V8 support building with Clang on windows. Node.js should include support for this too.
Benefits:
Blockers:
configure.ninja. However,gypbackend forninjaonly supports MSVC.openssl.gyprequiresllvm_versionto be set.python .\deps\v8\tools\clang\scripts\update.py.clang-cl.exe.