Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch rules_ruby to the supported version from bazel-contrib #19808

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ ruby/tests/utf8_pb.rb
ruby/compatibility_tests/v3.0.0/protoc
ruby/compatibility_tests/v3.0.0/tests/generated_code_pb.rb
ruby/compatibility_tests/v3.0.0/tests/test_import_pb.rb
ruby/Gemfile.lock

# IntelliJ CLion Config files and build output
cmake/.idea
Expand Down
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
45 changes: 22 additions & 23 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,35 @@ 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")
rb_register_toolchains(
version = "system",
)

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

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
21 changes: 9 additions & 12 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 @@ -230,15 +227,15 @@ genrule(
""",
tags = ["manual"],
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_ruby": [],
"@ruby//engine:jruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)

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
47 changes: 47 additions & 0 deletions ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
PATH
remote: .
specs:
google-protobuf (4.30.0-java)
ffi (~> 1)
ffi-compiler (~> 1)
rake (>= 13)

GEM
remote: https://rubygems.org/
specs:
bigdecimal (3.1.8)
bigdecimal (3.1.8-java)
ffi (1.17.0)
ffi-compiler (1.3.2)
ffi (>= 1.15.5)
rake
power_assert (2.0.5)
rake (13.2.1)
rake-compiler (1.1.9)
rake
test-unit (3.6.7)
power_assert

PLATFORMS
aarch64-linux
arm-linux
arm64-darwin
arm64-linux
java
x64-mingw-ucrt
x64-mingw32
x86-linux
x86-mingw32
x86_64-darwin
x86_64-linux

DEPENDENCIES
bigdecimal
ffi (~> 1)
ffi-compiler (~> 1)
google-protobuf!
rake-compiler (~> 1.1.0)
test-unit (~> 3.0, >= 3.0.9)

BUNDLED WITH
2.4.10
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
)
3 changes: 1 addition & 2 deletions ruby/ext/google/protobuf_c/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ cc_library(
],
linkstatic = True,
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_jruby": ["@platforms//:incompatible"],
"@ruby//engine:jruby": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
"//third_party/utf8_range",
"@rules_ruby//ruby/runtime:headers",
],
alwayslink = True,
)
Expand Down
Loading
Loading