Bazel: Clang for Windows support

Created on 9 Mar 2018  路  10Comments  路  Source: bazelbuild/bazel

Description of the problem / feature request:

Setting env CC doesn't work on Windows and are thus unable to specify something other than an MSVC toolchain. I'd like to see support for 'clang' and 'clang-cl'.

Feature requests: what underlying problem are you trying to solve with this feature?

To be able to use bazel on Windows to compile C/C++ programs with LLVM/Clang for Windows.

What operating system are you running Bazel on?

Windows 10

Have you found anything relevant by searching the web?

The most relevant answer on web is this link:
https://stackoverflow.com/questions/47624689/how-to-set-c-compiler-on-os-x-with-bazel

But setting CC as suggested in the answer does not work on Windows. It seems to be ignored entirely and uses MSVC despite the environment value.

P4 windows team-Rules-CPP feature request

All 10 comments

@meteorcloudy : WDYT? Is this feasible? Is this in scope?

+1 for the feature request. LibreOffice does that: [1], Mozilla does that: [2] and that makes a lot of sense to offer such custom toolchain for Bazel.

[1] https://wiki.documentfoundation.org/Development/clang-cl
[2] https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Building_Firefox_on_Windows_with_clang-cl

@xgalaxy We have a different cc configure mechanism on Windows.

It would be great to have clang support on Window. And I believe Bazel itself already have all features for supporting it on Windows. But we need someone who have knowledge on how to write the CROSSTOOL. I can try to do that when I have time.

+1

+1

I'm trying to support clang-cl.exe on Windows, please see #6553.

https://github.com/bazelbuild/bazel/pull/6553#issue-226949824 describes how to use clang-cl on Windows and it seems to be working correctly. However, Visual C++ build tools are still required. It would be nice to extend it to switch more things from Visual C++ build tools to LLVM tools so that the Visual C++ build tools are not required.

Just as clarification, the LLVM toolchain is incomplete, and specific tools from the VC++ toolchain will continue to be required.

A second caution, the clang-cl toolchain provided by Microsoft is completely incapable of 64-bit assembly. It is a 32 bit compiler distributed in a 32 bit .exe, and the -m64 flag cannot be used to produce the desired output. It looks like only the LLVM flavor can be supported.

Further follow-up, as comments above were somewhat confused; the projects mentioned above are using the clang-cl compiler.

This is now supported and must be understood as different-than-"clang", because clang-cl uses the MSVC cl.exe command line conventions, requiring that windows-specific toolchain;
https://docs.bazel.build/versions/3.7.0/windows.html#build-c-with-clang

Supporting CC=clang implies using the build toolchain following cygwin/mingw/msys2 conventions. Possible and perhaps trivial in theory. A top-line issue title "Support CC=clang on Windows" might make this issue clearer?

Was this page helpful?
0 / 5 - 0 ratings