Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tongke6 authored Dec 18, 2024
1 parent 7a5f0ea commit 7a06a83
Show file tree
Hide file tree
Showing 10 changed files with 380 additions and 0 deletions.
32 changes: 32 additions & 0 deletions modules/protobuf/25.5/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/protocolbuffers/protobuf/issues/14313

module(
name = "protobuf",
version = "25.5",
compatibility_level = 1,
repo_name = "com_google_protobuf",
)

# LOWER BOUND dependency versions.
# Bzlmod follows MVS:
# https://bazel.build/versions/6.0.0/build/bzlmod#version-resolution
# Thus the highest version in their module graph is resolved.
bazel_dep(name = "abseil-cpp", version = "20230802.0.bcr.1", repo_name = "com_google_absl")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "jsoncpp", version = "1.9.5")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_java", version = "4.0.0")
bazel_dep(name = "rules_jvm_external", version = "5.1")
bazel_dep(name = "rules_pkg", version = "0.7.0")
bazel_dep(name = "rules_python", version = "0.10.2")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "zlib", version = "1.2.11")

# TODO: remove after toolchain types are moved to protobuf
bazel_dep(name = "rules_proto", version = "4.0.0")

# Do not take the effort to convert utf8_range to Bzlmod as this has been moved to protobuf/third_party
# See https://github.com/protocolbuffers/utf8_range/commit/1d1ea7e3fedf482d4a12b473c1ed25fe0f371a45
non_module_deps = use_extension("//:non_module_deps.bzl", "non_module_deps")
use_repo(non_module_deps, "utf8_range")
31 changes: 31 additions & 0 deletions modules/protobuf/25.5/patches/0001-Add-MODULE.bazel.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/MODULE.bazel b/MODULE.bazel
index 2d43e46df..ea70894de 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,2 +1,26 @@
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/protocolbuffers/protobuf/issues/14313
+
+module(
+ name = "protobuf",
+ version = "25.5",
+ compatibility_level = 1,
+)
+
+# LOWER BOUND dependency versions.
+# Bzlmod follows MVS:
+# https://bazel.build/versions/6.0.0/build/bzlmod#version-resolution
+# Thus the highest version in their module graph is resolved.
+bazel_dep(name = "abseil-cpp", version = "20230802.0.bcr.1", repo_name = "com_google_absl")
+bazel_dep(name = "bazel_skylib", version = "1.4.1")
+bazel_dep(name = "jsoncpp", version = "1.9.5")
+bazel_dep(name = "rules_cc", version = "0.0.9")
+bazel_dep(name = "rules_java", version = "4.0.0")
+bazel_dep(name = "rules_jvm_external", version = "5.1")
+bazel_dep(name = "rules_pkg", version = "0.7.0")
+bazel_dep(name = "rules_python", version = "0.10.2")
+bazel_dep(name = "platforms", version = "0.0.8")
+bazel_dep(name = "zlib", version = "1.2.11")
+
+# TODO: remove after toolchain types are moved to protobuf
+bazel_dep(name = "rules_proto", version = "4.0.0")
16 changes: 16 additions & 0 deletions modules/protobuf/25.5/patches/0002-Examples-MODULE.bazel.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel
new file mode 100644
index 000000000..7e7f44fb4
--- /dev/null
+++ b/examples/MODULE.bazel
@@ -0,0 +1,10 @@
+bazel_dep(name = "rules_cc", version = "0.0.1")
+bazel_dep(name = "rules_proto", version = "4.0.0")
+bazel_dep(name = "rules_java", version = "7.3.0")
+bazel_dep(name = "rules_pkg", version = "0.7.0")
+bazel_dep(name = "protobuf", repo_name = "com_google_protobuf")
+
+local_path_override(
+ module_name = "protobuf",
+ path = "..",
+)
15 changes: 15 additions & 0 deletions modules/protobuf/25.5/patches/0003-relative-labels.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/protobuf.bzl b/protobuf.bzl
index d96eeb4c9..cd10f01ec 100644
--- a/protobuf.bzl
+++ b/protobuf.bzl
@@ -493,8 +493,8 @@ def internal_ruby_proto_library(
srcs = [],
deps = [],
includes = ["."],
- default_runtime = "@com_google_protobuf//ruby:protobuf",
- protoc = "@com_google_protobuf//:protoc",
+ default_runtime = "//ruby:protobuf",
+ protoc = "//:protoc",
testonly = None,
visibility = ["//visibility:public"],
**kwargs):
39 changes: 39 additions & 0 deletions modules/protobuf/25.5/patches/0004-Add-utf8_range-dependency.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git a/MODULE.bazel b/MODULE.bazel
index ea70894de..37e49a5c6 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -24,3 +24,8 @@ bazel_dep(name = "zlib", version = "1.2.11")

# TODO: remove after toolchain types are moved to protobuf
bazel_dep(name = "rules_proto", version = "4.0.0")
+
+# Do not take the effort to convert utf8_range to Bzlmod as this has been moved to protobuf/third_party
+# See https://github.com/protocolbuffers/utf8_range/commit/1d1ea7e3fedf482d4a12b473c1ed25fe0f371a45
+non_module_deps = use_extension("//:non_module_deps.bzl", "non_module_deps")
+use_repo(non_module_deps, "utf8_range")
diff --git a/non_module_deps.bzl b/non_module_deps.bzl
new file mode 100644
index 000000000..0b3c57229
--- /dev/null
+++ b/non_module_deps.bzl
@@ -0,0 +1,19 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+def _github_archive(repo, commit, **kwargs):
+ repo_name = repo.split("/")[-1]
+ http_archive(
+ urls = [repo + "/archive/" + commit + ".zip"],
+ strip_prefix = repo_name + "-" + commit,
+ **kwargs
+ )
+
+def _non_module_deps_impl(ctx):
+ _github_archive(
+ name = "utf8_range",
+ repo = "https://github.com/protocolbuffers/utf8_range",
+ commit = "de0b4a8ff9b5d4c98108bdfe723291a33c52c54f",
+ sha256 = "5da960e5e5d92394c809629a03af3c7709d2d3d0ca731dacb3a9fb4bf28f7702",
+ )
+
+non_module_deps = module_extension(implementation = _non_module_deps_impl)
\ No newline at end of file
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
diff --git a/BUILD.bazel b/BUILD.bazel
index 23efee4a3..1c7ff6ee7 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -5,7 +5,7 @@ load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_librar
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
-load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
+load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library")

licenses(["notice"])

@@ -150,17 +150,6 @@ filegroup(
visibility = ["//visibility:public"],
)

-internal_ruby_proto_library(
- name = "well_known_ruby_protos",
- srcs = [":well_known_protos"],
- default_runtime = "",
- includes = ["src"],
- visibility = [
- "//conformance:__pkg__",
- "//ruby:__subpackages__",
- ],
-)
-
################################################################################
# Protocol Buffers Compiler
################################################################################
@@ -525,33 +514,6 @@ internal_php_proto_library(
],
)

