From 93bd7457939e8e5706b4e6f66a152ea512df0633 Mon Sep 17 00:00:00 2001 From: Tim Trippel Date: Thu, 10 Oct 2024 13:47:44 -0700 Subject: [PATCH 1/2] [bazel] move proto deps to separate macro / file This moves the protobuf bazel deps to a separate macro and file. Additionally, this adds constants to encode go and protobuf bazel dep versions to enable easier updating of these deps in the future. Signed-off-by: Tim Trippel --- WORKSPACE | 22 +++++++++++++--------- src/proto/BUILD.bazel | 2 +- third_party/docker/BUILD.bazel | 2 ++ third_party/go/BUILD.bazel | 2 ++ third_party/go/repos.bzl | 12 ++++++------ third_party/google/repos.bzl | 20 -------------------- third_party/protobuf/BUILD.bazel | 5 +++++ third_party/protobuf/repos.bzl | 27 +++++++++++++++++++++++++++ 8 files changed, 56 insertions(+), 36 deletions(-) create mode 100644 third_party/protobuf/BUILD.bazel create mode 100644 third_party/protobuf/repos.bzl diff --git a/WORKSPACE b/WORKSPACE index 1115164..cdf9208 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -34,21 +34,21 @@ crt_register_toolchains( win64 = True, ) +# Google dependencies. +# BoringSSL, RE2, GoogleTest, Protobuf Matchers, ABSL. +load("//third_party/google:repos.bzl", "google_repos") +google_repos() + # gazelle:repository_macro third_party/go/deps.bzl%go_packages_ load("//third_party/go:repos.bzl", "go_repos") go_repos() load("//third_party/go:deps.bzl", "go_deps") go_deps() -# Various linters. -load("//third_party/lint:repos.bzl", "lint_repos") -lint_repos() - -# Google dependencies. -# BoringSSL, RE2, GoogleTest, Protobuf Matchers, ABSL, Protobuf, gRPC. -load("//third_party/google:repos.bzl", "google_repos") -google_repos() -# Load the deps from the Google repos in the correct order. +# Protobuf rules. +load("//third_party/protobuf:repos.bzl", "protobuf_repos") +protobuf_repos() +# Load the proto deps in the right order load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") @@ -56,6 +56,10 @@ grpc_deps() load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") grpc_extra_deps() +# Various linters. +load("//third_party/lint:repos.bzl", "lint_repos") +lint_repos() + # Foreign CC and packaging/release rules. load("//third_party/bazel:repos.bzl", "bazel_repos") bazel_repos() diff --git a/src/proto/BUILD.bazel b/src/proto/BUILD.bazel index b05a4ff..8988a5a 100644 --- a/src/proto/BUILD.bazel +++ b/src/proto/BUILD.bazel @@ -4,9 +4,9 @@ # OT Provisioning Protobuf Definitions -load("@rules_proto//proto:defs.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") package(default_visibility = ["//visibility:public"]) diff --git a/third_party/docker/BUILD.bazel b/third_party/docker/BUILD.bazel index 3e8bb41..c85882e 100644 --- a/third_party/docker/BUILD.bazel +++ b/third_party/docker/BUILD.bazel @@ -1,3 +1,5 @@ # Copyright lowRISC contributors (OpenTitan project). # Licensed under the Apache License, Version 2.0, see LICENSE for details. # SPDX-License-Identifier: Apache-2.0 + +package(default_visibility = ["//visibility:public"]) diff --git a/third_party/go/BUILD.bazel b/third_party/go/BUILD.bazel index 3e8bb41..c85882e 100644 --- a/third_party/go/BUILD.bazel +++ b/third_party/go/BUILD.bazel @@ -1,3 +1,5 @@ # Copyright lowRISC contributors (OpenTitan project). # Licensed under the Apache License, Version 2.0, see LICENSE for details. # SPDX-License-Identifier: Apache-2.0 + +package(default_visibility = ["//visibility:public"]) diff --git a/third_party/go/repos.bzl b/third_party/go/repos.bzl index 75f7003..de55455 100644 --- a/third_party/go/repos.bzl +++ b/third_party/go/repos.bzl @@ -4,14 +4,17 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +_RULES_GO_VERSION = "0.34.0" +_GAZELLE_VERSION = "0.24.0" + def go_repos(): # Go toolchain http_archive( name = "io_bazel_rules_go", sha256 = "16e9fca53ed6bd4ff4ad76facc9b7b651a89db1689a2877d6fd7b82aa824e366", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v{}/rules_go-v{}.zip".format(_RULES_GO_VERSION, _RULES_GO_VERSION), + "https://github.com/bazelbuild/rules_go/releases/download/v{}/rules_go-v{}.zip".format(_RULES_GO_VERSION, _RULES_GO_VERSION), ], ) @@ -19,8 +22,5 @@ def go_repos(): http_archive( name = "bazel_gazelle", sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", - ], + url = "https://github.com/bazelbuild/bazel-gazelle/releases/download/v{}/bazel-gazelle-v{}.tar.gz".format(_GAZELLE_VERSION, _GAZELLE_VERSION), ) diff --git a/third_party/google/repos.bzl b/third_party/google/repos.bzl index c98fd49..5814aa8 100644 --- a/third_party/google/repos.bzl +++ b/third_party/google/repos.bzl @@ -49,23 +49,3 @@ def google_repos(): strip_prefix = "abseil-cpp-20230125.0", sha256 = "3ea49a7d97421b88a8c48a0de16c16048e17725c7ec0f1d3ea2683a2a75adc21", ) - - # Protobuf toolchain - http_archive( - name = "com_google_protobuf", - urls = [ - "https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protobuf-all-3.17.3.tar.gz", - ], - strip_prefix = "protobuf-3.17.3", - sha256 = "77ad26d3f65222fd96ccc18b055632b0bfedf295cb748b712a98ba1ac0b704b2", - ) - - # gRPC - http_archive( - name = "com_github_grpc_grpc", - sha256 = "ec19657a677d49af59aa806ec299c070c882986c9fcc022b1c22c2a3caf01bcd", - strip_prefix = "grpc-1.45.0", - urls = ["https://github.com/grpc/grpc/archive/refs/tags/v1.45.0.tar.gz"], - patches = [Label("//third_party/google:grpc-windows-constraints.patch")], - patch_args = ["-p1"], - ) diff --git a/third_party/protobuf/BUILD.bazel b/third_party/protobuf/BUILD.bazel new file mode 100644 index 0000000..c85882e --- /dev/null +++ b/third_party/protobuf/BUILD.bazel @@ -0,0 +1,5 @@ +# Copyright lowRISC contributors (OpenTitan project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +package(default_visibility = ["//visibility:public"]) diff --git a/third_party/protobuf/repos.bzl b/third_party/protobuf/repos.bzl new file mode 100644 index 0000000..310304f --- /dev/null +++ b/third_party/protobuf/repos.bzl @@ -0,0 +1,27 @@ +# Copyright lowRISC contributors (OpenTitan project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +_PROTOBUF_VERSION = "3.17.3" +_GRPC_VERSION = "1.45.0" + +def protobuf_repos(): + # Protobuf toolchain + http_archive( + name = "com_google_protobuf", + url = "https://github.com/protocolbuffers/protobuf/releases/download/v{}/protobuf-all-{}.tar.gz".format(_PROTOBUF_VERSION, _PROTOBUF_VERSION), + sha256 = "77ad26d3f65222fd96ccc18b055632b0bfedf295cb748b712a98ba1ac0b704b2", + strip_prefix = "protobuf-{}".format(_PROTOBUF_VERSION), + ) + + #gRPC + http_archive( + name = "com_github_grpc_grpc", + sha256 = "ec19657a677d49af59aa806ec299c070c882986c9fcc022b1c22c2a3caf01bcd", + strip_prefix = "grpc-{}".format(_GRPC_VERSION), + url = "https://github.com/grpc/grpc/archive/refs/tags/v{}.tar.gz".format(_GRPC_VERSION), + patches = [Label("//third_party/google:grpc-windows-constraints.patch")], + patch_args = ["-p1"], + ) From 0a5e4a4508efbbe2e96707950fe49bef898cba19 Mon Sep 17 00:00:00 2001 From: Tim Trippel Date: Thu, 10 Oct 2024 14:32:23 -0700 Subject: [PATCH 2/2] [bazel] bump bazel version to 6.2.1 This updates the Bazel version to 6.2.1 to match the bazel version used in the lowRISC/opentitan repo on the `earlgrey_1.0.0` branch. Additionally, the protobuf and gRPC dep versions required updating to work with Bazel 6.2.1. Signed-off-by: Tim Trippel --- .bazelversion | 2 +- WORKSPACE | 11 ++++++----- third_party/protobuf/grpc-go-toolchain.patch | 13 +++++++++++++ .../grpc-windows-constraints.patch | 0 third_party/protobuf/repos.bzl | 13 ++++++++----- 5 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 third_party/protobuf/grpc-go-toolchain.patch rename third_party/{google => protobuf}/grpc-windows-constraints.patch (100%) diff --git a/.bazelversion b/.bazelversion index 91ff572..024b066 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.2.0 +6.2.1 diff --git a/WORKSPACE b/WORKSPACE index cdf9208..d2e1c6a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -34,17 +34,18 @@ crt_register_toolchains( win64 = True, ) -# Google dependencies. -# BoringSSL, RE2, GoogleTest, Protobuf Matchers, ABSL. -load("//third_party/google:repos.bzl", "google_repos") -google_repos() - +# Go dependencies. # gazelle:repository_macro third_party/go/deps.bzl%go_packages_ load("//third_party/go:repos.bzl", "go_repos") go_repos() load("//third_party/go:deps.bzl", "go_deps") go_deps() +# Google dependencies. +# BoringSSL, RE2, GoogleTest, Protobuf Matchers, ABSL. +load("//third_party/google:repos.bzl", "google_repos") +google_repos() + # Protobuf rules. load("//third_party/protobuf:repos.bzl", "protobuf_repos") protobuf_repos() diff --git a/third_party/protobuf/grpc-go-toolchain.patch b/third_party/protobuf/grpc-go-toolchain.patch new file mode 100644 index 0000000..b58e554 --- /dev/null +++ b/third_party/protobuf/grpc-go-toolchain.patch @@ -0,0 +1,13 @@ +diff --git a/bazel/grpc_extra_deps.bzl b/bazel/grpc_extra_deps.bzl +index 4d8afa3131..514189f9a5 100644 +--- a/bazel/grpc_extra_deps.bzl ++++ b/bazel/grpc_extra_deps.bzl +@@ -53,7 +53,7 @@ def grpc_extra_deps(ignore_version_differences = False): + api_dependencies() + + go_rules_dependencies() +- go_register_toolchains(version = "1.18") ++ go_register_toolchains() + gazelle_dependencies() + + # Pull-in the go 3rd party dependencies for protoc_gen_validate, which is diff --git a/third_party/google/grpc-windows-constraints.patch b/third_party/protobuf/grpc-windows-constraints.patch similarity index 100% rename from third_party/google/grpc-windows-constraints.patch rename to third_party/protobuf/grpc-windows-constraints.patch diff --git a/third_party/protobuf/repos.bzl b/third_party/protobuf/repos.bzl index 310304f..2efb61c 100644 --- a/third_party/protobuf/repos.bzl +++ b/third_party/protobuf/repos.bzl @@ -4,24 +4,27 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -_PROTOBUF_VERSION = "3.17.3" -_GRPC_VERSION = "1.45.0" +_PROTOBUF_VERSION = "3.20.1" +_GRPC_VERSION = "1.52.0" def protobuf_repos(): # Protobuf toolchain http_archive( name = "com_google_protobuf", url = "https://github.com/protocolbuffers/protobuf/releases/download/v{}/protobuf-all-{}.tar.gz".format(_PROTOBUF_VERSION, _PROTOBUF_VERSION), - sha256 = "77ad26d3f65222fd96ccc18b055632b0bfedf295cb748b712a98ba1ac0b704b2", + sha256 = "3a400163728db996e8e8d21c7dfb3c239df54d0813270f086c4030addeae2fad", strip_prefix = "protobuf-{}".format(_PROTOBUF_VERSION), ) #gRPC http_archive( name = "com_github_grpc_grpc", - sha256 = "ec19657a677d49af59aa806ec299c070c882986c9fcc022b1c22c2a3caf01bcd", + sha256 = "df9608a5bd4eb6d6b78df75908bb3390efdbbb9e07eddbee325e98cdfad6acd5", strip_prefix = "grpc-{}".format(_GRPC_VERSION), url = "https://github.com/grpc/grpc/archive/refs/tags/v{}.tar.gz".format(_GRPC_VERSION), - patches = [Label("//third_party/google:grpc-windows-constraints.patch")], + patches = [ + Label("//third_party/protobuf:grpc-windows-constraints.patch"), + Label("//third_party/protobuf:grpc-go-toolchain.patch"), + ], patch_args = ["-p1"], )