From 5dc66837fb37a58f96d2445abc35765f00325e89 Mon Sep 17 00:00:00 2001 From: Nils Wireklint Date: Mon, 12 Jun 2023 16:15:48 +0200 Subject: [PATCH] Use bazel 7 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. --- .bazelrc | 11 ++ .bazelversion | 2 +- README.md | 5 + WORKSPACE | 31 ++--- .../WORKSPACE | 6 +- .../extract-bazel-auto-toolchains.sh | 2 +- .../ubuntu-act-22-04/local_config_cc/BUILD | 114 ++++++++---------- .../builtin_include_directory_paths | 0 .../local_config_cc/cc_toolchain_config.bzl | 15 ++- .../local_config_cc/tools/cpp/empty.cc | 0 .../local_config_cc_toolchains/BUILD | 0 .../local_config_platform/BUILD.bazel | 17 +-- .../local_config_platform/constraints.bzl | 4 +- .../ubuntu-act-22-04/local_config_sh/BUILD | 1 + 14 files changed, 107 insertions(+), 101 deletions(-) mode change 100644 => 100755 tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/BUILD mode change 100644 => 100755 tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/builtin_include_directory_paths mode change 100644 => 100755 tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/tools/cpp/empty.cc mode change 100644 => 100755 tools/remote-toolchains/ubuntu-act-22-04/local_config_cc_toolchains/BUILD mode change 100644 => 100755 tools/remote-toolchains/ubuntu-act-22-04/local_config_sh/BUILD diff --git a/.bazelrc b/.bazelrc index 3752b49..664e7e3 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/.bazelversion b/.bazelversion index 09b254e..66ce77b 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.0.0 +7.0.0 diff --git a/README.md b/README.md index 94ed11c..1e51426 100644 --- a/README.md +++ b/README.md @@ -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...) diff --git a/WORKSPACE b/WORKSPACE index f98476a..283f42c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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", @@ -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") @@ -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") diff --git a/tools/remote-toolchains/extract-bazel-auto-toolchains-fixture/WORKSPACE b/tools/remote-toolchains/extract-bazel-auto-toolchains-fixture/WORKSPACE index da47f00..b2ccf57 100644 --- a/tools/remote-toolchains/extract-bazel-auto-toolchains-fixture/WORKSPACE +++ b/tools/remote-toolchains/extract-bazel-auto-toolchains-fixture/WORKSPACE @@ -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") diff --git a/tools/remote-toolchains/extract-bazel-auto-toolchains.sh b/tools/remote-toolchains/extract-bazel-auto-toolchains.sh index 435cf8a..ae21226 100755 --- a/tools/remote-toolchains/extract-bazel-auto-toolchains.sh +++ b/tools/remote-toolchains/extract-bazel-auto-toolchains.sh @@ -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]}")" diff --git a/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/BUILD b/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/BUILD old mode 100644 new mode 100755 index b5acd20..cb3c433 --- a/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/BUILD +++ b/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/BUILD @@ -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 @@ -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", @@ -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", @@ -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", @@ -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") diff --git a/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/builtin_include_directory_paths b/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/builtin_include_directory_paths old mode 100644 new mode 100755 diff --git a/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/cc_toolchain_config.bzl b/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/cc_toolchain_config.bzl index 3d5ae2f..4325a68 100644 --- a/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/cc_toolchain_config.bzl +++ b/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/cc_toolchain_config.bzl @@ -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", ), ], @@ -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", @@ -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", ), @@ -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 = [ @@ -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, @@ -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( diff --git a/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/tools/cpp/empty.cc b/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc/tools/cpp/empty.cc old mode 100644 new mode 100755 diff --git a/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc_toolchains/BUILD b/tools/remote-toolchains/ubuntu-act-22-04/local_config_cc_toolchains/BUILD old mode 100644 new mode 100755 diff --git a/tools/remote-toolchains/ubuntu-act-22-04/local_config_platform/BUILD.bazel b/tools/remote-toolchains/ubuntu-act-22-04/local_config_platform/BUILD.bazel index b2828f7..ceb1919 100644 --- a/tools/remote-toolchains/ubuntu-act-22-04/local_config_platform/BUILD.bazel +++ b/tools/remote-toolchains/ubuntu-act-22-04/local_config_platform/BUILD.bazel @@ -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', +]) diff --git a/tools/remote-toolchains/ubuntu-act-22-04/local_config_platform/constraints.bzl b/tools/remote-toolchains/ubuntu-act-22-04/local_config_platform/constraints.bzl index 5d65993..6a7d8c3 100644 --- a/tools/remote-toolchains/ubuntu-act-22-04/local_config_platform/constraints.bzl +++ b/tools/remote-toolchains/ubuntu-act-22-04/local_config_platform/constraints.bzl @@ -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', ] diff --git a/tools/remote-toolchains/ubuntu-act-22-04/local_config_sh/BUILD b/tools/remote-toolchains/ubuntu-act-22-04/local_config_sh/BUILD old mode 100644 new mode 100755 index 8acbc76..324975d --- a/tools/remote-toolchains/ubuntu-act-22-04/local_config_sh/BUILD +++ b/tools/remote-toolchains/ubuntu-act-22-04/local_config_sh/BUILD @@ -1,3 +1,4 @@ + load("@bazel_tools//tools/sh:sh_toolchain.bzl", "sh_toolchain") sh_toolchain(