Skip to content

Commit 4fc9ab3

Browse files
authored
Enable GCC 10 (#31)
This patch allows the user to specify `--config=gcc10` to compiler the code. We need `--features=static_libstdcxx` because the sysroot has a newer version of libstdc++ than the Ubuntu 18.04. We use Ubuntu 18.04 as our host system at the moment.
1 parent 52e1ef9 commit 4fc9ab3

File tree

6 files changed

+99
-1
lines changed

6 files changed

+99
-1
lines changed

.bazelrc

+4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ build:clang11 --platform_suffix=clang11
66
build:clang11 --//build:requested_compiler_flag=clang11
77
build:clang14 --platform_suffix=clang14
88
build:clang14 --//build:requested_compiler_flag=clang14
9+
build:gcc10 --platform_suffix=gcc10
10+
build:gcc10 --//build:requested_compiler_flag=gcc10
11+
build:gcc10 --features=static_libstdcxx
912

1013
# Add a generic alias if the user doesn't care about the exact version.
1114
build:clang --config=clang14
15+
build:gcc --config=gcc10
1216

1317
# Compile with clang by default
1418
build --config=clang14

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ Use the following `--config` settings to switch to different compilers.
3131
| Latest supported Clang | `--config=clang` |
3232
| Clang 11 | `--config=clang11` |
3333
| Clang 14 | `--config=clang14` |
34+
| Latest supported GCC | `--config=gcc` |
35+
| GCC 10 | `--config=gcc10` |
3436

35-
Note that the sandboxed compilers do not use a sysroot.
37+
Note that only GCC uses a sysroot.

WORKSPACE

+27
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ load("@llvm_14_toolchain//:toolchains.bzl", llvm_14_register_toolchains="llvm_re
5858

5959
llvm_14_register_toolchains()
6060

61+
http_archive(
62+
name = "aspect_gcc_toolchain",
63+
urls = [
64+
"https://github.com/aspect-build/gcc-toolchain/tarball/ac745d4685e2095cc4f057862800f3f0a473c201",
65+
],
66+
patches = [
67+
"@//:third_party/aspect_gcc_toolchain/0001-Expose-target_settings-and-set-std-c-14.patch",
68+
],
69+
patch_args = ["-p1"],
70+
sha256 = "e2e12202dd83f67d71101b24554044de25e1625d16b4b56bc453ecaa8f7c6bd0",
71+
type = "tar.gz",
72+
strip_prefix = "aspect-build-gcc-toolchain-ac745d4",
73+
)
74+
75+
load("@aspect_gcc_toolchain//toolchain:defs.bzl", "gcc_register_toolchain", "ARCHS")
76+
load("@aspect_gcc_toolchain//sysroot:flags.bzl", gcc_sysroot_cflags="cflags", gcc_sysroot_cxxflags="cxxflags")
77+
78+
gcc_register_toolchain(
79+
name = "gcc_toolchain_x86_64",
80+
sysroot_variant = "x86_64",
81+
target_arch = ARCHS.x86_64,
82+
gcc_version = "10.3.0",
83+
target_settings = ["@//build:gcc10_requested"],
84+
extra_cflags = gcc_sysroot_cflags,
85+
extra_cxxflags = gcc_sysroot_cxxflags,
86+
)
87+
6188
http_archive(
6289
name = "com_google_googletest",
6390
sha256 = "24564e3b712d3eb30ac9a85d92f7d720f60cc0173730ac166f27dda7fed76cb2",

build/BUILD

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ string_flag(
66
values = [
77
"clang11",
88
"clang14",
9+
"gcc10",
910
],
1011
)
1112

@@ -20,3 +21,9 @@ config_setting(
2021
flag_values = {"requested_compiler_flag": "clang14"},
2122
visibility = ["//visibility:public"],
2223
)
24+
25+
config_setting(
26+
name = "gcc10_requested",
27+
flag_values = {"requested_compiler_flag": "gcc10"},
28+
visibility = ["//visibility:public"],
29+
)

config/buildkite/pipelines/au-pull-request.yml

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ steps:
88
command: bazel test --config=clang11 //...:all
99
- label: "Clang 14"
1010
command: bazel test --config=clang14 //...:all
11+
- label: "GCC 10"
12+
command: bazel test --config=gcc10 //...:all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
From b26193f526de8e4ea4e1b370f3c9f104222c3d60 Mon Sep 17 00:00:00 2001
2+
From: Philipp Schrader <[email protected]>
3+
Date: Tue, 6 Dec 2022 00:17:31 -0800
4+
Subject: [PATCH] Expose target_settings and set -std=c++14
5+
6+
---
7+
toolchain/cc_toolchain_config.bzl | 2 +-
8+
toolchain/defs.bzl | 8 ++++++++
9+
2 files changed, 9 insertions(+), 1 deletion(-)
10+
11+
diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl
12+
index afeef35..517bb4a 100644
13+
--- a/toolchain/cc_toolchain_config.bzl
14+
+++ b/toolchain/cc_toolchain_config.bzl
15+
@@ -299,7 +299,7 @@ def _impl(ctx):
16+
),
17+
flag_set(
18+
actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend],
19+
- flag_groups = [flag_group(flags = ["-std=c++0x"])],
20+
+ flag_groups = [flag_group(flags = ["-std=c++14"])],
21+
),
22+
],
23+
)
24+
diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl
25+
index 1420724..2bdb4c8 100644
26+
--- a/toolchain/defs.bzl
27+
+++ b/toolchain/defs.bzl
28+
@@ -56,6 +56,7 @@ def _gcc_toolchain_impl(rctx):
29+
rctx.file("BUILD.bazel", _TOOLCHAIN_BUILD_FILE_CONTENT.format(
30+
gcc_toolchain_workspace_name = rctx.attr.gcc_toolchain_workspace_name,
31+
target_compatible_with = str(target_compatible_with),
32+
+ target_settings = str(rctx.attr.target_settings),
33+
toolchain_files_repository_name = rctx.attr.toolchain_files_repository_name,
34+
35+
# Sysroot
36+
@@ -133,6 +134,12 @@ _FEATURE_ATTRS = {
37+
doc = "contraint_values passed to target_compatible_with of the toolchain. {target_arch} is rendered to the target_arch attribute value.",
38+
mandatory = False,
39+
),
40+
+ "target_settings": attr.string_list(
41+
+ default = [],
42+
+ doc = "A list of config_settings that must be satisfied by the " +
43+
+ "target configuration in order for this toolchain to be " +
44+
+ "selected during toolchain resolution.",
45+
+ ),
46+
"toolchain_files_repository_name": attr.string(
47+
doc = "The name of the repository containing the toolchain files.",
48+
mandatory = True,
49+
@@ -551,6 +558,7 @@ fortran_toolchain(
50+
toolchain(
51+
name = "cc_toolchain",
52+
target_compatible_with = {target_compatible_with},
53+
+ target_settings = {target_settings},
54+
toolchain = ":_cc_toolchain",
55+
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
56+
)

0 commit comments

Comments
 (0)