Skip to content

Detect cc as the underlying gcc or clang #23119

Open
@tyler-yankee

Description

@tyler-yankee

On Linux, Drake's CMake logic tries to explicitly set the compiler to pass to Bazel via --repo_env, a la:

drake/CMakeLists.txt

Lines 293 to 298 in 62023e3

if(NOT APPLE)
string(APPEND BAZEL_REPO_ENV
" --repo_env=CC=${CMAKE_C_COMPILER}"
" --repo_env=CXX=${CMAKE_CXX_COMPILER}"
)
endif()

When compiling with CMAKE_{C|CXX}_COMPILER=/usr/bin/{cc|c++} (default in many cases), Bazel's rules_cc doesn't know to try and detect what the compiler actually is (gcc/clang). So the build will still be fine, but none of the Bazel logic specific to gcc or clang will be applied.

From a quick investigation, passing something like --repo_env=CC=$(realpath /usr/bin/cc) doesn't quite do it. We already have a lot of CMake logic to parse the compiler type and version (mostly to warn about what is unsupported); that logic just needs an extra tweak to (try and) detect the appropriate underlying compiler to pass to Bazel.

Metadata

Metadata

Assignees

Labels

component: build systemBazel, CMake, dependencies, memory checkers, linters

Type

No type

Projects

Status

In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions