Skip to content

Commit 571b727

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Make rules_ruby a dev-only dependency.
There is no canonical rules_ruby repo today, and we don't want our fork to become one. In order to unblock inclusion of Protobuf in the bzlmod registry, we're making this a dev dependency and dropping support for Bazel/Ruby. Fixes #14569 PiperOrigin-RevId: 584393841
1 parent c802609 commit 571b727

11 files changed

Lines changed: 97 additions & 60 deletions

File tree

BUILD.bazel

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_librar
55
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
66
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
77
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
8-
load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
8+
load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library")
99

1010
licenses(["notice"])
1111

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

153-
internal_ruby_proto_library(
154-
name = "well_known_ruby_protos",
155-
srcs = [":well_known_protos"],
156-
default_runtime = "",
157-
includes = ["src"],
158-
visibility = [
159-
"//conformance:__pkg__",
160-
"//ruby:__subpackages__",
161-
],
162-
)
163-
164153
################################################################################
165154
# Protocol Buffers Compiler
166155
################################################################################
@@ -524,33 +513,6 @@ internal_php_proto_library(
524513
],
525514
)
526515

527-
internal_ruby_proto_library(
528-
name = "test_messages_proto2_ruby_proto",
529-
testonly = 1,
530-
srcs = ["//src/google/protobuf:test_messages_proto2.proto"],
531-
includes = ["src/google/protobuf"],
532-
visibility = [
533-
"//conformance:__pkg__",
534-
"//ruby:__subpackages__",
535-
],
536-
)
537-
538-
internal_ruby_proto_library(
539-
name = "test_messages_proto3_ruby_proto",
540-
testonly = 1,
541-
srcs = ["//src/google/protobuf:test_messages_proto3.proto"],
542-
includes = [
543-
"src/google/protobuf",
544-
# The above must come first.
545-
"src",
546-
],
547-
visibility = [
548-
"//conformance:__pkg__",
549-
"//ruby:__subpackages__",
550-
],
551-
deps = [":well_known_ruby_protos"],
552-
)
553-
554516
filegroup(
555517
name = "bzl_srcs",
556518
srcs = glob(["**/*.bzl"]),

WORKSPACE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")
9191

9292
kt_register_toolchains()
9393

94+
http_archive(
95+
name = "rules_ruby",
96+
urls = [
97+
"https://github.com/protocolbuffers/rules_ruby/archive/b7f3e9756f3c45527be27bc38840d5a1ba690436.zip"
98+
],
99+
strip_prefix = "rules_ruby-b7f3e9756f3c45527be27bc38840d5a1ba690436",
100+
sha256 = "347927fd8de6132099fcdc58e8f7eab7bde4eb2fd424546b9cd4f1c6f8f8bad8",
101+
)
102+
94103
load("@rules_ruby//ruby:defs.bzl", "ruby_runtime")
95104

96105
ruby_runtime("system_ruby")

conformance/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "objc_library")
44
load("@rules_ruby//ruby:defs.bzl", "ruby_binary")
5-
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
5+
load("//ruby:defs.bzl", "internal_ruby_proto_library")
6+
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library")
67
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
78
load(
89
"@rules_pkg//:mappings.bzl",
@@ -347,8 +348,7 @@ ruby_binary(
347348
visibility = ["//ruby:__subpackages__"],
348349
deps = [
349350
":conformance_ruby_proto",
350-
"//:test_messages_proto2_ruby_proto",
351-
"//:test_messages_proto3_ruby_proto",
351+
"//ruby:conformance_test_ruby_proto",
352352
],
353353
)
354354

protobuf.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ load("@bazel_skylib//lib:versions.bzl", "versions")
22
load("@rules_cc//cc:defs.bzl", "objc_library")
33
load("@rules_proto//proto:defs.bzl", "ProtoInfo")
44
load("@rules_python//python:defs.bzl", "py_library")
5-
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
65

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

491490
def internal_ruby_proto_library(
492491
name,
492+
ruby_library,
493493
srcs = [],
494494
deps = [],
495495
includes = ["."],
@@ -506,6 +506,7 @@ def internal_ruby_proto_library(
506506
507507
Args:
508508
name: the name of the ruby_proto_library.
509+
ruby_library: the ruby library rules to use.
509510
srcs: the .proto files to compile.
510511
deps: a list of dependency labels; must be a internal_ruby_proto_library.
511512
includes: a string indicating the include path of the .proto files.

protobuf_deps.bzl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,6 @@ def protobuf_deps():
101101
url = "https://github.com/bazelbuild/rules_python/releases/download/0.26.0/rules_python-0.26.0.tar.gz",
102102
)
103103

104-
if not native.existing_rule("rules_ruby"):
105-
_github_archive(
106-
name = "rules_ruby",
107-
repo = "https://github.com/protocolbuffers/rules_ruby",
108-
commit = "b7f3e9756f3c45527be27bc38840d5a1ba690436",
109-
sha256 = "347927fd8de6132099fcdc58e8f7eab7bde4eb2fd424546b9cd4f1c6f8f8bad8",
110-
)
111-
112104
if not native.existing_rule("rules_jvm_external"):
113105
_github_archive(
114106
name = "rules_jvm_external",

ruby/BUILD.bazel

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ load("@bazel_skylib//lib:selects.bzl", "selects")
66
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
77
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
88
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
9-
load("//:protobuf.bzl", "internal_ruby_proto_library")
9+
load("//python:internal.bzl", "internal_copy_files")
10+
load("//ruby:defs.bzl", "internal_ruby_proto_library")
1011
load("//:protobuf_version.bzl", "PROTOBUF_RUBY_VERSION")
1112
load("//conformance:defs.bzl", "conformance_test")
1213

@@ -85,6 +86,49 @@ selects.config_setting_group(
8586
],
8687
)
8788

89+
internal_copy_files(
90+
name = "copied_wkt_proto_files",
91+
srcs = [
92+
"//:well_known_type_protos",
93+
"//src/google/protobuf:descriptor_proto_srcs",
94+
"//src/google/protobuf/compiler:plugin.proto",
95+
],
96+
strip_prefix = "src",
97+
)
98+
99+
internal_ruby_proto_library(
100+
name = "well_known_ruby_protos",
101+
srcs = [":copied_wkt_proto_files"],
102+
default_runtime = "",
103+
includes = ["."],
104+
visibility = [
105+
"//conformance:__pkg__",
106+
"//ruby:__subpackages__",
107+
],
108+
)
109+
110+
internal_copy_files(
111+
name = "copied_conformance_test_files",
112+
testonly = 1,
113+
srcs = [
114+
"//src/google/protobuf:test_messages_proto2.proto",
115+
"//src/google/protobuf:test_messages_proto3.proto",
116+
],
117+
strip_prefix = "src",
118+
)
119+
120+
internal_ruby_proto_library(
121+
name = "conformance_test_ruby_proto",
122+
testonly = 1,
123+
srcs = [":copied_conformance_test_files"],
124+
includes = ["."],
125+
visibility = [
126+
"//conformance:__pkg__",
127+
"//ruby:__subpackages__",
128+
],
129+
deps = [":well_known_ruby_protos"],
130+
)
131+
88132
ruby_library(
89133
name = "protobuf",
90134
visibility = [
@@ -104,7 +148,7 @@ genrule(
104148
"//ruby/lib/google:copy_jar",
105149
"//ruby/lib/google:dist_files",
106150
"//ruby/ext/google/protobuf_c:dist_files",
107-
"//:well_known_ruby_protos",
151+
":well_known_ruby_protos",
108152
"google-protobuf.gemspec",
109153
],
110154
outs = ["google-protobuf-" + PROTOBUF_RUBY_VERSION + "-java.gem"],
@@ -118,7 +162,7 @@ genrule(
118162
for utf in $(execpaths //third_party/utf8_range:utf8_range_srcs) $(execpath //third_party/utf8_range:LICENSE); do
119163
mv "tmp/$$utf" "tmp/ruby/ext/google/protobuf_c/third_party/utf8_range"
120164
done
121-
for wkt in $(execpaths //:well_known_ruby_protos); do
165+
for wkt in $(execpaths :well_known_ruby_protos); do
122166
mv "tmp/$$wkt" "tmp/ruby/lib/google/protobuf/"
123167
done
124168
mv "tmp/$(execpath //ruby/lib/google:copy_jar)" "tmp/ruby/lib/google"
@@ -140,9 +184,9 @@ genrule(
140184
srcs = [
141185
"//third_party/utf8_range:utf8_range_srcs",
142186
"//third_party/utf8_range:LICENSE",
143-
"//:well_known_ruby_protos",
144187
"//ruby/ext/google/protobuf_c:dist_files",
145188
"//ruby/lib/google:dist_files",
189+
":well_known_ruby_protos",
146190
"google-protobuf.gemspec",
147191
],
148192
outs = ["google-protobuf-" + PROTOBUF_RUBY_VERSION + ".gem"],
@@ -156,7 +200,7 @@ genrule(
156200
for utf in $(execpaths //third_party/utf8_range:utf8_range_srcs) $(execpath //third_party/utf8_range:LICENSE); do
157201
mv "tmp/$$utf" "tmp/ruby/ext/google/protobuf_c/third_party/utf8_range"
158202
done
159-
for wkt in $(execpaths //:well_known_ruby_protos); do
203+
for wkt in $(execpaths :well_known_ruby_protos); do
160204
mv "tmp/$$wkt" "tmp/ruby/lib/google/protobuf/"
161205
done
162206
cd tmp/ruby
@@ -197,7 +241,7 @@ internal_ruby_proto_library(
197241
visibility = [
198242
"//ruby:__subpackages__",
199243
],
200-
deps = ["//:well_known_ruby_protos"],
244+
deps = [":well_known_ruby_protos"],
201245
)
202246

203247
conformance_test(

ruby/compatibility_tests/v3.0.0/tests/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
22
load("@rules_ruby//ruby:defs.bzl", "ruby_test")
3-
load("//:protobuf.bzl", "internal_ruby_proto_library")
3+
load("//ruby:defs.bzl", "internal_ruby_proto_library")
44

55
internal_ruby_proto_library(
66
name = "test_ruby_protos",

ruby/defs.bzl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Wrapper around internal_ruby_proto_library to supply our rules_ruby"""
2+
3+
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
4+
load("//:protobuf.bzl", _internal_ruby_proto_library = "internal_ruby_proto_library")
5+
6+
def internal_ruby_proto_library(
7+
name,
8+
**kwargs):
9+
"""Bazel rule to create a Ruby protobuf library from proto source files
10+
11+
NOTE: the rule is only an internal workaround to generate protos. The
12+
interface may change and the rule may be removed when bazel has introduced
13+
the native rule.
14+
15+
Args:
16+
name: the name of the ruby_proto_library.
17+
**kwargs: other keyword arguments that are passed to ruby_library.
18+
19+
"""
20+
_internal_ruby_proto_library(
21+
name,
22+
ruby_library,
23+
**kwargs
24+
)

ruby/lib/google/BUILD.bazel

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ ruby_library(
7676
"//ruby:linux_ffi_enabled": ["libprotobuf_c_ffi.so"],
7777
"//conditions:default": [],
7878
}),
79-
includes = ["ruby/lib"],
79+
includes = [
80+
"ruby",
81+
"ruby/lib",
82+
],
8083
visibility = ["//ruby:__pkg__"],
81-
deps = ["//:well_known_ruby_protos"] + select({
84+
deps = ["//ruby:well_known_ruby_protos"] + select({
8285
"//ruby:ffi_enabled": [
8386
"@protobuf_bundle//:ffi",
8487
"@protobuf_bundle//:ffi-compiler",

src/google/protobuf/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ exports_files(
798798
visibility = [
799799
"//:__pkg__",
800800
"//python:__pkg__",
801+
"//ruby:__pkg__",
801802
],
802803
)
803804

0 commit comments

Comments
 (0)