Skip to content

feat: select the GCC version through a build flag - #239

Merged
f0rmiga merged 2 commits into
mainfrom
f0rmiga/gcc-version-flag
Aug 10, 2026
Merged

feat: select the GCC version through a build flag#239
f0rmiga merged 2 commits into
mainfrom
f0rmiga/gcc-version-flag

Conversation

@f0rmiga

@f0rmiga f0rmiga commented Aug 10, 2026

Copy link
Copy Markdown
Owner

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.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread toolchain/defs.bzl Outdated
Comment thread docs/defs.md
Comment thread toolchain/defs.bzl
Comment thread docs/README.md Outdated
Comment thread docs/README.md
- 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

@f0rmiga
f0rmiga merged commit 042d4f1 into main Aug 10, 2026
30 checks passed
@f0rmiga
f0rmiga deleted the f0rmiga/gcc-version-flag branch August 10, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants