bazel-contrib / bazel-contrib/toolchains_llvm

c++-compile action should use clang++ instead of clang.

Open
#372 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
371
Forks
283
Avg merge
1d 55m
Merged PRs (30d)
25

Description

Hi,
Thank you for the work on the project so far. It makes cc toolchain configuration much easier.

I've noticed that some builds fail with linker errors, for instance, compiling `cc_test` with `com_google_google_test` fails with
```
ld.lld: error: undefined reference due to --no-allow-shlib-undefined: nextafter
```

This is related to https://github.com/google/googletest/issues/3878

I think the problem is as described in the issue above - compiling c++ should use clang++.

This might be, however, problematic as it goes down to bazel implementation of [default actions](https://github.com/bazelbuild/bazel/blob/5156558beb0ab639f9bfd17856b42d6ef32d5017/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java#L1129) that is using `gcc` instead of `g++`.

It is possible to override the action configs in `cc_common.create_cc_toolchain_config_info`, but [unix_cc_toolchain_config](https://github.com/bazelbuild/bazel/blob/master/tools/cpp/unix_cc_toolchain_config.bzl) does not expose it.

I did some rough experiment and replaced clang with clang++ in https://github.com/bazel-contrib/toolchains_llvm/blob/master/toolchain/cc_wrapper.sh.tpl and that did the trick. This is not a generic solution though, as it would fail c compilation.

**On the bright side**, the workaround is to add `-lm` to `cc_test` linkopts or link_flags of cc toolchain configuration.

Perhaps we should start with exposing `action_configs` in unix_cc_toolchain_config and then override the cpp actions in toolchains_llvm. Alternative would be to inline unix_cc_toolchain_config into toolchains_llvm.

Looking forward to your feedback.

Contributor guide

Open the contributing guide

Research direction

Read toolchain/cc_wrapper.sh.tpl and the Bazel unix_cc_toolchain_config and default action configs referenced in the issue. Reproduce the com_google_googletest cc_test linker failure, then determine how to make C++ linking use the correct driver without breaking C compilation. Done means the failing case no longer needs the -lm workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.