Skip to content

Commit

Permalink
Update toolchain using Ubuntu 20.04 docker image
Browse files Browse the repository at this point in the history
See this instruction to use Ubuntu 20.04 docker image used by Bazel
project: [1].

[1] bazelbuild/bazel-toolchains#870 (comment)
  • Loading branch information
davido committed Nov 13, 2023
1 parent 5ac3169 commit 1f74b00
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 57 deletions.
32 changes: 8 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#### RBE toolchain config for a given combination of Bazel release and docker image

Clone the [bazel-toolchain](https://github.com/bazelbuild/bazel-toolchains.git)
project and checkout `v5.1.2` tag.
project.

Build the `rbe_configs_gen` with the following command:

Expand All @@ -17,31 +17,15 @@ directory and run this command in `bazel-toolchain` directory:

```
$ ./rbe_configs_gen \
--bazel_version=5.3.2 \
--toolchain_container=gcr.io/$PROJECT_NAME/rbe-ubuntu18-04:latest \
--output_src_root=/home/<user>/projects/rbe_autoconfig \
--exec_os=linux \
--target_os=linux
--bazel_version=6.4.0 \
--toolchain_container=gcr.io/bazel-public/ubuntu2004-java11@sha256:833b20afd7b624693160c8e9f8aafaee46657d29d32e61012256aa3d045d8662 \
--output_src_root=/path/to/repo \
--output_config_path=path/to/config-directory \
--exec_os=linux \
--target_os=linux \
--cpp_env_json=ubuntu2004.json
```

To replace JDK 8 with JDK 11 the following diff was applied:

```diff
diff --git a/java/BUILD b/java/BUILD
index 237e5c1..7c6ab59 100755
--- a/java/BUILD
+++ b/java/BUILD
@@ -20,5 +20,5 @@ package(default_visibility = ["//visibility:public"])
java_runtime(
name = "jdk",
srcs = [],
- java_home = "/usr/lib/jvm/11.29.3-ca-jdk11.0.2/reduced",
+ java_home = "/usr/lib/jvm/java-8-openjdk-amd64",
)
```

See also this [related issue upstream](https://github.com/bazelbuild/bazel-toolchains/issues/961).

Conduct new release on GitHub and upload `tar.gz` archive to GCloud bucket.
Consume the new release from Gerrit project:

Expand Down
42 changes: 20 additions & 22 deletions cc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ filegroup(
cc_toolchain_suite(
name = "toolchain",
toolchains = {
"k8|clang": ":cc-compiler-k8",
"k8|gcc": ":cc-compiler-k8",
"k8": ":cc-compiler-k8",
"armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
"armeabi-v7a": ":cc-compiler-armeabi-v7a",
Expand All @@ -67,45 +67,42 @@ cc_toolchain(
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
module_map = ":module.modulemap",
module_map = None,
)

cc_toolchain_config(
name = "linux_gnu_x86",
cpu = "k8",
compiler = "clang",
compiler = "gcc",
toolchain_identifier = "linux_gnu_x86",
host_system_name = "i686-unknown-linux-gnu",
target_system_name = "x86_64-unknown-linux-gnu",
target_libc = "glibc_2.19",
abi_version = "clang",
abi_version = "gcc",
abi_libc_version = "glibc_2.19",
cxx_builtin_include_directories = ["/usr/local/include",
"/usr/local/lib/clang/12.0.0/include",
cxx_builtin_include_directories = ["/usr/lib/gcc/x86_64-linux-gnu/9/include",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"/usr/local/lib/clang/12.0.0/share",
"/usr/include/c++/7.5.0",
"/usr/include/x86_64-linux-gnu/c++/7.5.0",
"/usr/include/c++/7.5.0/backward",
"/usr/local/include/c++/v1"],
"/usr/include/c++/9",
"/usr/include/x86_64-linux-gnu/c++/9",
"/usr/include/c++/9/backward"],
tool_paths = {"ar": "/usr/bin/ar",
"ld": "/usr/bin/ld",
"llvm-cov": "/usr/local/bin/llvm-cov",
"llvm-profdata": "/usr/local/bin/llvm-profdata",
"llvm-cov": "/usr/bin/llvm-cov",
"llvm-profdata": "/usr/bin/llvm-profdata",
"cpp": "/usr/bin/cpp",
"gcc": "/usr/local/bin/clang-12",
"gcc": "/usr/bin/gcc",
"dwp": "/usr/bin/dwp",
"gcov": "/dev/null",
"gcov": "/usr/bin/gcov",
"nm": "/usr/bin/nm",
"objcopy": "/usr/bin/objcopy",
"objdump": "/usr/bin/objdump",
"strip": "/usr/bin/strip"},
compile_flags = ["-fstack-protector",
"-Wall",
"-Wthread-safety",
"-Wself-assign",
"-fcolor-diagnostics",
"-Wunused-but-set-parameter",
"-Wno-free-nonheap-object",
"-fno-omit-frame-pointer"],
opt_compile_flags = ["-g0",
"-O2",
Expand All @@ -114,15 +111,16 @@ cc_toolchain_config(
"-ffunction-sections",
"-fdata-sections"],
dbg_compile_flags = ["-g"],
cxx_flags = ["-std=c++0x"],
link_flags = ["-fuse-ld=/usr/bin/ld.gold",
cxx_flags = ["-std=c++14"],
link_flags = ["-fuse-ld=gold",
"-Wl,-no-as-needed",
"-Wl,-z,relro,-z,now",
"-B/usr/local/bin"],
"-B/usr/bin",
"-pass-exit-codes"],
link_libs = ["-lstdc++",
"-lm"],
opt_link_flags = ["-Wl,--gc-sections"],
unfiltered_compile_flags = ["-no-canonical-prefixes",
unfiltered_compile_flags = ["-fno-canonical-system-headers",
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
Expand Down
12 changes: 5 additions & 7 deletions cc/builtin_include_directory_paths
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
This file is generated by cc_configure and contains builtin include directories
that /usr/local/bin/clang-12 reported. This file is a dependency of every compilation action and
that /usr/bin/gcc reported. This file is a dependency of every compilation action and
changes to it will be reflected in the action cache key. When some of these
paths change, Bazel will make sure to rerun the action, even though none of
declared action inputs or the action commandline changes.

/usr/lib/gcc/x86_64-linux-gnu/9/include
/usr/local/include
/usr/local/lib/clang/12.0.0/include
/usr/include/x86_64-linux-gnu
/usr/include
/usr/local/lib/clang/12.0.0/share
/usr/include/c++/7.5.0
/usr/include/x86_64-linux-gnu/c++/7.5.0
/usr/include/c++/7.5.0/backward
/usr/local/include/c++/v1
/usr/include/c++/9
/usr/include/x86_64-linux-gnu/c++/9
/usr/include/c++/9/backward
65 changes: 65 additions & 0 deletions cc/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,34 @@ lto_index_actions = [
ACTION_NAMES.lto_index_for_nodeps_dynamic_library,
]

def _sanitizer_feature(name = "", specific_compile_flags = [], specific_link_flags = []):
return feature(
name = name,
flag_sets = [
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(flags = [
"-fno-omit-frame-pointer",
"-fno-sanitize-recover=all",
] + specific_compile_flags),
],
with_features = [
with_feature_set(features = [name]),
],
),
flag_set(
actions = all_link_actions,
flag_groups = [
flag_group(flags = specific_link_flags),
],
with_features = [
with_feature_set(features = [name]),
],
),
],
)

def _impl(ctx):
tool_paths = [
tool_path(name = name, path = path)
Expand Down Expand Up @@ -1224,6 +1252,37 @@ def _impl(ctx):
enabled = True,
)

asan_feature = _sanitizer_feature(
name = "asan",
specific_compile_flags = [
"-fsanitize=address",
"-fno-common",
],
specific_link_flags = [
"-fsanitize=address",
],
)

tsan_feature = _sanitizer_feature(
name = "tsan",
specific_compile_flags = [
"-fsanitize=thread",
],
specific_link_flags = [
"-fsanitize=thread",
],
)

ubsan_feature = _sanitizer_feature(
name = "ubsan",
specific_compile_flags = [
"-fsanitize=undefined",
],
specific_link_flags = [
"-fsanitize=undefined",
],
)

is_linux = ctx.attr.target_libc != "macosx"
libtool_feature = feature(
name = "libtool",
Expand Down Expand Up @@ -1265,6 +1324,9 @@ def _impl(ctx):
strip_debug_symbols_feature,
coverage_feature,
supports_pic_feature,
asan_feature,
tsan_feature,
ubsan_feature,
] + (
[
supports_start_end_lib_feature,
Expand Down Expand Up @@ -1300,6 +1362,9 @@ def _impl(ctx):
libtool_feature,
archiver_flags_feature,
supports_pic_feature,
asan_feature,
tsan_feature,
ubsan_feature,
] + (
[
supports_start_end_lib_feature,
Expand Down
2 changes: 1 addition & 1 deletion cc/cc_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ set -eu


# Call the C++ compiler
/usr/local/bin/clang-12 "$@"
/usr/bin/gcc "$@"
2 changes: 1 addition & 1 deletion config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ platform(
"@bazel_tools//tools/cpp:clang",
],
exec_properties = {
"container-image": "docker://gcr.io/api-project-164060093628/rbe-ubuntu18-04@sha256:00d248350be6a76bd1c93d77c90826e7754388a7e9f9299d4a8f4bdae29219dd",
"container-image": "docker://gcr.io/bazel-public/ubuntu2004-java11@sha256:833b20afd7b624693160c8e9f8aafaee46657d29d32e61012256aa3d045d8662",
"OSFamily": "Linux",
},
)
4 changes: 2 additions & 2 deletions java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ alias(

local_java_runtime(
name = "rbe_jdk",
java_home = "/usr/lib/jvm/11.29.3-ca-jdk11.0.2/reduced",
version = "11",
java_home = "/usr/lib/jvm/java-11-openjdk-amd64",
version = "11.0.17",
)

0 comments on commit 1f74b00

Please sign in to comment.