Skip to content

Commit

Permalink
Update cc_proto to 0.1.0 and remove rules_proto dep
Browse files Browse the repository at this point in the history
Closes bufbuild#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.
  • Loading branch information
kgreenek committed Dec 27, 2024
1 parent 4027b94 commit ff84910
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 55 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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()
11 changes: 11 additions & 0 deletions bazel/dependency_imports.bzl
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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()

Expand Down
7 changes: 4 additions & 3 deletions bazel/extra_dependency_imports.bzl
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions bazel/protobuf.bzl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
99 changes: 70 additions & 29 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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"):
Expand Down Expand Up @@ -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",
)
2 changes: 1 addition & 1 deletion java/pgv-java-grpc/src/test/proto/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion java/pgv-java-stub/src/test/proto/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 2 additions & 5 deletions tests/generation/multi_file_java_test/BUILD
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/harness/BUILD
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/harness/cases/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/harness/cases/other_package/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -71,6 +71,6 @@ pgv_java_proto_library(

py_proto_library(
name = "embed_python_proto",
deps = [":embed_proto"],
visibility = ["//visibility:public"],
deps = [":embed_proto"],
)
4 changes: 2 additions & 2 deletions tests/harness/cases/sort/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -71,6 +71,6 @@ pgv_java_proto_library(

py_proto_library(
name = "sort_python_proto",
deps = [":sort_proto"],
visibility = ["//visibility:public"],
deps = [":sort_proto"],
)
4 changes: 2 additions & 2 deletions tests/harness/cases/yet_another_package/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -71,6 +71,6 @@ pgv_java_proto_library(

py_proto_library(
name = "embed_python_proto",
deps = [":embed_proto"],
visibility = ["//visibility:public"],
deps = [":embed_proto"],
)
5 changes: 3 additions & 2 deletions tests/harness/cc/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions validate/BUILD
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit ff84910

Please sign in to comment.