Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ jobs:
run: |
ln -s .github/workflows/.bazelrc.ci .bazelrc.ci
bazel test --compilation_mode ${{ matrix.compilation_mode }} //...
gcc_versions:
strategy:
matrix:
gcc_version:
- 12.5.0
- 13.4.0
- 14.3.0
- 15.2.0
- 16.1.0
- 16.2.0
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: bazel-contrib/setup-bazel@0.15.0
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
- name: Test GCC ${{ matrix.gcc_version }}
run: |
ln -s .github/workflows/.bazelrc.ci .bazelrc.ci
bazel test --//toolchain:gcc_version=${{ matrix.gcc_version }} //...
sanitizers:
strategy:
matrix:
Expand Down
3 changes: 1 addition & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ gcc_toolchains = use_extension("//toolchain:module_extensions.bzl", "gcc_toolcha
),
use_repo(gcc_toolchains, "gcc_toolchain_{}".format(arch)),
register_toolchains(
"@gcc_toolchain_{}//:cc_toolchain".format(arch),
"@gcc_toolchain_{}//:fortran_toolchain".format(arch),
"@gcc_toolchain_{}//:all".format(arch),
# Register toolchains as dev dependencies so that we don't pollute the toolchain resolution of consumers.
dev_dependency = True,
),
Expand Down
41 changes: 41 additions & 0 deletions docs/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions docs/defs.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions docs/updating-gcc-builds.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions tests/gcc_version/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) Thulio Ferraz Assis 2026
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("//rules_cc:defs.bzl", "cc_test")
load("//toolchain:defs.bzl", "AVAILABLE_GCC_VERSIONS", "DEFAULT_GCC_VERSION")

# Asserts that the compiler picked by toolchain resolution is the one the gcc_version flag asked
# for. The build fails to compile when the selected toolchain reports a different version.
cc_test(
name = "gcc_version_test",
srcs = ["main.c"],
copts = select(dicts.add(
{
"//toolchain:gcc_version_{}".format(gcc_version.replace(".", "_")): [
"-DEXPECTED_GCC_MAJOR={}".format(gcc_version.split(".")[0]),
"-DEXPECTED_GCC_MINOR={}".format(gcc_version.split(".")[1]),
]
for gcc_version in AVAILABLE_GCC_VERSIONS
},
{
"//conditions:default": [
"-DEXPECTED_GCC_MAJOR={}".format(DEFAULT_GCC_VERSION.split(".")[0]),
"-DEXPECTED_GCC_MINOR={}".format(DEFAULT_GCC_VERSION.split(".")[1]),
],
},
)),
)
28 changes: 28 additions & 0 deletions tests/gcc_version/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Thulio Ferraz Assis 2026
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <stdio.h>

#if __GNUC__ != EXPECTED_GCC_MAJOR
#error "The compiling GCC major version does not match the gcc_version flag."
#endif

#if __GNUC_MINOR__ != EXPECTED_GCC_MINOR
#error "The compiling GCC minor version does not match the gcc_version flag."
#endif

int main(void) {
printf("%d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
return 0;
}
11 changes: 9 additions & 2 deletions tests/lld/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//rules_cc:defs.bzl", "cc_binary")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("//rules_cc:defs.bzl", "cc_binary")

# This binary is always linked with lld via the target-level `linker-lld`
# feature, which requires the toolchain archive to ship `ld.lld`.
# feature, which requires the toolchain archive to ship `ld.lld`. GCC versions
# older than 15.2.0 are built without lld, so the test is skipped for them.
cc_binary(
name = "hello_world_lld",
srcs = ["main.c"],
features = ["linker-lld"],
target_compatible_with = select({
"//toolchain:gcc_version_12_5_0": ["@platforms//:incompatible"],
"//toolchain:gcc_version_13_4_0": ["@platforms//:incompatible"],
"//toolchain:gcc_version_14_3_0": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)

sh_test(
Expand Down
21 changes: 21 additions & 0 deletions toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@
# limitations under the License.

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load(":defs.bzl", "AVAILABLE_GCC_VERSIONS")

# Selects which GCC version the registered toolchains resolve to. The empty default defers to the
# gcc_version each toolchain was declared with.
string_flag(
name = "gcc_version",
build_setting_default = "",
visibility = ["//visibility:public"],
)

# Matches when gcc_version is set to that exact version. None of these match while the flag is left
# at its empty default, so a select over them needs a //conditions:default branch.
[
config_setting(
name = "gcc_version_{}".format(gcc_version.replace(".", "_")),
flag_values = {":gcc_version": gcc_version},
visibility = ["//visibility:public"],
)
for gcc_version in AVAILABLE_GCC_VERSIONS
]

exports_files(
["config.bzl"],
Expand Down
Loading
Loading