-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cmake uses C++ compilation flags for linking #1133
Comments
I think for the case of passing in |
Yeah I was thinking something like that too, but indeed detecting whether it is being invoked as a compiler or as a linker could be brittle, most of the time the only difference in the command line seems to be the input filename extensions. Alternatively, we could specify our own custom linker flags, something that is then picked up by the wrapper script and removed before invoking the underlying linker. |
This is a not-very-elegant workaround for bazelbuild#1133.
There's an issue that affects some CMake projects, nameli X265 and AOM, that is that they use the C++ compiler for linking, which means they also pick up all CXX_FLAGS from the crosstool file. When the CC toolchain configures
CXX_FLAGS
to include-x c++
, this gets passed to the toolchain config asCMAKE_CXX_FLAGS_INIT
, which ends up being used in the link step too, as described in the relevant CMake documentation.The issue here seems to be that in Bazel,
CXX_FLAGS
are meant for compilation only, and not for linking, and thus passing them on to the toolchain file asCMAKE_CXX_FLAGS_INIT
isn't the right thing to do probably.I could work around this issue by modifying
@rules_foreign_cc
to instead pass the compile flags usingadd_compile_options
, but I was doing that manually for this single flag, and I had to also remove it from theCMAKE_CXX_FLAGS_INIT
:add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-xc++>)
There should be a better way to specify compile flags and link flags, by translating the Bazel toolchain info to the appropriate options in the toolchain file, rather than setting these INIT flags that end up being used for both compilation and linking. In general, the toolchain file should be constructed somehow… in a better way, but I'm not sure how or what is the right mapping from Bazel toolchain info values to CMake options.
For the case of
-xc++
this simple workaround is sufficient, but it would be better to come up with a more complete solution. I'd be happy to contribute this if someone could help figure out what's the right mapping from Bazel features to CMake options.There's some more detail in tweag/rules_nixpkgs#467.
The text was updated successfully, but these errors were encountered: