From ff849102dc01dab230587df4b095d569e5ad9cd2 Mon Sep 17 00:00:00 2001 From: Kevin Greene Date: Fri, 27 Dec 2024 10:16:25 -0800 Subject: [PATCH] Update cc_proto to 0.1.0 and remove rules_proto dep Closes https://github.com/bufbuild/protoc-gen-validate/issues/1199 rules_proto has been deprecated and should no longer be used. rules_cc removed the proto-related bazel rules as of 0.1.0. Instead, these rules now live in com_google_protobuf and should be used from there. Several other dependencies also had to be updated to support the changes in com_google_protobuf and cc_proto. --- WORKSPACE | 2 +- bazel/dependency_imports.bzl | 11 +++ bazel/extra_dependency_imports.bzl | 7 +- bazel/protobuf.bzl | 4 +- bazel/repositories.bzl | 99 +++++++++++++------ java/pgv-java-grpc/src/test/proto/BUILD.bazel | 2 +- java/pgv-java-stub/src/test/proto/BUILD.bazel | 2 +- tests/generation/multi_file_java_test/BUILD | 7 +- tests/harness/BUILD | 4 +- tests/harness/cases/BUILD | 2 +- tests/harness/cases/other_package/BUILD | 4 +- tests/harness/cases/sort/BUILD | 4 +- tests/harness/cases/yet_another_package/BUILD | 4 +- tests/harness/cc/BUILD | 5 +- validate/BUILD | 4 +- 15 files changed, 106 insertions(+), 55 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 6e5744726..db92b7b2e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,6 +16,6 @@ load("//bazel:extra_dependency_imports.bzl", "pgv_extra_dependency_imports") pgv_extra_dependency_imports() -load("@maven//:defs.bzl", "pinned_maven_install") +load("@protobuf_maven//:defs.bzl", "pinned_maven_install") pinned_maven_install() diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index 666edf7a8..dd3145d9c 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -1,6 +1,10 @@ +load("@bazel_features//:deps.bzl", "bazel_features_deps") load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies") +load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies") load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains") load("@rules_python//python:pip.bzl", "pip_parse") @@ -21,6 +25,13 @@ def _pgv_go_dependencies(): gazelle_dependencies() def pgv_dependency_imports(): + bazel_skylib_workspace() + bazel_features_deps() + + rules_java_dependencies() + + rules_jvm_external_deps() + # Import @com_google_protobuf's dependencies. protobuf_deps() diff --git a/bazel/extra_dependency_imports.bzl b/bazel/extra_dependency_imports.bzl index b78260665..f921d97f7 100644 --- a/bazel/extra_dependency_imports.bzl +++ b/bazel/extra_dependency_imports.bzl @@ -1,18 +1,19 @@ -load("@bazel_features//:deps.bzl", "bazel_features_deps") load("@com_google_protobuf//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS") load("@pgv_pip_deps//:requirements.bzl", "install_deps") load("@rules_jvm_external//:defs.bzl", "maven_install") +load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup") load("//:dependencies.bzl", "go_third_party") def pgv_extra_dependency_imports(): - bazel_features_deps() - install_deps() # gazelle:repository_macro dependencies.bzl%go_third_party go_third_party() + rules_jvm_external_setup() + maven_install( + name = "protobuf_maven", artifacts = PROTOBUF_MAVEN_ARTIFACTS, maven_install_json = "@com_google_protobuf//:maven_install.json", repositories = [ diff --git a/bazel/protobuf.bzl b/bazel/protobuf.bzl index 08d9d561e..1263aafdb 100644 --- a/bazel/protobuf.bzl +++ b/bazel/protobuf.bzl @@ -1,6 +1,6 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") -load("@bazel_tools//tools/jdk:toolchain_utils.bzl", "find_java_runtime_toolchain", "find_java_toolchain") -load("@rules_proto//proto:defs.bzl", "ProtoInfo") +load("@bazel_tools//tools/jdk:toolchain_utils.bzl", "find_java_toolchain") +load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") # Borrowed from https://github.com/grpc/grpc-java/blob/v1.28.0/java_grpc_library.bzl#L59 # "repository" here is for Bazel builds that span multiple WORKSPACES. diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index a585c0c42..92647a1b2 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -14,6 +14,59 @@ def pgv_dependencies(maven_repos = _DEFAULT_REPOSITORIES): ], ) + if not native.existing_rule("rules_python"): + http_archive( + name = "rules_python", + sha256 = "4912ced70dc1a2a8e4b86cec233b192ca053e82bc72d877b98e126156e8f228d", + strip_prefix = "rules_python-0.32.2", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.32.2/rules_python-0.32.2.tar.gz", + ) + + if not native.existing_rule("rules_cc"): + http_archive( + name = "rules_cc", + sha256 = "4b12149a041ddfb8306a8fd0e904e39d673552ce82e4296e96fac9cbf0780e59", + strip_prefix = "rules_cc-0.1.0", + url = "https://github.com/bazelbuild/rules_cc/releases/download/0.1.0/rules_cc-0.1.0.tar.gz", + ) + + if not native.existing_rule("bazel_features"): + http_archive( + name = "bazel_features", + sha256 = "8b1c9b7558498000f5adebbc584b7bf15b6b2bf181448a66f6b2fc5b4c84231c", + strip_prefix = "bazel_features-1.23.0", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.23.0/bazel_features-v1.23.0.tar.gz", + ) + + if not native.existing_rule("rules_license"): + http_archive( + name = "rules_license", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz", + "https://github.com/bazelbuild/rules_license/releases/download/1.0.0/rules_license-1.0.0.tar.gz", + ], + sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38", + ) + + if not native.existing_rule("rules_jvm_external"): + RULES_JVM_EXTERNAL_TAG = "6.6" + RULES_JVM_EXTERNAL_SHA = "3afe5195069bd379373528899c03a3072f568d33bd96fe037bd43b1f590535e7" + http_archive( + name = "rules_jvm_external", + strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, + sha256 = RULES_JVM_EXTERNAL_SHA, + url = "https://github.com/bazel-contrib/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (RULES_JVM_EXTERNAL_TAG, RULES_JVM_EXTERNAL_TAG), + ) + + if not native.existing_rule("rules_java"): + http_archive( + name = "rules_java", + urls = [ + "https://github.com/bazelbuild/rules_java/releases/download/8.6.3/rules_java-8.6.3.tar.gz", + ], + sha256 = "6d8c6d5cd86fed031ee48424f238fa35f33abc9921fd97dd4ae1119a29fc807f", + ) + if not native.existing_rule("bazel_gazelle"): http_archive( name = "bazel_gazelle", @@ -24,9 +77,18 @@ def pgv_dependencies(maven_repos = _DEFAULT_REPOSITORIES): if not native.existing_rule("com_google_protobuf"): http_archive( name = "com_google_protobuf", - url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz", - sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa", - strip_prefix = "protobuf-27.0", + url = "https://github.com/protocolbuffers/protobuf/releases/download/v29.2/protobuf-29.2.tar.gz", + sha256 = "63150aba23f7a90fd7d87bdf514e459dd5fe7023fdde01b56ac53335df64d4bd", + strip_prefix = "protobuf-29.2", + ) + + # NOTE: Even though this is not directly used, rules_go requires this still. + if not native.existing_rule("rules_proto"): + http_archive( + name = "rules_proto", + sha256 = "14a225870ab4e91869652cfd69ef2028277fc1dc4910d65d353b62d6e0ae21f4", + strip_prefix = "rules_proto-7.1.0", + url = "https://github.com/bazelbuild/rules_proto/releases/download/7.1.0/rules_proto-7.1.0.tar.gz", ) # TODO(akonradi): This shouldn't be necessary since the same http_archive block is imported by @@ -43,8 +105,11 @@ def pgv_dependencies(maven_repos = _DEFAULT_REPOSITORIES): if not native.existing_rule("bazel_skylib"): http_archive( name = "bazel_skylib", - sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa", - urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz"], + sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz", + ], ) if not native.existing_rule("com_google_re2j"): @@ -78,27 +143,3 @@ def pgv_dependencies(maven_repos = _DEFAULT_REPOSITORIES): artifact_sha256 = "bd62795d7068a69cbea333f6dbf9c9c1a6ad7521443fb57202a44874f240ba25", server_urls = maven_repos, ) - - if not native.existing_rule("rules_python"): - http_archive( - name = "rules_python", - sha256 = "4912ced70dc1a2a8e4b86cec233b192ca053e82bc72d877b98e126156e8f228d", - strip_prefix = "rules_python-0.32.2", - url = "https://github.com/bazelbuild/rules_python/releases/download/0.32.2/rules_python-0.32.2.tar.gz", - ) - - if not native.existing_rule("rules_proto"): - http_archive( - name = "rules_proto", - sha256 = "303e86e722a520f6f326a50b41cfc16b98fe6d1955ce46642a5b7a67c11c0f5d", - strip_prefix = "rules_proto-6.0.0", - url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.0/rules_proto-6.0.0.tar.gz", - ) - - if not native.existing_rule("rules_cc"): - http_archive( - name = "rules_cc", - sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf", - strip_prefix = "rules_cc-0.0.9", - url = "https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz", - ) diff --git a/java/pgv-java-grpc/src/test/proto/BUILD.bazel b/java/pgv-java-grpc/src/test/proto/BUILD.bazel index c7c3d7090..43000e27f 100644 --- a/java/pgv-java-grpc/src/test/proto/BUILD.bazel +++ b/java/pgv-java-grpc/src/test/proto/BUILD.bazel @@ -1,6 +1,6 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") proto_library( name = "io_envoyproxy_pgv_grpc_proto", diff --git a/java/pgv-java-stub/src/test/proto/BUILD.bazel b/java/pgv-java-stub/src/test/proto/BUILD.bazel index 42fb9d8a9..7f9d67381 100644 --- a/java/pgv-java-stub/src/test/proto/BUILD.bazel +++ b/java/pgv-java-stub/src/test/proto/BUILD.bazel @@ -1,5 +1,5 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") proto_library( name = "io_envoyproxy_pvg_cases_proto", diff --git a/tests/generation/multi_file_java_test/BUILD b/tests/generation/multi_file_java_test/BUILD index 049a9d1ac..32a95dc4f 100644 --- a/tests/generation/multi_file_java_test/BUILD +++ b/tests/generation/multi_file_java_test/BUILD @@ -1,9 +1,6 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@rules_cc//cc:defs.bzl", "cc_binary") -load("@rules_proto//proto:defs.bzl", "proto_library") -load( - "//bazel:pgv_proto_library.bzl", - "pgv_cc_proto_library", -) +load("//bazel:pgv_proto_library.bzl", "pgv_cc_proto_library") # gazelle:go_generate_proto false diff --git a/tests/harness/BUILD b/tests/harness/BUILD index f206df7b4..a5b0603d6 100644 --- a/tests/harness/BUILD +++ b/tests/harness/BUILD @@ -1,8 +1,8 @@ +load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:proto.bzl", "py_proto_library") proto_library( diff --git a/tests/harness/cases/BUILD b/tests/harness/cases/BUILD index adb0ec86f..fca3fe5dc 100644 --- a/tests/harness/cases/BUILD +++ b/tests/harness/cases/BUILD @@ -1,5 +1,5 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:proto.bzl", "py_proto_library") load( "//bazel:pgv_proto_library.bzl", diff --git a/tests/harness/cases/other_package/BUILD b/tests/harness/cases/other_package/BUILD index ed14ab064..f0ab1024d 100644 --- a/tests/harness/cases/other_package/BUILD +++ b/tests/harness/cases/other_package/BUILD @@ -1,7 +1,7 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:proto.bzl", "py_proto_library") load( "//bazel:pgv_proto_library.bzl", @@ -71,6 +71,6 @@ pgv_java_proto_library( py_proto_library( name = "embed_python_proto", - deps = [":embed_proto"], visibility = ["//visibility:public"], + deps = [":embed_proto"], ) diff --git a/tests/harness/cases/sort/BUILD b/tests/harness/cases/sort/BUILD index 1077297b9..423efb097 100644 --- a/tests/harness/cases/sort/BUILD +++ b/tests/harness/cases/sort/BUILD @@ -1,7 +1,7 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:proto.bzl", "py_proto_library") load( "//bazel:pgv_proto_library.bzl", @@ -71,6 +71,6 @@ pgv_java_proto_library( py_proto_library( name = "sort_python_proto", - deps = [":sort_proto"], visibility = ["//visibility:public"], + deps = [":sort_proto"], ) diff --git a/tests/harness/cases/yet_another_package/BUILD b/tests/harness/cases/yet_another_package/BUILD index 5518b6a55..4f631b5bc 100644 --- a/tests/harness/cases/yet_another_package/BUILD +++ b/tests/harness/cases/yet_another_package/BUILD @@ -1,7 +1,7 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:proto.bzl", "py_proto_library") load( "//bazel:pgv_proto_library.bzl", @@ -71,6 +71,6 @@ pgv_java_proto_library( py_proto_library( name = "embed_python_proto", - deps = [":embed_proto"], visibility = ["//visibility:public"], + deps = [":embed_proto"], ) diff --git a/tests/harness/cc/BUILD b/tests/harness/cc/BUILD index 929a826c8..bdd99d8a2 100644 --- a/tests/harness/cc/BUILD +++ b/tests/harness/cc/BUILD @@ -1,5 +1,6 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "cc_test") -load("@rules_proto//proto:defs.bzl", "proto_library") +load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") MSVC_C_OPTS = [ "-WX", diff --git a/validate/BUILD b/validate/BUILD index 7d40181e9..31ff5c9a2 100644 --- a/validate/BUILD +++ b/validate/BUILD @@ -1,8 +1,8 @@ +load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:proto.bzl", "py_proto_library") package(