Skip to content

Support building with win-clang #19630

Description

@hashseed

Chrome and V8 support building with Clang on windows. Node.js should include support for this too.

Benefits:

  • Future proof. Chrome is already deprecating MSVC build. V8 might do the same in the long-term.
  • No more dependency on installing Visual Studio. Clang is open source.

Blockers:

  • Expose clang build in configure.
  • Official way to build V8 on Windows is to use ninja. However, gyp backend for ninja only supports MSVC.
  • openssl.gyp requires llvm_version to be set.
  • Actually fetching Clang. This is done in V8 through python .\deps\v8\tools\clang\scripts\update.py.
  • Version and macro detection does not work with clang-cl.exe.

Activity

  1. hashseed commented on Mar 27, 2018

    @hashseed
    MemberAuthor
  2. added
    windowsIssues and PRs related to the Windows platform.
    buildIssues and PRs related to Node.js builds or CI infrastructure.
    on Mar 27, 2018
  3. targos commented on Mar 27, 2018

    @targos
    Member

    /cc @nodejs/platform-windows

  4. seishun commented on Mar 30, 2018

    @seishun
    Contributor

    Official way to build V8 on Windows is to use ninja. However, gyp backend for ninja only supports MSVC.

    How can we solve this?

  5. hashseed commented on Mar 30, 2018

    @hashseed
    MemberAuthor

    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.

  6. seishun commented on Mar 30, 2018

    @seishun
    Contributor

    You mean implementing it in gyp?

  7. bnoordhuis commented on Mar 31, 2018

    @bnoordhuis
    Member

    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
    }
    # ...
  8. nico commented on Apr 5, 2018

    @nico

    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).

  9. hashseed commented on Apr 17, 2018

    @hashseed
    MemberAuthor

    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

  10. refack commented on Apr 17, 2018

    @refack
    Contributor

    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.
      image1

    • There might be conflicting interests with the @nodejs/chakracore team. But IMHO that should be upstreamed to V8 & Chromium.

  11. hashseed commented on Apr 17, 2018

    @hashseed
    MemberAuthor

    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 :)

  12. gibfahn commented on Apr 19, 2018

    @gibfahn
    Member

    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?

  13. hashseed commented on Apr 30, 2018

    @hashseed
    MemberAuthor

    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
    • 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.

  14. seishun commented on Apr 30, 2018

    @seishun
    Contributor

    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]
    
  15. 20 remaining items

  16. self-assigned this
    on Oct 17, 2018
  17. refack commented on Oct 17, 2018

    @refack
    Contributor

    This is an interesting issue, I'll try to pick it...

  18. refack commented on Oct 23, 2018

    @refack
    Contributor

    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.

  19. refack commented on Oct 26, 2018

    @refack
    Contributor

    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

  20. added a commit that references this issue on Nov 3, 2018
  21. added a commit that references this issue on Nov 5, 2018
  22. jasnell commented on Jun 25, 2020

    @jasnell
    Member

    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

  23. aminya commented on Oct 1, 2020

    @aminya

    This is a very necessary feature. MSVC is not an optimized compiler. Can we open this again?

    https://www.youtube.com/watch?v=8e7IdHG5fhQ

  24. removed their assignment
    on Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildIssues and PRs related to Node.js builds or CI infrastructure.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo