Skip to content

Commit

Permalink
Enable GCC 10 (#31)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
philsc authored Dec 6, 2022
1 parent 52e1ef9 commit 4fc9ab3
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ build:clang11 --platform_suffix=clang11
build:clang11 --//build:requested_compiler_flag=clang11
build:clang14 --platform_suffix=clang14
build:clang14 --//build:requested_compiler_flag=clang14
build:gcc10 --platform_suffix=gcc10
build:gcc10 --//build:requested_compiler_flag=gcc10
build:gcc10 --features=static_libstdcxx

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

# Compile with clang by default
build --config=clang14
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ Use the following `--config` settings to switch to different compilers.
| Latest supported Clang | `--config=clang` |
| Clang 11 | `--config=clang11` |
| Clang 14 | `--config=clang14` |
| Latest supported GCC | `--config=gcc` |
| GCC 10 | `--config=gcc10` |

Note that the sandboxed compilers do not use a sysroot.
Note that only GCC uses a sysroot.
27 changes: 27 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ load("@llvm_14_toolchain//:toolchains.bzl", llvm_14_register_toolchains="llvm_re

llvm_14_register_toolchains()

http_archive(
name = "aspect_gcc_toolchain",
urls = [
"https://github.com/aspect-build/gcc-toolchain/tarball/ac745d4685e2095cc4f057862800f3f0a473c201",
],
patches = [
"@//:third_party/aspect_gcc_toolchain/0001-Expose-target_settings-and-set-std-c-14.patch",
],
patch_args = ["-p1"],
sha256 = "e2e12202dd83f67d71101b24554044de25e1625d16b4b56bc453ecaa8f7c6bd0",
type = "tar.gz",
strip_prefix = "aspect-build-gcc-toolchain-ac745d4",
)

load("@aspect_gcc_toolchain//toolchain:defs.bzl", "gcc_register_toolchain", "ARCHS")
load("@aspect_gcc_toolchain//sysroot:flags.bzl", gcc_sysroot_cflags="cflags", gcc_sysroot_cxxflags="cxxflags")

gcc_register_toolchain(
name = "gcc_toolchain_x86_64",
sysroot_variant = "x86_64",
target_arch = ARCHS.x86_64,
gcc_version = "10.3.0",
target_settings = ["@//build:gcc10_requested"],
extra_cflags = gcc_sysroot_cflags,
extra_cxxflags = gcc_sysroot_cxxflags,
)

http_archive(
name = "com_google_googletest",
sha256 = "24564e3b712d3eb30ac9a85d92f7d720f60cc0173730ac166f27dda7fed76cb2",
Expand Down
7 changes: 7 additions & 0 deletions build/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ string_flag(
values = [
"clang11",
"clang14",
"gcc10",
],
)

Expand All @@ -20,3 +21,9 @@ config_setting(
flag_values = {"requested_compiler_flag": "clang14"},
visibility = ["//visibility:public"],
)

config_setting(
name = "gcc10_requested",
flag_values = {"requested_compiler_flag": "gcc10"},
visibility = ["//visibility:public"],
)
2 changes: 2 additions & 0 deletions config/buildkite/pipelines/au-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ steps:
command: bazel test --config=clang11 //...:all
- label: "Clang 14"
command: bazel test --config=clang14 //...:all
- label: "GCC 10"
command: bazel test --config=gcc10 //...:all
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
From b26193f526de8e4ea4e1b370f3c9f104222c3d60 Mon Sep 17 00:00:00 2001
From: Philipp Schrader <[email protected]>
Date: Tue, 6 Dec 2022 00:17:31 -0800
Subject: [PATCH] Expose target_settings and set -std=c++14

---
toolchain/cc_toolchain_config.bzl | 2 +-
toolchain/defs.bzl | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl
index afeef35..517bb4a 100644
--- a/toolchain/cc_toolchain_config.bzl
+++ b/toolchain/cc_toolchain_config.bzl
@@ -299,7 +299,7 @@ def _impl(ctx):
),
flag_set(
actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend],
- flag_groups = [flag_group(flags = ["-std=c++0x"])],
+ flag_groups = [flag_group(flags = ["-std=c++14"])],
),
],
)
diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl
index 1420724..2bdb4c8 100644
--- a/toolchain/defs.bzl
+++ b/toolchain/defs.bzl
@@ -56,6 +56,7 @@ def _gcc_toolchain_impl(rctx):
rctx.file("BUILD.bazel", _TOOLCHAIN_BUILD_FILE_CONTENT.format(
gcc_toolchain_workspace_name = rctx.attr.gcc_toolchain_workspace_name,
target_compatible_with = str(target_compatible_with),
+ target_settings = str(rctx.attr.target_settings),
toolchain_files_repository_name = rctx.attr.toolchain_files_repository_name,

# Sysroot
@@ -133,6 +134,12 @@ _FEATURE_ATTRS = {
doc = "contraint_values passed to target_compatible_with of the toolchain. {target_arch} is rendered to the target_arch attribute value.",
mandatory = False,
),
+ "target_settings": attr.string_list(
+ default = [],
+ doc = "A list of config_settings that must be satisfied by the " +
+ "target configuration in order for this toolchain to be " +
+ "selected during toolchain resolution.",
+ ),
"toolchain_files_repository_name": attr.string(
doc = "The name of the repository containing the toolchain files.",
mandatory = True,
@@ -551,6 +558,7 @@ fortran_toolchain(
toolchain(
name = "cc_toolchain",
target_compatible_with = {target_compatible_with},
+ target_settings = {target_settings},
toolchain = ":_cc_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

0 comments on commit 4fc9ab3

Please sign in to comment.