bazelbuild / bazelbuild/bazel

Allow configuring different compilers for C and C++

Open
#4,644 22 comments 20 reactions 0 assignees View on GitHub
not stale P4 team-Rules-CPP type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the problem / feature request:
Allow configuring separate compiler executables when targeting C and C ++respectively, and make this information accessible in Skylark (e.g. add it to the cpp fragment). Having them be declared by CC/CXX would be nice, but that might break a lot of stuff since CC is already used to configure the C++ compiler.

### Feature requests: what underlying problem are you trying to solve with this feature?
From what I understand the cc_toolchain is supposed to configure both the C++ and C toolchain, but it only allows specifying one compiler executable. This means that in cases where one might want to use g++ as the C++ compiler, you will no longer be able to build C files (without providing a secondary toolchain? I'm a bit fuzzy here). This is a real problem, see for example https://github.com/envoyproxy/envoy/issues/839. Envoy uses g++/clang++ instead of gcc/clang to work around https://github.com/bazelbuild/bazel/issues/2840

### Have you found anything relevant by searching the web?

Looked at the cpp fragment docs and asked around in IRC. Everything seems to assume that the compiler given to the cc_toolchain can handle both C++ and C.

If this seems like a reasonable idea I'm happy to attempt to get this working.

Contributor guide

Open the contributing guide

Research direction

Read the cc_toolchain and cpp fragment documentation referenced in the issue, then trace how the compiler executable is configured and exposed in Skylark. Done means C and C++ can use separate configured compiler executables while preserving existing CC behavior, with both language targets covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.