feat: select the GCC version through a build flag - #239
Merged
Conversation
Register every GCC version in AVAILABLE_GCC_VERSIONS as a toolchain and let --@gcc_toolchain//toolchain:gcc_version pick which one resolves. Leaving the flag unset keeps using the gcc_version the toolchain was declared with. Toolchain resolution has to load every registered toolchain() target, so declaring all versions in the repository that downloads the compiler would fetch every tarball on any build. The toolchain() declarations therefore move to a lightweight hub repository that keeps the name the toolchain was declared with, while each version gets its own repository holding the cc_toolchain. Only the selected version is ever fetched. The hub also aliases the public targets of the selected version, so labels such as @gcc_toolchain_x86_64//:libstdcxx keep resolving and follow the flag. Each version additionally gets a //toolchain:gcc_version_* config_setting so builds can branch on the selected compiler. //tests/gcc_version asserts the compiler reports the requested version, and CI runs the full suite against every version. GCC 12.5.0, 13.4.0 and 14.3.0 are built without ld.lld, so //tests/lld is marked incompatible with them and is skipped rather than failing.
There was a problem hiding this comment.
Pull request overview
Adds build-flag-based GCC version selection while lazily fetching only the selected compiler.
Changes:
- Introduces per-version toolchains and a lightweight selection hub.
- Adds version and linker compatibility tests across CI.
- Documents compiler selection and maintenance workflows.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
toolchain/defs.bzl |
Implements versioned repositories and hub selection. |
toolchain/BUILD.bazel |
Defines the GCC version flag and settings. |
tests/lld/BUILD.bazel |
Skips unsupported GCC versions. |
tests/gcc_version/main.c |
Verifies the compiler version. |
tests/gcc_version/BUILD.bazel |
Configures version assertions. |
MODULE.bazel |
Registers all generated toolchains. |
docs/updating-gcc-builds.md |
Updates maintenance instructions. |
docs/README.md |
Documents version selection. |
docs/defs.md |
Updates generated API documentation. |
.github/workflows/default.yaml |
Tests every available GCC version. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Forward an explicitly empty target_compatible_with to the hub instead of discarding it, so callers can still drop the default Linux/CPU constraints. - Forward repo_mapping to the hub as well, whose BUILD file also resolves @bazel_skylib, @platforms and @rules_cc. - Document target_compatible_with, extra_target_compatible_with and target_settings on gcc_declare_toolchain, since they no longer appear on the gcc_toolchain repository rule. - Register @gcc_toolchain_<arch>//:all in the Bzlmod example, which otherwise has no matching toolchain for any non-default version. - Stop describing a gcc_version set on the declaration as a permanent pin; the flag still overrides it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Register every GCC version in AVAILABLE_GCC_VERSIONS as a toolchain and let --@gcc_toolchain//toolchain:gcc_version pick which one resolves. Leaving the flag unset keeps using the gcc_version the toolchain was declared with.
Toolchain resolution has to load every registered toolchain() target, so declaring all versions in the repository that downloads the compiler would fetch every tarball on any build. The toolchain() declarations therefore move to a lightweight hub repository that keeps the name the toolchain was declared with, while each version gets its own repository holding the cc_toolchain. Only the selected version is ever fetched. The hub also aliases the public targets of the selected version, so labels such as @gcc_toolchain_x86_64//:libstdcxx keep resolving and follow the flag.
Each version additionally gets a //toolchain:gcc_version_* config_setting so builds can branch on the selected compiler. //tests/gcc_version asserts the compiler reports the requested version, and CI runs the full suite against every version.
GCC 12.5.0, 13.4.0 and 14.3.0 are built without ld.lld, so //tests/lld is marked incompatible with them and is skipped rather than failing.