From b33606486c7989df65eddd23e738bb279f6c8d96 Mon Sep 17 00:00:00 2001 From: Jason Lunn Date: Fri, 27 Dec 2024 13:24:47 -0500 Subject: [PATCH 1/4] Add a multi-platform Gemfile.lock #test-continuous --- .gitignore | 1 - ruby/Gemfile.lock | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 ruby/Gemfile.lock diff --git a/.gitignore b/.gitignore index 7cbe5ec2a596e..a54510bef76f7 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock new file mode 100644 index 0000000000000..9947517d3bb9b --- /dev/null +++ b/ruby/Gemfile.lock @@ -0,0 +1,50 @@ +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-aarch64-linux-gnu) + ffi (1.17.0-arm-linux-gnu) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-java) + ffi (1.17.0-x86-linux-gnu) + ffi (1.17.0-x86_64-darwin) + ffi (1.17.0-x86_64-linux-gnu) + 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 + x86-linux + 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 From 2bf39f57130504324a3f1426a3616022c9692c98 Mon Sep 17 00:00:00 2001 From: Jason Lunn Date: Fri, 27 Dec 2024 14:00:47 -0500 Subject: [PATCH 2/4] Add release platforms --- ruby/Gemfile.lock | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock index 9947517d3bb9b..0665182f33f04 100644 --- a/ruby/Gemfile.lock +++ b/ruby/Gemfile.lock @@ -11,13 +11,7 @@ GEM specs: bigdecimal (3.1.8) bigdecimal (3.1.8-java) - ffi (1.17.0-aarch64-linux-gnu) - ffi (1.17.0-arm-linux-gnu) - ffi (1.17.0-arm64-darwin) - ffi (1.17.0-java) - ffi (1.17.0-x86-linux-gnu) - ffi (1.17.0-x86_64-darwin) - ffi (1.17.0-x86_64-linux-gnu) + ffi (1.17.0) ffi-compiler (1.3.2) ffi (>= 1.15.5) rake @@ -34,7 +28,10 @@ PLATFORMS arm64-darwin arm64-linux java + x64-mingw-ucrt + x64-mingw32 x86-linux + x86-mingw32 x86_64-darwin x86_64-linux From 5e47c00597e783d8ae0bb0d221812015ab250c65 Mon Sep 17 00:00:00 2001 From: Jason Lunn Date: Fri, 27 Dec 2024 15:29:58 -0500 Subject: [PATCH 3/4] Switch `rules_ruby` to the supported version from `bazel-contrib` --- MODULE.bazel | 17 +++++++ WORKSPACE | 43 ++++++++--------- WORKSPACE.bzlmod | 17 ------- protobuf.bzl | 12 ++--- ruby/BUILD.bazel | 19 ++++---- ruby/defs.bzl | 6 +-- ruby/ext/google/protobuf_c/BUILD.bazel | 2 +- ruby/lib/google/BUILD.bazel | 20 ++------ ruby/src/main/java/BUILD.bazel | 2 +- ruby/tests/BUILD.bazel | 65 ++++++++++++-------------- 10 files changed, 88 insertions(+), 115 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 74a215ac5f564..3576dcb76e640 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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") @@ -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") diff --git a/WORKSPACE b/WORKSPACE index c49abcf5329fc..6b6b0c2c067ea 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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( diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod index a3dd8925a198e..e91b392bb63bd 100644 --- a/WORKSPACE.bzlmod +++ b/WORKSPACE.bzlmod @@ -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. diff --git a/protobuf.bzl b/protobuf.bzl index 283c858507e47..63d581bc8719d 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -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, @@ -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. """ @@ -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, @@ -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 ) diff --git a/ruby/BUILD.bazel b/ruby/BUILD.bazel index 4a62a3e60e78b..db206daeda8a8 100755 --- a/ruby/BUILD.bazel +++ b/ruby/BUILD.bazel @@ -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") @@ -42,7 +42,7 @@ selects.config_setting_group( name = "jruby_ffi", match_all = [ ":ffi_enabled", - "@rules_ruby//ruby/runtime:config_jruby", + "@ruby//engine:jruby", ], ) @@ -50,7 +50,7 @@ selects.config_setting_group( name = "jruby_native", match_all = [ ":ffi_disabled", - "@rules_ruby//ruby/runtime:config_jruby", + "@ruby//engine:jruby", ], ) @@ -58,7 +58,7 @@ selects.config_setting_group( name = "ruby_ffi", match_all = [ ":ffi_enabled", - "@rules_ruby//ruby/runtime:config_ruby", + "@ruby//engine:jruby", ], ) @@ -66,7 +66,7 @@ selects.config_setting_group( name = "ruby_native", match_all = [ ":ffi_disabled", - "@rules_ruby//ruby/runtime:config_ruby", + "@ruby//engine:jruby", ], ) @@ -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__", @@ -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__", @@ -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", @@ -193,7 +190,7 @@ genrule( """, tags = ["manual"], target_compatible_with = select({ - "@rules_ruby//ruby/runtime:config_jruby": [], + "@ruby//engine:jruby": [], "//conditions:default": ["@platforms//:incompatible"], }), ) @@ -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"], diff --git a/ruby/defs.bzl b/ruby/defs.bzl index 7f60b47f5cdd0..00ba450038a52 100644 --- a/ruby/defs.bzl +++ b/ruby/defs.bzl @@ -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( @@ -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 ) diff --git a/ruby/ext/google/protobuf_c/BUILD.bazel b/ruby/ext/google/protobuf_c/BUILD.bazel index 33c42bd17717c..3d2fc653a8c1b 100644 --- a/ruby/ext/google/protobuf_c/BUILD.bazel +++ b/ruby/ext/google/protobuf_c/BUILD.bazel @@ -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 = [ diff --git a/ruby/lib/google/BUILD.bazel b/ruby/lib/google/BUILD.bazel index e5aaceab911ce..c4b9c5202bc0f 100644 --- a/ruby/lib/google/BUILD.bazel +++ b/ruby/lib/google/BUILD.bazel @@ -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", @@ -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({ @@ -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( diff --git a/ruby/src/main/java/BUILD.bazel b/ruby/src/main/java/BUILD.bazel index b596e6a26d4d7..2c7423a0cf2a3 100644 --- a/ruby/src/main/java/BUILD.bazel +++ b/ruby/src/main/java/BUILD.bazel @@ -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__"], diff --git a/ruby/tests/BUILD.bazel b/ruby/tests/BUILD.bazel index f61982eb1cb78..4b1e0d8a2fd5a 100644 --- a/ruby/tests/BUILD.bazel +++ b/ruby/tests/BUILD.bazel @@ -1,8 +1,8 @@ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") -load("@rules_ruby//ruby:defs.bzl", "ruby_library", "ruby_test") +load("@rules_ruby//ruby:defs.bzl", "rb_library", "rb_test") load("//ruby:defs.bzl", "internal_ruby_proto_library") -ruby_library( +rb_library( name = "common_tests", srcs = ["common_tests.rb"], ) @@ -10,155 +10,150 @@ ruby_library( internal_ruby_proto_library( name = "test_ruby_protos", srcs = glob(["*.proto"]), - includes = [ - ".", - "ruby/tests", - "src", - ], visibility = [ "//ruby:__subpackages__", ], deps = ["//ruby:well_known_ruby_protos"], ) -ruby_test( +rb_test( name = "implementation", srcs = ["implementation.rb"], deps = [ "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "basic", srcs = ["basic.rb"], deps = [ ":common_tests", ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "basic_proto2", srcs = ["basic_proto2.rb"], deps = [ ":common_tests", ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "encode_decode_test", srcs = ["encode_decode_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "gc_test", srcs = ["gc_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "generated_code_test", srcs = ["generated_code_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "multi_level_nesting_test", srcs = ["multi_level_nesting_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "object_cache_test", srcs = ["object_cache_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "repeated_field_test", srcs = ["repeated_field_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "ruby_version", srcs = ["ruby_version.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "stress", srcs = ["stress.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "type_errors", srcs = ["type_errors.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "utf8", srcs = ["utf8.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "well_known_types_test", srcs = ["well_known_types_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) From d1ea3178449ef20bc4d8bcd6edee02a1ac2bf925 Mon Sep 17 00:00:00 2001 From: Jason Lunn Date: Fri, 27 Dec 2024 15:29:58 -0500 Subject: [PATCH 4/4] Switch `rules_ruby` to the supported version from `bazel-contrib` --- MODULE.bazel | 17 +++++++ WORKSPACE | 45 +++++++++--------- WORKSPACE.bzlmod | 17 ------- protobuf.bzl | 12 ++--- ruby/BUILD.bazel | 21 ++++----- ruby/defs.bzl | 6 +-- ruby/ext/google/protobuf_c/BUILD.bazel | 3 +- ruby/lib/google/BUILD.bazel | 21 ++------- ruby/src/main/java/BUILD.bazel | 3 +- ruby/tests/BUILD.bazel | 65 ++++++++++++-------------- 10 files changed, 92 insertions(+), 118 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 74a215ac5f564..3576dcb76e640 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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") @@ -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") diff --git a/WORKSPACE b/WORKSPACE index c49abcf5329fc..9e9febe0f535f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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( diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod index a3dd8925a198e..e91b392bb63bd 100644 --- a/WORKSPACE.bzlmod +++ b/WORKSPACE.bzlmod @@ -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. diff --git a/protobuf.bzl b/protobuf.bzl index 283c858507e47..63d581bc8719d 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -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, @@ -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. """ @@ -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, @@ -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 ) diff --git a/ruby/BUILD.bazel b/ruby/BUILD.bazel index 4a62a3e60e78b..3d404758b1a22 100755 --- a/ruby/BUILD.bazel +++ b/ruby/BUILD.bazel @@ -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") @@ -42,7 +42,7 @@ selects.config_setting_group( name = "jruby_ffi", match_all = [ ":ffi_enabled", - "@rules_ruby//ruby/runtime:config_jruby", + "@ruby//engine:jruby", ], ) @@ -50,7 +50,7 @@ selects.config_setting_group( name = "jruby_native", match_all = [ ":ffi_disabled", - "@rules_ruby//ruby/runtime:config_jruby", + "@ruby//engine:jruby", ], ) @@ -58,7 +58,7 @@ selects.config_setting_group( name = "ruby_ffi", match_all = [ ":ffi_enabled", - "@rules_ruby//ruby/runtime:config_ruby", + "@ruby//engine:jruby", ], ) @@ -66,7 +66,7 @@ selects.config_setting_group( name = "ruby_native", match_all = [ ":ffi_disabled", - "@rules_ruby//ruby/runtime:config_ruby", + "@ruby//engine:jruby", ], ) @@ -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__", @@ -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__", @@ -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", @@ -193,7 +190,7 @@ genrule( """, tags = ["manual"], target_compatible_with = select({ - "@rules_ruby//ruby/runtime:config_jruby": [], + "@ruby//engine:jruby": [], "//conditions:default": ["@platforms//:incompatible"], }), ) @@ -230,7 +227,7 @@ genrule( """, tags = ["manual"], target_compatible_with = select({ - "@rules_ruby//ruby/runtime:config_ruby": [], + "@ruby//engine:jruby": [], "//conditions:default": ["@platforms//:incompatible"], }), ) @@ -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"], diff --git a/ruby/defs.bzl b/ruby/defs.bzl index 7f60b47f5cdd0..00ba450038a52 100644 --- a/ruby/defs.bzl +++ b/ruby/defs.bzl @@ -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( @@ -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 ) diff --git a/ruby/ext/google/protobuf_c/BUILD.bazel b/ruby/ext/google/protobuf_c/BUILD.bazel index 33c42bd17717c..58c5356daaca6 100644 --- a/ruby/ext/google/protobuf_c/BUILD.bazel +++ b/ruby/ext/google/protobuf_c/BUILD.bazel @@ -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, ) diff --git a/ruby/lib/google/BUILD.bazel b/ruby/lib/google/BUILD.bazel index e5aaceab911ce..49825a7d16041 100644 --- a/ruby/lib/google/BUILD.bazel +++ b/ruby/lib/google/BUILD.bazel @@ -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", @@ -44,7 +44,6 @@ genrule( java_binary( name = "protobuf_java_bin", create_executable = False, - deploy_env = ["@rules_ruby//ruby/runtime:jruby_binary"], runtime_deps = [ "//ruby/src/main/java:protobuf_java", ], @@ -60,14 +59,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({ @@ -76,21 +75,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( diff --git a/ruby/src/main/java/BUILD.bazel b/ruby/src/main/java/BUILD.bazel index b596e6a26d4d7..f4114c5897eed 100644 --- a/ruby/src/main/java/BUILD.bazel +++ b/ruby/src/main/java/BUILD.bazel @@ -9,14 +9,13 @@ 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__"], deps = [ "//java/core", "//java/util", - "@rules_ruby//ruby/runtime:jars", ], ) diff --git a/ruby/tests/BUILD.bazel b/ruby/tests/BUILD.bazel index f61982eb1cb78..4b1e0d8a2fd5a 100644 --- a/ruby/tests/BUILD.bazel +++ b/ruby/tests/BUILD.bazel @@ -1,8 +1,8 @@ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") -load("@rules_ruby//ruby:defs.bzl", "ruby_library", "ruby_test") +load("@rules_ruby//ruby:defs.bzl", "rb_library", "rb_test") load("//ruby:defs.bzl", "internal_ruby_proto_library") -ruby_library( +rb_library( name = "common_tests", srcs = ["common_tests.rb"], ) @@ -10,155 +10,150 @@ ruby_library( internal_ruby_proto_library( name = "test_ruby_protos", srcs = glob(["*.proto"]), - includes = [ - ".", - "ruby/tests", - "src", - ], visibility = [ "//ruby:__subpackages__", ], deps = ["//ruby:well_known_ruby_protos"], ) -ruby_test( +rb_test( name = "implementation", srcs = ["implementation.rb"], deps = [ "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "basic", srcs = ["basic.rb"], deps = [ ":common_tests", ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "basic_proto2", srcs = ["basic_proto2.rb"], deps = [ ":common_tests", ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "encode_decode_test", srcs = ["encode_decode_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "gc_test", srcs = ["gc_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "generated_code_test", srcs = ["generated_code_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "multi_level_nesting_test", srcs = ["multi_level_nesting_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "object_cache_test", srcs = ["object_cache_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "repeated_field_test", srcs = ["repeated_field_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "ruby_version", srcs = ["ruby_version.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "stress", srcs = ["stress.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "type_errors", srcs = ["type_errors.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "utf8", srcs = ["utf8.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], ) -ruby_test( +rb_test( name = "well_known_types_test", srcs = ["well_known_types_test.rb"], deps = [ ":test_ruby_protos", "//ruby:protobuf", - "@protobuf_bundle//:test-unit", + "@protobuf_bundle", ], )