Skip to content

Commit 2dac90d

Browse files
Make rules_ruby a dev-only dependency. (#20575)
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 Co-authored-by: Mike Kruskal <[email protected]>
1 parent 5a56dd4 commit 2dac90d

File tree

11 files changed

+98
-61
lines changed

11 files changed

+98
-61
lines changed

BUILD.bazel

+1-39
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
################################################################################
@@ -525,33 +514,6 @@ internal_php_proto_library(
525514
],
526515
)
527516

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

WORKSPACE

+9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")
8282

8383
kt_register_toolchains()
8484

85+
http_archive(
86+
name = "rules_ruby",
87+
urls = [
88+
"https://github.com/protocolbuffers/rules_ruby/archive/b7f3e9756f3c45527be27bc38840d5a1ba690436.zip"
89+
],
90+
strip_prefix = "rules_ruby-b7f3e9756f3c45527be27bc38840d5a1ba690436",
91+
sha256 = "347927fd8de6132099fcdc58e8f7eab7bde4eb2fd424546b9cd4f1c6f8f8bad8",
92+
)
93+
8594
load("@rules_ruby//ruby:defs.bzl", "ruby_runtime")
8695

8796
ruby_runtime("system_ruby")

conformance/BUILD.bazel

+3-3
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",
@@ -331,8 +332,7 @@ ruby_binary(
331332
visibility = ["//ruby:__subpackages__"],
332333
deps = [
333334
":conformance_ruby_proto",
334-
"//:test_messages_proto2_ruby_proto",
335-
"//:test_messages_proto3_ruby_proto",
335+
"//ruby:conformance_test_ruby_proto",
336336
],
337337
)
338338

protobuf.bzl

+2-1
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

-8
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ def protobuf_deps():
109109
sha256 = "f9e4f6acf82449324d56669bda4bdb28b48688ad2990d8b39fa5b93ed39c9ad1",
110110
)
111111

112-
if not native.existing_rule("rules_ruby"):
113-
_github_archive(
114-
name = "rules_ruby",
115-
repo = "https://github.com/protocolbuffers/rules_ruby",
116-
commit = "b7f3e9756f3c45527be27bc38840d5a1ba690436",
117-
sha256 = "347927fd8de6132099fcdc58e8f7eab7bde4eb2fd424546b9cd4f1c6f8f8bad8",
118-
)
119-
120112
if not native.existing_rule("rules_jvm_external"):
121113
_github_archive(
122114
name = "rules_jvm_external",

ruby/BUILD.bazel

+51-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ 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")
99
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
10-
load("//:protobuf.bzl", "internal_ruby_proto_library")
11-
load("//conformance:defs.bzl", "conformance_test")
10+
load("//python:internal.bzl", "internal_copy_files")
11+
load("//ruby:defs.bzl", "internal_ruby_proto_library")
1212
load("//:protobuf_version.bzl", "PROTOBUF_RUBY_VERSION")
13+
load("//conformance:defs.bzl", "conformance_test")
1314

1415
################################################################################
1516
# Ruby Runtime
@@ -86,6 +87,49 @@ selects.config_setting_group(
8687
],
8788
)
8889

90+
internal_copy_files(
91+
name = "copied_wkt_proto_files",
92+
srcs = [
93+
"//:well_known_type_protos",
94+
"//src/google/protobuf:descriptor_proto_srcs",
95+
"//src/google/protobuf/compiler:plugin.proto",
96+
],
97+
strip_prefix = "src",
98+
)
99+
100+
internal_ruby_proto_library(
101+
name = "well_known_ruby_protos",
102+
srcs = [":copied_wkt_proto_files"],
103+
default_runtime = "",
104+
includes = ["."],
105+
visibility = [
106+
"//conformance:__pkg__",
107+
"//ruby:__subpackages__",
108+
],
109+
)
110+
111+
internal_copy_files(
112+
name = "copied_conformance_test_files",
113+
testonly = 1,
114+
srcs = [
115+
"//src/google/protobuf:test_messages_proto2.proto",
116+
"//src/google/protobuf:test_messages_proto3.proto",
117+
],
118+
strip_prefix = "src",
119+
)
120+
121+
internal_ruby_proto_library(
122+
name = "conformance_test_ruby_proto",
123+
testonly = 1,
124+
srcs = [":copied_conformance_test_files"],
125+
includes = ["."],
126+
visibility = [
127+
"//conformance:__pkg__",
128+
"//ruby:__subpackages__",
129+
],
130+
deps = [":well_known_ruby_protos"],
131+
)
132+
89133
ruby_library(
90134
name = "protobuf",
91135
visibility = [
@@ -105,7 +149,7 @@ genrule(
105149
"//ruby/lib/google:copy_jar",
106150
"//ruby/lib/google:dist_files",
107151
"//ruby/ext/google/protobuf_c:dist_files",
108-
"//:well_known_ruby_protos",
152+
":well_known_ruby_protos",
109153
"google-protobuf.gemspec",
110154
],
111155
outs = ["google-protobuf-" + PROTOBUF_RUBY_VERSION + "-java.gem"],
@@ -119,7 +163,7 @@ genrule(
119163
for utf in $(execpaths @utf8_range//:utf8_range_srcs) $(execpath @utf8_range//:LICENSE); do
120164
mv "tmp/$$utf" "tmp/ruby/ext/google/protobuf_c/third_party/utf8_range"
121165
done
122-
for wkt in $(execpaths //:well_known_ruby_protos); do
166+
for wkt in $(execpaths :well_known_ruby_protos); do
123167
mv "tmp/$$wkt" "tmp/ruby/lib/google/protobuf/"
124168
done
125169
mv "tmp/$(execpath //ruby/lib/google:copy_jar)" "tmp/ruby/lib/google"
@@ -141,9 +185,9 @@ genrule(
141185
srcs = [
142186
"@utf8_range//:utf8_range_srcs",
143187
"@utf8_range//:LICENSE",
144-
"//:well_known_ruby_protos",
145188
"//ruby/ext/google/protobuf_c:dist_files",
146189
"//ruby/lib/google:dist_files",
190+
":well_known_ruby_protos",
147191
"google-protobuf.gemspec",
148192
],
149193
outs = ["google-protobuf-" + PROTOBUF_RUBY_VERSION + ".gem"],
@@ -157,7 +201,7 @@ genrule(
157201
for utf in $(execpaths @utf8_range//:utf8_range_srcs) $(execpath @utf8_range//:LICENSE); do
158202
mv "tmp/$$utf" "tmp/ruby/ext/google/protobuf_c/third_party/utf8_range"
159203
done
160-
for wkt in $(execpaths //:well_known_ruby_protos); do
204+
for wkt in $(execpaths :well_known_ruby_protos); do
161205
mv "tmp/$$wkt" "tmp/ruby/lib/google/protobuf/"
162206
done
163207
cd tmp/ruby
@@ -198,7 +242,7 @@ internal_ruby_proto_library(
198242
visibility = [
199243
"//ruby:__subpackages__",
200244
],
201-
deps = ["//:well_known_ruby_protos"],
245+
deps = [":well_known_ruby_protos"],
202246
)
203247

204248
conformance_test(

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

+1-1
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

+24
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

+5-2
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

+1
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ exports_files(
780780
visibility = [
781781
"//:__pkg__",
782782
"//python:__pkg__",
783+
"//ruby:__pkg__",
783784
],
784785
)
785786

src/google/protobuf/compiler/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ exports_files(
226226
visibility = [
227227
"//:__pkg__",
228228
"//python:__pkg__",
229+
"//ruby:__pkg__",
229230
],
230231
)
231232

0 commit comments

Comments
 (0)