From 8d396055ee8799fc8ea582410f166c65fb07643c Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 20 Dec 2024 12:30:13 -0800 Subject: [PATCH] [CI] Fix for bazel 8.x (#427) --- .github/workflows/tests.yml | 2 +- MODULE.bazel | 7 ++++-- tests/MODULE.bazel | 36 ++++++++++++++++++----------- tests/WORKSPACE | 32 +++++++++++++++++++++++++ tests/scripts/bazel.sh | 1 + tests/scripts/run_external_tests.sh | 7 +++++- toolchain/deps.bzl | 6 ++--- 7 files changed, 71 insertions(+), 20 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 51bd2df8..26614fbd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,7 +29,7 @@ jobs: matrix: os: [macos-latest, ubuntu-latest] # TODO: Test with Bazel 8 after https://github.com/bazelbuild/bazel/pull/24154 has been released. - bazel_version: [7.0.0, latest] # Minimum supported Bazel version is 7.0.0. + bazel_version: [7.x, latest] # Minimum supported Bazel version is 7.x bzlmod: [true, false] runs-on: ${{ matrix.os }} steps: diff --git a/MODULE.bazel b/MODULE.bazel index 5a4d16ea..8c2d556a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -15,10 +15,13 @@ module( name = "toolchains_llvm", version = "0.0.0", - compatibility_level = 0, bazel_compatibility = [">=7.0.0"], + compatibility_level = 0, ) bazel_dep(name = "bazel_skylib", version = "1.5.0") -bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "rules_cc", version = "0.0.17") bazel_dep(name = "platforms", version = "0.0.8") + +# TODO: Remove when protobuf is released with a version of rules_python that supports 8.x +bazel_dep(name = "rules_python", version = "1.0.0", dev_dependency = True) diff --git a/tests/MODULE.bazel b/tests/MODULE.bazel index 27fe0ed4..38690550 100644 --- a/tests/MODULE.bazel +++ b/tests/MODULE.bazel @@ -28,9 +28,13 @@ bazel_dep(name = "rules_rust", version = "0.54.1") bazel_dep(name = "rules_foreign_cc", version = "0.13.0") bazel_dep(name = "abseil-cpp", version = "20240722.0", repo_name = "com_google_absl") +# TODO: Remove when protobuf is released with a version of rules_python that supports 8.x +bazel_dep(name = "rules_python", version = "1.0.0") + # As a workaround for https://github.com/bazelbuild/rules_foreign_cc/issues/1018. rules_foreign_cc_tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools") use_repo(rules_foreign_cc_tools, ninja_mac = "ninja_1.12.1_mac") + register_toolchains( "//:ninja_mac_arm64_toolchain", ) @@ -66,28 +70,29 @@ LLVM_VERSIONS = { llvm.toolchain( name = "llvm_toolchain", - llvm_versions = LLVM_VERSIONS, cxx_standard = {"": "c++17"}, + llvm_versions = LLVM_VERSIONS, ) llvm.extra_target_compatible_with( name = "llvm_toolchain", constraints = ["@//:cxx17"], ) use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm") + register_toolchains("@llvm_toolchain//:all") llvm.toolchain( name = "llvm_toolchain_cxx20", - llvm_versions = LLVM_VERSIONS, cxx_standard = {"": "c++20"}, + llvm_versions = LLVM_VERSIONS, ) llvm.extra_target_compatible_with( name = "llvm_toolchain_cxx20", constraints = ["//:cxx20"], ) use_repo(llvm, "llvm_toolchain_cxx20") -register_toolchains("@llvm_toolchain_cxx20//:all") +register_toolchains("@llvm_toolchain_cxx20//:all") # Example toolchain with user provided URLs. # TODO(siddharthab): Add test. @@ -132,6 +137,7 @@ llvm.toolchain( absolute_paths = True, llvm_versions = LLVM_VERSIONS, ) + # We can share the downloaded LLVM distribution with the first configuration. llvm.toolchain_root( name = "llvm_toolchain_with_absolute_paths", @@ -144,6 +150,7 @@ llvm.toolchain( name = "llvm_toolchain_with_system_llvm", llvm_versions = LLVM_VERSIONS, ) + # For this toolchain to work, the LLVM distribution archive would need to be unpacked here. llvm.toolchain_root( name = "llvm_toolchain_with_system_llvm", @@ -156,6 +163,7 @@ llvm.toolchain( name = "llvm_toolchain_with_sysroot", llvm_versions = LLVM_VERSIONS, ) + # We can share the downloaded LLVM distribution with the first configuration. llvm.toolchain_root( name = "llvm_toolchain_with_sysroot", @@ -163,28 +171,30 @@ llvm.toolchain_root( ) llvm.sysroot( name = "llvm_toolchain_with_sysroot", - targets = ["linux-x86_64"], label = "@org_chromium_sysroot_linux_x64//:sysroot", + targets = ["linux-x86_64"], ) use_repo(llvm, "llvm_toolchain_with_sysroot") - llvm.toolchain( name = "llvm_toolchain_linux_exec", + exec_arch = "amd64", + # Option 2: + # distribution = "clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz", + exec_os = "linux", llvm_version = "17.0.6", # Option 1: sha256 = {"": "884ee67d647d77e58740c1e645649e29ae9e8a6fe87c1376be0f3a30f3cc9ab3"}, strip_prefix = {"": "clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04"}, urls = {"": ["https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz"]}, - # Option 2: - # distribution = "clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz", - exec_os = "linux", - exec_arch = "amd64", ) use_repo(llvm, "llvm_toolchain_linux_exec") # Toolchain example for WebAssembly. llvm.toolchain( name = "llvm_toolchain_wasm", + libclang_rt = { + "@libclang_rt_wasm32//:libclang_rt.builtins-wasm32.a": "wasm32-unknown-unknown/libclang_rt.builtins.a", + }, # WebAssembly tests use a separate (newer) version of LLVM to exercise # support for experimental features such as wasm64. llvm_versions = { @@ -195,9 +205,6 @@ llvm.toolchain( "wasm32": "libc", "wasm64": "none", }, - libclang_rt = { - "@libclang_rt_wasm32//:libclang_rt.builtins-wasm32.a": "wasm32-unknown-unknown/libclang_rt.builtins.a", - }, ) llvm.sysroot( name = "llvm_toolchain_wasm", @@ -209,17 +216,20 @@ llvm.sysroot( label = "@wasi_sdk_sysroots//empty", targets = ["wasm64"], ) - use_repo(llvm, "llvm_toolchain_wasm") + register_toolchains("@llvm_toolchain_wasm//:all") wasi_sdk_sysroots = use_repo_rule("//wasm:wasi_sdk.bzl", "wasi_sdk_sysroots") + wasi_sdk_sysroots(name = "wasi_sdk_sysroots") libclang_rt_wasm32 = use_repo_rule("//wasm:wasi_sdk.bzl", "libclang_rt_wasm32") + libclang_rt_wasm32(name = "libclang_rt_wasm32") http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + # This sysroot is used by github.com/vsco/bazel-toolchains. http_archive( name = "org_chromium_sysroot_linux_x64", diff --git a/tests/WORKSPACE b/tests/WORKSPACE index ede3e3ed..4e646cd8 100644 --- a/tests/WORKSPACE +++ b/tests/WORKSPACE @@ -250,6 +250,17 @@ rules_rust_dependencies() rust_register_toolchains() +http_archive( + name = "rules_python", + sha256 = "4f7e2aa1eb9aa722d96498f5ef514f426c1f55161c3c9ae628c857a7128ceb07", + strip_prefix = "rules_python-1.0.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/1.0.0/rules_python-1.0.0.tar.gz", +) + +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + # For testing rules_foreign_cc. # See https://bazelbuild.github.io/rules_foreign_cc/0.6.0/cmake.html @@ -260,6 +271,27 @@ http_archive( url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.13.0.tar.gz", ) +http_archive( + name = "com_google_protobuf", + sha256 = "537d1c4edb6cbfa96d98a021650e3c455fffcf80dbdcea7fe46cb356e6e9732d", + strip_prefix = "protobuf-29.0-rc3", + urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v29.0-rc3/protobuf-29.0-rc3.zip"], +) + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() + +http_archive( + name = "rules_java", + sha256 = "6d8c6d5cd86fed031ee48424f238fa35f33abc9921fd97dd4ae1119a29fc807f", + urls = ["https://github.com/bazelbuild/rules_java/releases/download/8.6.3/rules_java-8.6.3.tar.gz"], +) + +load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies") + +rules_java_dependencies() + load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") rules_foreign_cc_dependencies() diff --git a/tests/scripts/bazel.sh b/tests/scripts/bazel.sh index 3d61674f..a7db03c7 100644 --- a/tests/scripts/bazel.sh +++ b/tests/scripts/bazel.sh @@ -38,6 +38,7 @@ readonly bazel common_args=( "--enable_bzlmod=${USE_BZLMOD:-true}" + "--enable_workspace" ) # shellcheck disable=SC2034 diff --git a/tests/scripts/run_external_tests.sh b/tests/scripts/run_external_tests.sh index c12cd7ee..46646924 100755 --- a/tests/scripts/run_external_tests.sh +++ b/tests/scripts/run_external_tests.sh @@ -24,7 +24,12 @@ cd "${scripts_dir}" # Generate some files needed for the tests. "${bazel}" query "${common_args[@]}" @io_bazel_rules_go//tests/core/cgo:dylib_test >/dev/null if [[ ${USE_BZLMOD} == "true" ]]; then - "$("${bazel}" info output_base)/external/rules_go~/tests/core/cgo/generate_imported_dylib.sh" + script="$("${bazel}" info output_base)/external/rules_go~/tests/core/cgo/generate_imported_dylib.sh" + if [[ -f "${script}" ]]; then + "${script}" + else + "$("${bazel}" info output_base)/external/rules_go+/tests/core/cgo/generate_imported_dylib.sh" + fi else "$("${bazel}" info output_base)/external/io_bazel_rules_go/tests/core/cgo/generate_imported_dylib.sh" fi diff --git a/toolchain/deps.bzl b/toolchain/deps.bzl index 5c372a45..04903a5a 100644 --- a/toolchain/deps.bzl +++ b/toolchain/deps.bzl @@ -19,9 +19,9 @@ def bazel_toolchain_dependencies(): if not native.existing_rule("rules_cc"): 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", + urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz"], + sha256 = "abc605dd850f813bb37004b77db20106a19311a96b2da1c92b789da529d28fe1", + strip_prefix = "rules_cc-0.0.17", ) # Load bazel_skylib if the user has not defined them.