Skip to content
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

Document @bazel_tools//tools/cpp:compiler and provide canonical compiler config_settings for each toolchain which Bazel autoconfigures #14914

Closed
trybka opened this issue Feb 25, 2022 · 3 comments · Fixed by bazelbuild/rules_cc#167
Labels
help wanted Someone outside the Bazel team could own this P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Documentation Documentation improvements that cannot be directly linked to other team labels team-Rules-CPP Issues for C++ rules type: documentation (cleanup)

Comments

@trybka
Copy link
Contributor

trybka commented Feb 25, 2022

Description of the problem / feature request:

@bazel_tools//tools/cpp:compiler is an undocumented target which provides the compiler attribute from the cc_toolchain currently in use. It is a Starlark rule defined here: tools/cpp/compiler_flag.bzl

This feature should be documented and supported for use in config_setting targets.

Ideally it would be easy to find from here: https://bazel.build/docs/integrating-with-rules-cc

In addition, it would be useful if well-known config_setting targets were provided for each value of cc_toolchain.compiler in use within the Bazel-provided toolchains.

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

Due to compiler differences, some flags need to be spelled differently depending on the compiler.

An example is gcc/clang vs. msvc/clang-cl:
When setting the C++ target std, gcc/clang expect -std=c++20 whereas msvc/clang-cl expect /std:c++20.
Unfortunately selecting on @platforms//os:windows as a target is not sufficient--clang and/or mingw cross compilation would need the former set of flags, despite targeting Windows.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Note: I am filing this bug on behalf of some other folks after a discussion on Slack, so my repro instructions might be a little vague.

Create a cc_library:


cc_library(
  name = "foo",
  ...
  copts = select({
      "@platforms//os:windows": ["/std:c++20"],
      "//conditions:default": ["-std=c++20"],
   }),
   ...
)

bazel build --compiler=mingw-gcc //...:foo_bin

What operating system are you running Bazel on?

Windows

What's the output of bazel info release?

IDK, current? Issue exists at tip-of-tree.

Have you found anything relevant by searching the web?

#12897

@trybka
Copy link
Contributor Author

trybka commented Feb 25, 2022

#14376 is related, too

@aiuto aiuto added team-Rules-CPP Issues for C++ rules untriaged labels Feb 26, 2022
@oquenchil oquenchil added type: documentation (cleanup) P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Apr 6, 2022
@keertk keertk added the team-Documentation Documentation improvements that cannot be directly linked to other team labels label Jan 10, 2023
@keertk keertk added the help wanted Someone outside the Bazel team could own this label Jan 17, 2023
@davidben
Copy link

For BoringSSL, we would also appreciate this to be documented. Managing a Bazel build has been disproportionately difficult for us, particularly around figuring out which platform or toolchain we're being asked to build for.

I gather from Abseil that this is indeed the way you detect the compiler. But if this isn't documented anywhere, we're stuck mimicking others and making educated guesses. Having clear documentation for the expected patterns here would go a long way towards catching Bazel up to other tools in usability.

@fmeum
Copy link
Collaborator

fmeum commented Jul 6, 2023

I have this pending change: bazelbuild/rules_cc#167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Someone outside the Bazel team could own this P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Documentation Documentation improvements that cannot be directly linked to other team labels team-Rules-CPP Issues for C++ rules type: documentation (cleanup)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants