Skip to content

Commit

Permalink
Use bazel 7
Browse files Browse the repository at this point in the history
This updates the remote toolchains and bumps some rule sets to be
compatible. We use the latest release of rules_cc in the fixture repo.
This was needed to avoid the "osx/crosstool" error in the extraction repo.
  • Loading branch information
stagnation committed Dec 19, 2023
1 parent 4249527 commit 5dc6683
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 101 deletions.
11 changes: 11 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# # Bazel7
# TODO: With bzlmod we cannot access the WORKSPACE file anymore
# $ bazel build //:gazelle
# ERROR: /.../external/bazel_gazelle_go_repository_config/BUILD.bazel: no such
# target '@@bazel_gazelle_go_repository_config//:WORKSPACE': target 'WORKSPACE'
# not declared in package '' defined by
# /CAS/bazel-cache/f1a15cfb78ca8fde7615be5d21224669/external/bazel_gazelle_go_repository_config/BUILD.bazel;
# however, a source file of this name exists. (Perhaps add
# 'exports_files(["WORKSPACE"])' to /BUILD?)
build --noenable_bzlmod

# Required for @com_google_absl and remoteapis that use it.
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.0
7.0.0
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ construct such a C++ toolchain which is activated using
`--config=remote-ubuntu-22-04`, see `.bazelrc` and `WORKSPACE` for the exact
setup.

This was solved in `@rules_cc` with this commit:
https://github.com/bazelbuild/rules_cc/commit/404bb430e7b910371a4f52913e2f9299c23aa60d before release 0.0.6
But we drag in an older version through `@bazel_gazelle_go_repository_config//`.


Note that the name and SHA of the container image is configured in multiple
places: `BUILD.bazel`, `.jsonnet` configuration for Buildbarn and for the actual
runner container (docker compose, kubernetes yaml, etc...)
Expand Down
31 changes: 16 additions & 15 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,25 @@ gazelle_dependencies()

http_archive(
name = "com_google_protobuf",
sha256 = "a700a49470d301f1190a487a923b5095bf60f08f4ae4cac9f5f7c36883d17971",
strip_prefix = "protobuf-23.4",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v23.4/protobuf-23.4.tar.gz"],
integrity = "sha256-m9h7goDvcg0yQFFPiE5WpxLyIY8NaTtIBQyDYCiUCkI=",
strip_prefix = "protobuf-25.1",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v25.1/protobuf-25.1.tar.gz"],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

# Below dependencies are for the example project.
# # Dependencies below are for the example project.

# C++ rules for Bazel.

http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz"],
sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf",
strip_prefix = "rules_cc-0.0.9",
)

http_archive(
name = "com_grail_bazel_toolchain",
Expand All @@ -112,14 +121,6 @@ llvm_toolchain(
llvm_version = "14.0.0",
)

# C++ rules for Bazel.
http_archive(
name = "rules_cc",
sha256 = "fe1e7b1801a63e79eb1b40dc44bf0590117a399e118ac44afd6fa07bf63e9ece",
strip_prefix = "rules_cc-58f8e026c00a8a20767e3dc669f46ba23bc93bdb",
urls = ["https://github.com/bazelbuild/rules_cc/archive/58f8e026c00a8a20767e3dc669f46ba23bc93bdb.zip"],
)

# Register the auto configured rules_cc toolchain for local execution.
load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains")

Expand Down Expand Up @@ -208,9 +209,9 @@ http_archive(

http_archive(
name = "aspect_rules_js",
sha256 = "00e7b97b696af63812df0ca9e9dbd18579f3edd3ab9a56f227238b8405e4051c",
strip_prefix = "rules_js-1.23.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.23.0/rules_js-v1.23.0.tar.gz",
sha256 = "76a04ef2120ee00231d85d1ff012ede23963733339ad8db81f590791a031f643",
strip_prefix = "rules_js-1.34.1",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.34.1/rules_js-v1.34.1.tar.gz",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# C++ rules for Bazel.
http_archive(
name = "rules_cc",
sha256 = "954b7a3efc8752da957ae193a13b9133da227bdacf5ceb111f2e11264f7e8c95",
strip_prefix = "rules_cc-9e10b8a6db775b1ecd358d8ddd3dab379a2c29a5",
urls = ["https://github.com/bazelbuild/rules_cc/archive/9e10b8a6db775b1ecd358d8ddd3dab379a2c29a5.zip"],
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz"],
sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf",
strip_prefix = "rules_cc-0.0.9",
)

load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains")
Expand Down
2 changes: 1 addition & 1 deletion tools/remote-toolchains/extract-bazel-auto-toolchains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# `.bazelversion` in the repository root.
#
# Example usage: ./extract-bazel-auto-toolchains.sh ubuntu-act-22-04 ghcr.io/catthehacker/ubuntu:act-22.04
set -eEuo pipefail
set -eu -o pipefail

script_dir="$(dirname "${BASH_SOURCE[0]}")"

Expand Down
114 changes: 49 additions & 65 deletions tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/BUILD
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ filegroup(

filegroup(
name = "compiler_deps",
srcs = glob(
["extra_tools/**"],
allow_empty = True,
) + [":builtin_include_directory_paths"],
srcs = glob(["extra_tools/**"], allow_empty = True) + [":builtin_include_directory_paths"],
)

# This is the entry point for --crosstool_top. Toolchains are found
Expand All @@ -59,6 +56,8 @@ cc_toolchain_suite(

cc_toolchain(
name = "cc-compiler-k8",
toolchain_identifier = "local",
toolchain_config = ":local",
all_files = ":compiler_deps",
ar_files = ":compiler_deps",
as_files = ":compiler_deps",
Expand All @@ -68,62 +67,26 @@ cc_toolchain(
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
toolchain_config = ":local",
toolchain_identifier = "local",
)

cc_toolchain_config(
name = "local",
abi_libc_version = "local",
abi_version = "local",
compile_flags = [
"-U_FORTIFY_SOURCE",
"-fstack-protector",
"-Wall",
"-Wunused-but-set-parameter",
"-Wno-free-nonheap-object",
"-fno-omit-frame-pointer",
],
compiler = "compiler",
coverage_compile_flags = ["--coverage"],
coverage_link_flags = ["--coverage"],
cpu = "k8",
cxx_builtin_include_directories = [
"/usr/lib/gcc/x86_64-linux-gnu/11/include",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"/usr/include/c++/11",
"/usr/include/x86_64-linux-gnu/c++/11",
"/usr/include/c++/11/backward",
],
cxx_flags = ["-std=c++0x"],
dbg_compile_flags = ["-g"],
compiler = "compiler",
toolchain_identifier = "local",
host_system_name = "local",
link_flags = [
"-fuse-ld=gold",
"-Wl,-no-as-needed",
"-Wl,-z,relro,-z,now",
"-B/usr/bin",
"-pass-exit-codes",
"-lstdc++",
"-lm",
],
link_libs = [],
opt_compile_flags = [
"-g0",
"-O2",
"-D_FORTIFY_SOURCE=1",
"-DNDEBUG",
"-ffunction-sections",
"-fdata-sections",
],
opt_link_flags = ["-Wl,--gc-sections"],
supports_start_end_lib = True,
target_libc = "local",
target_system_name = "local",
tool_paths = {
"ar": "/usr/bin/ar",
target_libc = "local",
abi_version = "local",
abi_libc_version = "local",
cxx_builtin_include_directories = ["/usr/lib/gcc/x86_64-linux-gnu/11/include",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"/usr/include/c++/11",
"/usr/include/x86_64-linux-gnu/c++/11",
"/usr/include/c++/11/backward"],
tool_paths = {"ar": "/usr/bin/ar",
"ld": "/usr/bin/ld",
"cpp": "/usr/bin/cpp",
"gcc": "/usr/bin/gcc",
Expand All @@ -132,21 +95,44 @@ cc_toolchain_config(
"nm": "/usr/bin/nm",
"objcopy": "/usr/bin/objcopy",
"objdump": "/usr/bin/objdump",
"strip": "/usr/bin/strip",
},
toolchain_identifier = "local",
unfiltered_compile_flags = [
"-fno-canonical-system-headers",
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
"-D__TIME__=\"redacted\"",
],
"strip": "/usr/bin/strip"},
compile_flags = ["-U_FORTIFY_SOURCE",
"-fstack-protector",
"-Wall",
"-Wunused-but-set-parameter",
"-Wno-free-nonheap-object",
"-fno-omit-frame-pointer"],
opt_compile_flags = ["-g0",
"-O2",
"-D_FORTIFY_SOURCE=1",
"-DNDEBUG",
"-ffunction-sections",
"-fdata-sections"],
dbg_compile_flags = ["-g"],
cxx_flags = ["-std=c++0x"],
link_flags = ["-fuse-ld=gold",
"-Wl,-no-as-needed",
"-Wl,-z,relro,-z,now",
"-B/usr/bin",
"-pass-exit-codes"],
link_libs = ["-lstdc++",
"-lm"],
opt_link_flags = ["-Wl,--gc-sections"],
unfiltered_compile_flags = ["-fno-canonical-system-headers",
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
"-D__TIME__=\"redacted\""],
coverage_compile_flags = ["--coverage"],
coverage_link_flags = ["--coverage"],
supports_start_end_lib = True,
)

# Android tooling requires a default toolchain for the armeabi-v7a cpu.
cc_toolchain(
name = "cc-compiler-armeabi-v7a",
toolchain_identifier = "stub_armeabi-v7a",
toolchain_config = ":stub_armeabi-v7a",
all_files = ":empty",
ar_files = ":empty",
as_files = ":empty",
Expand All @@ -156,8 +142,6 @@ cc_toolchain(
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
toolchain_config = ":stub_armeabi-v7a",
toolchain_identifier = "stub_armeabi-v7a",
)

armeabi_cc_toolchain_config(name = "stub_armeabi-v7a")
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _impl(ctx):
],
flag_groups = [
flag_group(
flags = ["-gsplit-dwarf"],
flags = ["-gsplit-dwarf", "-g"],
expand_if_available = "per_object_debug_info_file",
),
],
Expand Down Expand Up @@ -354,8 +354,8 @@ def _impl(ctx):
flag_group(
flags = [
"-fprofile-use=%{fdo_profile_path}",
"-Xclang-only=-Wno-profile-instr-unprofiled",
"-Xclang-only=-Wno-profile-instr-out-of-date",
"-Wno-profile-instr-unprofiled",
"-Wno-profile-instr-out-of-date",
"-fprofile-correction",
],
expand_if_available = "fdo_profile_path",
Expand Down Expand Up @@ -808,8 +808,8 @@ def _impl(ctx):
flag_groups = [
flag_group(
flags = [
"-Xclang-only=-mllvm",
"-Xclang-only=-prefetch-hints-file=%{fdo_prefetch_hints_path}",
"-mllvm",
"-prefetch-hints-file=%{fdo_prefetch_hints_path}",
],
expand_if_available = "fdo_prefetch_hints_path",
),
Expand Down Expand Up @@ -950,7 +950,6 @@ def _impl(ctx):
],
)

dynamic_library_linker_tool_path = tool_paths
dynamic_library_linker_tool_feature = feature(
name = "dynamic_library_linker_tool",
flag_sets = [
Expand Down Expand Up @@ -1114,6 +1113,8 @@ def _impl(ctx):
strip_debug_symbols_feature,
coverage_feature,
supports_pic_feature,
gcc_coverage_map_format_feature,
llvm_coverage_map_format_feature,
] + (
[
supports_start_end_lib_feature,
Expand Down Expand Up @@ -1150,6 +1151,8 @@ def _impl(ctx):
user_compile_flags_feature,
sysroot_feature,
unfiltered_compile_flags_feature,
gcc_coverage_map_format_feature,
llvm_coverage_map_format_feature,
]

return cc_common.create_cc_toolchain_config_info(
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# DO NOT EDIT: automatically generated BUILD file for local_config_platform
package(default_visibility = ["//visibility:public"])

load(":constraints.bzl", "HOST_CONSTRAINTS")

platform(
name = "host",
# Auto-detected host platform constraints.
constraint_values = HOST_CONSTRAINTS,
package(default_visibility = ['//visibility:public'])
load(':constraints.bzl', 'HOST_CONSTRAINTS')
platform(name = 'host',
# Auto-detected host platform constraints.
constraint_values = HOST_CONSTRAINTS,
)
exports_files([
# Export constraints.bzl for use in downstream bzl_library targets.
'constraints.bzl',
])
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DO NOT EDIT: automatically generated constraints list for local_config_platform
# Auto-detected host platform constraints.
HOST_CONSTRAINTS = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
'@platforms//cpu:x86_64',
'@platforms//os:linux',
]
1 change: 1 addition & 0 deletions tools/remote-toolchains/ubuntu-act-22-04/local_config_sh/BUILD
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

load("@bazel_tools//tools/sh:sh_toolchain.bzl", "sh_toolchain")

sh_toolchain(
Expand Down

0 comments on commit 5dc6683

Please sign in to comment.