-internal_ruby_proto_library(
- name = "test_messages_proto2_ruby_proto",
- testonly = 1,
- srcs = ["//src/google/protobuf:test_messages_proto2.proto"],
- includes = ["src/google/protobuf"],
- visibility = [
- "//conformance:__pkg__",
- "//ruby:__subpackages__",
- ],
-)
-
-internal_ruby_proto_library(
- name = "test_messages_proto3_ruby_proto",
- testonly = 1,
- srcs = ["//src/google/protobuf:test_messages_proto3.proto"],
- includes = [
- "src/google/protobuf",
- # The above must come first.
- "src",
- ],
- visibility = [
- "//conformance:__pkg__",
- "//ruby:__subpackages__",
- ],
- deps = [":well_known_ruby_protos"],
-)
-
filegroup(
name = "bzl_srcs",
srcs = glob(["**/*.bzl"]),
diff --git a/conformance/BUILD.bazel b/conformance/BUILD.bazel
index c4955042c..56a81c5aa 100644
--- a/conformance/BUILD.bazel
+++ b/conformance/BUILD.bazel
@@ -2,7 +2,7 @@

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "objc_library")
load("@rules_ruby//ruby:defs.bzl", "ruby_binary")
-load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
+load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load(
"@rules_pkg//:mappings.bzl",
diff --git a/protobuf.bzl b/protobuf.bzl
index cd10f01ec..efc59e8bc 100644
--- a/protobuf.bzl
+++ b/protobuf.bzl
@@ -2,7 +2,6 @@ load("@bazel_skylib//lib:versions.bzl", "versions")
load("@rules_cc//cc:defs.bzl", "objc_library")
load("@rules_proto//proto:defs.bzl", "ProtoInfo")
load("@rules_python//python:defs.bzl", "py_library")
-load("@rules_ruby//ruby:defs.bzl", "ruby_library")

def _GetPath(ctx, path):
if ctx.label.workspace_root:
@@ -490,6 +489,7 @@ def internal_objc_proto_library(

def internal_ruby_proto_library(
name,
+ ruby_library,
srcs = [],
deps = [],
includes = ["."],
@@ -506,6 +506,7 @@ def internal_ruby_proto_library(

Args:
name: the name of the ruby_proto_library.
+ ruby_library: the ruby library rules to use.
srcs: the .proto files to compile.
deps: a list of dependency labels; must be a internal_ruby_proto_library.
includes: a string indicating the include path of the .proto files.
diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl
index d055eed8c..c96090989 100644
--- a/protobuf_deps.bzl
+++ b/protobuf_deps.bzl
@@ -109,14 +109,6 @@ def protobuf_deps():
sha256 = "f9e4f6acf82449324d56669bda4bdb28b48688ad2990d8b39fa5b93ed39c9ad1",
)

- if not native.existing_rule("rules_ruby"):
- _github_archive(
- name = "rules_ruby",
- repo = "https://github.com/protocolbuffers/rules_ruby",
- commit = "b7f3e9756f3c45527be27bc38840d5a1ba690436",
- sha256 = "347927fd8de6132099fcdc58e8f7eab7bde4eb2fd424546b9cd4f1c6f8f8bad8",
- )
-
if not native.existing_rule("rules_jvm_external"):
_github_archive(
name = "rules_jvm_external",
diff --git a/ruby/BUILD.bazel b/ruby/BUILD.bazel
index cc4b477ee..847c50fcf 100755
--- a/ruby/BUILD.bazel
+++ b/ruby/BUILD.bazel
@@ -7,7 +7,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
-load("//:protobuf.bzl", "internal_ruby_proto_library")
+load("//ruby:defs.bzl", "internal_ruby_proto_library")
load("//conformance:defs.bzl", "conformance_test")
load("//:protobuf_version.bzl", "PROTOBUF_RUBY_VERSION")

diff --git a/ruby/compatibility_tests/v3.0.0/tests/BUILD.bazel b/ruby/compatibility_tests/v3.0.0/tests/BUILD.bazel
index 34a539172..697f87699 100644
--- a/ruby/compatibility_tests/v3.0.0/tests/BUILD.bazel
+++ b/ruby/compatibility_tests/v3.0.0/tests/BUILD.bazel
@@ -1,6 +1,6 @@
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_ruby//ruby:defs.bzl", "ruby_test")
-load("//:protobuf.bzl", "internal_ruby_proto_library")
+load("//ruby:defs.bzl", "internal_ruby_proto_library")

internal_ruby_proto_library(
name = "test_ruby_protos",
diff --git a/ruby/defs.bzl b/ruby/defs.bzl
new file mode 100644
index 000000000..e7610ad01
--- /dev/null
+++ b/ruby/defs.bzl
@@ -0,0 +1,24 @@
+"""Wrapper around internal_ruby_proto_library to supply our rules_ruby"""
+
+load("@rules_ruby//ruby:defs.bzl", "ruby_library")
+load("//:protobuf.bzl", _internal_ruby_proto_library = "internal_ruby_proto_library")
+
+def internal_ruby_proto_library(
+ name,
+ **kwargs):
+ """Bazel rule to create a Ruby protobuf library from proto source files
+
+ NOTE: the rule is only an internal workaround to generate protos. The
+ interface may change and the rule may be removed when bazel has introduced
+ the native rule.
+
+ Args:
+ name: the name of the ruby_proto_library.
+ **kwargs: other keyword arguments that are passed to ruby_library.
+
+ """
+ _internal_ruby_proto_library(
+ name,
+ ruby_library,
+ **kwargs
+ )
\ No newline at end of file
12 changes: 12 additions & 0 deletions modules/protobuf/25.5/patches/0006-Add-repo_name.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/MODULE.bazel b/MODULE.bazel
index 37e49a5c6..ede816afc 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -5,6 +5,7 @@ module(
name = "protobuf",
version = "25.5",
compatibility_level = 1,
+ repo_name = "com_google_protobuf",
)

# LOWER BOUND dependency versions.
39 changes: 39 additions & 0 deletions modules/protobuf/25.5/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
matrix:
platform: ["debian10", "macos", "ubuntu2004", "windows"]
bazel:
- 7.x
- 6.x

tasks:
verify_targets:
name: "Verify build targets"
platform: ${{ platform }}
bazel: ${{ bazel }}
build_flags:
- '--host_cxxopt=-std=c++14'
- '--cxxopt=-std=c++14'
build_targets:
- '@protobuf//:protobuf'
- '@protobuf//:protobuf_lite'
- '@protobuf//:protoc'
- '@protobuf//:test_messages_proto2_cc_proto'
- '@protobuf//:test_messages_proto3_cc_proto'

bcr_test_module:
module_path: "examples"
matrix:
platform: ["debian10", "macos", "ubuntu2004", "windows"]
bazel:
- 7.x
- 6.x
tasks:
run_test_module:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
build_flags:
- '--host_cxxopt=-std=c++14'
- '--cxxopt=-std=c++14'
- '--nocheck_visibility'
build_targets:
- "//..."
14 changes: 14 additions & 0 deletions modules/protobuf/25.5/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"url": "https://github.com/protocolbuffers/protobuf/releases/download/v25.5/protobuf-25.5.tar.gz",
"integrity": "sha256-PPfVsXxP8E/p8DgQTp0Mrm2gm4ziccE+RPisafUeTg8=",
"strip_prefix": "protobuf-25.5",
"patch_strip": 1,
"patches": {
"0001-Add-MODULE.bazel.patch": "sha256-v3aLq5ijyJP1ps8eA59v5YGHx4K2GuBVDvE5rXQljgA=",
"0002-Examples-MODULE.bazel.patch": "sha256-k7d24FnGJcB+cnpmsmrzKO1FfE6r8gAYp13CDCvGUiM=",
"0003-relative-labels.patch": "sha256-qafPK4p4WWgEFbzesFCghZVthul1KYq+hAz5T9sZOYQ=",
"0004-Add-utf8_range-dependency.patch": "sha256-oghruhqg3b9LiQ/A4v6w2KjJLxS0pwOJSSetyIU5pNI=",
"0005-Make-rules_ruby-a-dev-only-dependency.patch": "sha256-o3fv37+EXKESz1Kdq9en72kPzxZh4weCPR5laFOKSdw=",
"0006-Add-repo_name.patch": "sha256-BOsh6WsbuyO+Wdm+VxGbGbKarQpRFjK25ImYCkQ0ggg="
}
}
1 change: 1 addition & 0 deletions modules/protobuf/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"21.7",
"23.1",
"24.4",
"25.5",
"26.0",
"26.0.bcr.1",
"26.0.bcr.2",
Expand Down

0 comments on commit 7a06a83

Please sign in to comment.