Skip to content

Commit

Permalink
Switch rules_ruby to the supported version from bazel-contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLunn committed Dec 27, 2024
1 parent 2bf39f5 commit 5e47c00
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 115 deletions.
17 changes: 17 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_python", version = "0.28.0")
bazel_dep(name = "rules_rust", version = "0.51.0")
bazel_dep(name = "rules_ruby", version = "0.16.0")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "zlib", version = "1.3.1")
bazel_dep(name = "bazel_features", version = "1.17.0", repo_name = "proto_bazel_features")
Expand All @@ -33,6 +34,22 @@ bazel_dep(
version = "0.2.0",
)

# Ruby
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
version = "system",
)
use_repo(ruby, "ruby")

ruby.bundle_fetch(
name = "protobuf_bundle",
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
use_repo(ruby, "bundle", "ruby_toolchains")
register_toolchains("@ruby_toolchains//:all")

# Proto toolchains
register_toolchains("//bazel/private/toolchains:all")

Expand Down
43 changes: 19 additions & 24 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,31 @@ kt_register_toolchains()

http_archive(
name = "rules_ruby",
integrity = "sha256-Lh/xxR6WsKJnS92sYkpJDBtdS6DNrCbi0kuUxBffG6E=",
strip_prefix = "rules_ruby-588d9dd40487277e2560ece09fe310d7c0ecb4a6",
urls = [
"https://github.com/protocolbuffers/rules_ruby/archive/588d9dd40487277e2560ece09fe310d7c0ecb4a6.zip",
],
sha256 = "971b86974e5698abf3aa0a5dc285d378af19c7f2e1f1de33d2d08405460c370f",
strip_prefix = "rules_ruby-0.16.0",
url = "https://github.com/bazel-contrib/rules_ruby/releases/download/v0.16.0/rules_ruby-v0.16.0.tar.gz",
)

load("@rules_ruby//ruby:defs.bzl", "ruby_runtime")

ruby_runtime("system_ruby")

register_toolchains("@system_ruby//:toolchain")
load("@rules_ruby//ruby:deps.bzl", "rb_register_toolchains", "rb_bundle_fetch")

# Uncomment pairs of ruby_runtime() + register_toolchain() calls below to enable
# local JRuby testing. Do not submit the changes (due to impact on test duration
# for non JRuby builds due to downloading JRuby SDKs).
#ruby_runtime("jruby-9.2")
#
#register_toolchains("@jruby-9.2//:toolchain")
#
#ruby_runtime("jruby-9.3")
#
#register_toolchains("@jruby-9.3//:toolchain")

load("@system_ruby//:bundle.bzl", "ruby_bundle")
rb_register_toolchains(
version = "system",
)

ruby_bundle(
rb_bundle_fetch(
name = "protobuf_bundle",
srcs = ["//ruby:google-protobuf.gemspec"],
gem_checksums = {
"bigdecimal-3.1.8": "a89467ed5a44f8ae01824af49cbc575871fa078332e8f77ea425725c1ffe27be",
"bigdecimal-3.1.8-java": "b9e94c14623fff8575f17a10320852219bbba92ecff4977571503d942687326e",
"ffi-1.17.0": "51630e43425078311c056ca75f961bb3bda1641ab36e44ad4c455e0b0e4a231c",
"ffi-compiler-1.3.2": "a94f3d81d12caf5c5d4ecf13980a70d0aeaa72268f3b9cc13358bcc6509184a0",
"power_assert-2.0.5": "63b511b85bb8ea57336d25156864498644f5bbf028699ceda27949e0125bc323",
"rake-13.2.1": "46cb38dae65d7d74b6020a4ac9d48afed8eb8149c040eccf0523bec91907059d",
"rake-compiler-1.1.9": "51b5c95a1ff25cabaaf92e674a2bed847ab53d66302fc8843830df46ab1f51f5",
"test-unit-3.6.7": "c342bb9f7334ea84a361b43c20b063f405c0bf3c7dbe3ff38f61a91661d29221",
},
gemfile = "//ruby:Gemfile",
gemfile_lock = "//ruby:Gemfile.lock",
)

http_archive(
Expand Down
17 changes: 0 additions & 17 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# TODO: either replace rules_ruby with a maintained version on BCR
# or use bzlmod extensions to depend on this specific repo
http_archive(
name = "rules_ruby",
urls = [
"https://github.com/protocolbuffers/rules_ruby/archive/588d9dd40487277e2560ece09fe310d7c0ecb4a6.zip"
],
strip_prefix = "rules_ruby-588d9dd40487277e2560ece09fe310d7c0ecb4a6",
integrity = "sha256-Lh/xxR6WsKJnS92sYkpJDBtdS6DNrCbi0kuUxBffG6E=",
)

load("@rules_ruby//ruby:defs.bzl", "ruby_runtime")

ruby_runtime("system_ruby")

register_toolchains("@system_ruby//:toolchain")

# Following are just needed to run conformance tests, not really needed to support them via MODULE.bazel

# For testing runtime against old gencode from a previous major version.
Expand Down
12 changes: 4 additions & 8 deletions protobuf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,9 @@ def internal_objc_proto_library(

def internal_ruby_proto_library(
name,
ruby_library,
rb_library,
srcs = [],
deps = [],
includes = ["."],
default_runtime = "@com_google_protobuf//ruby:protobuf",
protoc = "@com_google_protobuf//:protoc",
testonly = None,
Expand All @@ -513,16 +512,15 @@ def internal_ruby_proto_library(
Args:
name: the name of the ruby_proto_library.
ruby_library: the ruby library rules to use.
rb_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.
default_runtime: the RubyProtobuf runtime
protoc: the label of the protocol compiler to generate the sources.
testonly: common rule attribute (see:
https://bazel.build/reference/be/common-definitions#common-attributes)
visibility: the visibility of the generated files.
**kwargs: other keyword arguments that are passed to ruby_library.
**kwargs: other keyword arguments that are passed to rb_library.
"""

Expand All @@ -533,7 +531,6 @@ def internal_ruby_proto_library(
srcs = srcs,
deps = [s + "_genproto" for s in deps],
langs = ["ruby"],
includes = includes,
protoc = protoc,
testonly = testonly,
visibility = visibility,
Expand All @@ -543,13 +540,12 @@ def internal_ruby_proto_library(
deps = []
if default_runtime:
deps.append(default_runtime)
ruby_library(
rb_library(
name = name,
srcs = [name + "_genproto"],
deps = deps,
testonly = testonly,
visibility = visibility,
includes = includes,
**kwargs
)

Expand Down
19 changes: 8 additions & 11 deletions ruby/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
load("@rules_ruby//ruby:defs.bzl", "rb_library")
load("//:protobuf_version.bzl", "PROTOBUF_RUBY_VERSION")
load("//conformance:defs.bzl", "conformance_test")
load("//python:internal.bzl", "internal_copy_files")
Expand Down Expand Up @@ -42,31 +42,31 @@ selects.config_setting_group(
name = "jruby_ffi",
match_all = [
":ffi_enabled",
"@rules_ruby//ruby/runtime:config_jruby",
"@ruby//engine:jruby",
],
)

selects.config_setting_group(
name = "jruby_native",
match_all = [
":ffi_disabled",
"@rules_ruby//ruby/runtime:config_jruby",
"@ruby//engine:jruby",
],
)

selects.config_setting_group(
name = "ruby_ffi",
match_all = [
":ffi_enabled",
"@rules_ruby//ruby/runtime:config_ruby",
"@ruby//engine:jruby",
],
)

selects.config_setting_group(
name = "ruby_native",
match_all = [
":ffi_disabled",
"@rules_ruby//ruby/runtime:config_ruby",
"@ruby//engine:jruby",
],
)

Expand Down Expand Up @@ -100,7 +100,6 @@ internal_ruby_proto_library(
name = "well_known_ruby_protos",
srcs = [":copied_wkt_proto_files"],
default_runtime = "",
includes = ["."],
visibility = [
"//conformance:__pkg__",
"//ruby:__subpackages__",
Expand All @@ -121,7 +120,6 @@ internal_ruby_proto_library(
name = "conformance_test_ruby_proto",
testonly = 1,
srcs = [":copied_conformance_test_files"],
includes = ["."],
visibility = [
"//conformance:__pkg__",
"//ruby:__subpackages__",
Expand All @@ -143,12 +141,11 @@ internal_ruby_proto_library(
name = "conformance_editions_test_ruby_proto",
testonly = 1,
srcs = [":copied_conformance_editions_test_files"],
includes = ["."],
visibility = ["//conformance:__pkg__"],
deps = [":well_known_ruby_protos"],
)

ruby_library(
rb_library(
name = "protobuf",
visibility = [
"//visibility:public",
Expand Down Expand Up @@ -193,7 +190,7 @@ genrule(
""",
tags = ["manual"],
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_jruby": [],
"@ruby//engine:jruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
Expand Down Expand Up @@ -238,7 +235,7 @@ genrule(
filegroup(
name = "release",
srcs = select({
"@rules_ruby//ruby/runtime:config_jruby": [":jruby_release"],
"@ruby//engine:jruby": [":jruby_release"],
"//conditions:default": [":ruby_release"],
}),
tags = ["manual"],
Expand Down
6 changes: 3 additions & 3 deletions ruby/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Wrapper around internal_ruby_proto_library to supply our rules_ruby"""

load("@rules_ruby//ruby:defs.bzl", "ruby_library")
load("@rules_ruby//ruby:defs.bzl", "rb_library")
load("//:protobuf.bzl", _internal_ruby_proto_library = "internal_ruby_proto_library")

def internal_ruby_proto_library(
Expand All @@ -14,11 +14,11 @@ def internal_ruby_proto_library(
Args:
name: the name of the ruby_proto_library.
**kwargs: other keyword arguments that are passed to ruby_library.
**kwargs: other keyword arguments that are passed to rb_library.
"""
_internal_ruby_proto_library(
name,
ruby_library,
rb_library,
**kwargs
)
2 changes: 1 addition & 1 deletion ruby/ext/google/protobuf_c/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ cc_library(
],
linkstatic = True,
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_jruby": ["@platforms//:incompatible"],
"@ruby//engine:jruby": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
Expand Down
20 changes: 5 additions & 15 deletions ruby/lib/google/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
load("@rules_ruby//ruby:defs.bzl", "rb_library")

config_setting(
name = "requires_bundle",
Expand Down Expand Up @@ -60,14 +60,14 @@ genrule(
visibility = ["//ruby:__subpackages__"],
)

ruby_library(
rb_library(
name = "protobuf_lib",
srcs = glob([
"**/*.rb",
]),
data = select({
# Platform native implementations
"@rules_ruby//ruby/runtime:config_jruby": ["protobuf_java.jar"],
"@ruby//engine:jruby": ["protobuf_java.jar"],
"@platforms//os:osx": ["protobuf_c.bundle"],
"//conditions:default": ["protobuf_c.so"],
}) + select({
Expand All @@ -76,21 +76,11 @@ ruby_library(
"//ruby:linux_ffi_enabled": ["libprotobuf_c_ffi.so"],
"//conditions:default": [],
}),
includes = [
"ruby",
"ruby/lib",
],
visibility = ["//ruby:__pkg__"],
deps = [
"//ruby:well_known_ruby_protos",
"@protobuf_bundle//:bigdecimal",
] + select({
"//ruby:ffi_enabled": [
"@protobuf_bundle//:ffi",
"@protobuf_bundle//:ffi-compiler",
],
"//conditions:default": [],
}),
"@protobuf_bundle",
],
)

pkg_files(
Expand Down
2 changes: 1 addition & 1 deletion ruby/src/main/java/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ java_library(
"google/ProtobufJavaService.java",
],
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_jruby": [],
"@ruby//engine:jruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
visibility = ["//ruby:__subpackages__"],
Expand Down
Loading

0 comments on commit 5e47c00

Please sign in to comment.