Skip to content

Commit 1f42de1

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Bazelify ruby runtime (#10525)
This uses https://github.com/protocolbuffers/rules_ruby to fully Bazelify our ruby runtime code. The Rakefile is left in place for now and is still used by our aarch64 tests. With the current implementation ruby behaves similarly to our python wrapper, which selects whatever version is installed in the system. Future enhancements will allow for more hermetic builds via Bazel flags to pin a specific version Closes #10525 COPYBARA_INTEGRATE_REVIEW=#10525 from mkruskal-google:rules_ruby 97fa1f7 FUTURE_COPYBARA_INTEGRATE_REVIEW=#10525 from mkruskal-google:rules_ruby 97fa1f7 PiperOrigin-RevId: 498031251
1 parent 4950dce commit 1f42de1

File tree

33 files changed

+601
-369
lines changed

33 files changed

+601
-369
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ ruby/tests/generated_code_proto2_pb.rb
174174
ruby/tests/multi_level_nesting_test_pb.rb
175175
ruby/tests/test_import_proto2_pb.rb
176176
ruby/tests/test_ruby_package_proto2_pb.rb
177-
ruby/Gemfile.lock
178177
ruby/compatibility_tests/v3.0.0/protoc
179178
ruby/compatibility_tests/v3.0.0/tests/generated_code_pb.rb
180179
ruby/compatibility_tests/v3.0.0/tests/test_import_pb.rb
180+
ruby/Gemfile.lock
181181

182182
# IntelliJ CLion Config files and build output
183183
cmake/.idea

BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ internal_ruby_proto_library(
148148
name = "well_known_ruby_protos",
149149
srcs = [":well_known_protos"],
150150
includes = ["src"],
151+
default_runtime = "",
151152
visibility = [
152153
"//conformance:__pkg__",
153154
"//ruby:__subpackages__",
@@ -519,7 +520,7 @@ internal_ruby_proto_library(
519520
# The above must come first.
520521
"src",
521522
],
522-
proto_deps = [":well_known_protos"],
523+
deps = [":well_known_ruby_protos"],
523524
visibility = [
524525
"//conformance:__pkg__",
525526
"//ruby:__subpackages__",

WORKSPACE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,27 @@ bazel_skylib_workspace()
6060
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
6161
rules_pkg_dependencies()
6262

63+
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
64+
apple_rules_dependencies()
65+
6366
# For `kt_jvm_library`
6467
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")
6568
kotlin_repositories()
6669

6770
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")
6871
kt_register_toolchains()
6972

73+
load("@rules_ruby//ruby:defs.bzl", "ruby_runtime")
74+
ruby_runtime("system_ruby")
75+
register_toolchains("@system_ruby//:toolchain")
76+
77+
load("@system_ruby//:bundle.bzl", "ruby_bundle")
78+
ruby_bundle(
79+
name = "protobuf_bundle",
80+
srcs = ["//ruby:google-protobuf.gemspec"],
81+
gemfile = "//ruby:Gemfile",
82+
)
83+
7084
load("@upb//bazel:workspace_deps.bzl", "upb_deps")
7185
upb_deps()
7286

conformance/BUILD.bazel

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Conformance testing for Protobuf.
22

33
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "objc_library")
4+
load("@rules_ruby//ruby:defs.bzl", "ruby_binary")
45
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
56
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
67
load(
@@ -317,19 +318,16 @@ cc_binary(
317318
deps = [":conformance_objc_lib"],
318319
)
319320

320-
inline_sh_binary(
321+
ruby_binary(
321322
name = "conformance_ruby",
322-
testonly = 1,
323+
testonly = True,
323324
srcs = ["conformance_ruby.rb"],
324-
cmd = "RUBYLIB=ruby/lib:conformance:src $(rootpath conformance_ruby.rb)",
325-
visibility = ["//ruby:__subpackages__"],
326325
deps = [
327326
":conformance_ruby_proto",
328327
"//:test_messages_proto2_ruby_proto",
329-
"//:test_messages_proto3_ruby_proto",
330-
"//:well_known_ruby_protos",
331-
"//ruby:protobuf",
328+
"//:test_messages_proto3_ruby_proto",
332329
],
330+
visibility = ["//ruby:__subpackages__"],
333331
)
334332

335333
################################################################################

conformance/conformance_ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3131
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232

33-
require 'conformance_pb'
33+
require 'conformance/conformance_pb'
3434
require 'google/protobuf/test_messages_proto3_pb'
3535
require 'google/protobuf/test_messages_proto2_pb'
3636

kokoro/linux/jruby92/common.cfg

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ timeout_mins: 120
66

77
env_vars {
88
key: "CONTAINER_IMAGE"
9-
value: "gcr.io/protobuf-build/ruby/linux:jruby-9.2.20.1-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
9+
value: "gcr.io/protobuf-build/ruby/linux:jruby-9.2.20.1-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
1010
}
1111

1212
env_vars {
1313
key: "BAZEL_TARGETS"
1414
value: "//ruby/..."
1515
}
1616

17-
env_vars {
18-
key: "BAZEL_EXTRA_FLAGS"
19-
value: "--define=ruby_platform=java"
20-
}
21-
2217
action {
2318
define_artifacts {
2419
regex: "**/sponge_log.*"

kokoro/linux/jruby93/common.cfg

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ timeout_mins: 120
66

77
env_vars {
88
key: "CONTAINER_IMAGE"
9-
value: "gcr.io/protobuf-build/ruby/linux:jruby-9.3.4.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
9+
value: "gcr.io/protobuf-build/ruby/linux:jruby-9.3.4.0-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
1010
}
1111

1212
env_vars {
1313
key: "BAZEL_TARGETS"
1414
value: "//ruby/..."
1515
}
1616

17-
env_vars {
18-
key: "BAZEL_EXTRA_FLAGS"
19-
value: "--define=ruby_platform=java"
20-
}
21-
2217
action {
2318
define_artifacts {
2419
regex: "**/sponge_log.*"

kokoro/linux/ruby26/common.cfg

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ timeout_mins: 120
66

77
env_vars {
88
key: "CONTAINER_IMAGE"
9-
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.6.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
9+
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.6.0-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
1010
}
1111

1212
env_vars {
1313
key: "BAZEL_TARGETS"
1414
value: "//ruby/..."
1515
}
1616

17-
env_vars {
18-
key: "BAZEL_EXTRA_FLAGS"
19-
value: "--define=ruby_platform=c"
20-
}
21-
2217
action {
2318
define_artifacts {
2419
regex: "**/sponge_log.*"

kokoro/linux/ruby27/common.cfg

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ timeout_mins: 120
66

77
env_vars {
88
key: "CONTAINER_IMAGE"
9-
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.7.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
9+
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.7.0-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
1010
}
1111

1212
env_vars {
1313
key: "BAZEL_TARGETS"
1414
value: "//ruby/..."
1515
}
1616

17-
env_vars {
18-
key: "BAZEL_EXTRA_FLAGS"
19-
value: "--define=ruby_platform=c"
20-
}
21-
2217
action {
2318
define_artifacts {
2419
regex: "**/sponge_log.*"

kokoro/linux/ruby30/common.cfg

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ timeout_mins: 120
66

77
env_vars {
88
key: "CONTAINER_IMAGE"
9-
value: "gcr.io/protobuf-build/ruby/linux:ruby-3.0.2-2f706fd1ab49f4e97af769388be486069b63efee"
9+
value: "gcr.io/protobuf-build/ruby/linux:ruby-3.0.2-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
1010
}
1111

1212
env_vars {
1313
key: "BAZEL_TARGETS"
1414
value: "//ruby/..."
1515
}
1616

17-
env_vars {
18-
key: "BAZEL_EXTRA_FLAGS"
19-
value: "--define=ruby_platform=c"
20-
}
21-
2217
action {
2318
define_artifacts {
2419
regex: "**/sponge_log.*"

0 commit comments

Comments
 (0)