Skip to content

Commit

Permalink
Bazelify ruby runtime (#10525)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mkruskal-google authored and copybara-github committed Dec 27, 2022
1 parent 15dff73 commit 1f46113
Show file tree
Hide file tree
Showing 35 changed files with 616 additions and 379 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ ruby/tests/generated_code_proto2_pb.rb
ruby/tests/multi_level_nesting_test_pb.rb
ruby/tests/test_import_proto2_pb.rb
ruby/tests/test_ruby_package_proto2_pb.rb
ruby/Gemfile.lock
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
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ internal_ruby_proto_library(
name = "well_known_ruby_protos",
srcs = [":well_known_protos"],
includes = ["src"],
default_runtime = "",
visibility = [
"//conformance:__pkg__",
"//ruby:__subpackages__",
Expand Down
14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,27 @@ bazel_skylib_workspace()
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()

load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
apple_rules_dependencies()

# For `kt_jvm_library`
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")
kotlin_repositories()

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

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

load("@system_ruby//:bundle.bzl", "ruby_bundle")
ruby_bundle(
name = "protobuf_bundle",
srcs = ["//ruby:google-protobuf.gemspec"],
gemfile = "//ruby:Gemfile",
)

load("@upb//bazel:workspace_deps.bzl", "upb_deps")
upb_deps()

Expand Down
12 changes: 5 additions & 7 deletions conformance/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Conformance testing for Protobuf.

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "objc_library")
load("@rules_ruby//ruby:defs.bzl", "ruby_binary")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load(
Expand Down Expand Up @@ -317,19 +318,16 @@ cc_binary(
deps = [":conformance_objc_lib"],
)

inline_sh_binary(
ruby_binary(
name = "conformance_ruby",
testonly = 1,
testonly = True,
srcs = ["conformance_ruby.rb"],
cmd = "RUBYLIB=ruby/lib:conformance:src $(rootpath conformance_ruby.rb)",
visibility = ["//ruby:__subpackages__"],
deps = [
":conformance_ruby_proto",
"//:test_messages_proto2_ruby_proto",
"//:test_messages_proto3_ruby_proto",
"//:well_known_ruby_protos",
"//ruby:protobuf",
"//:test_messages_proto3_ruby_proto",
],
visibility = ["//ruby:__subpackages__"],
)

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion conformance/conformance_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

require 'conformance_pb'
require 'conformance/conformance_pb'
require 'google/protobuf/test_messages_proto3_pb'
require 'google/protobuf/test_messages_proto2_pb'

Expand Down
7 changes: 1 addition & 6 deletions kokoro/linux/jruby92/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ timeout_mins: 120

env_vars {
key: "CONTAINER_IMAGE"
value: "gcr.io/protobuf-build/ruby/linux:jruby-9.2.20.1-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
value: "gcr.io/protobuf-build/ruby/linux:jruby-9.2.20.1-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
}

env_vars {
key: "BAZEL_TARGETS"
value: "//ruby/..."
}

env_vars {
key: "BAZEL_EXTRA_FLAGS"
value: "--define=ruby_platform=java"
}

action {
define_artifacts {
regex: "**/sponge_log.*"
Expand Down
7 changes: 1 addition & 6 deletions kokoro/linux/jruby93/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ timeout_mins: 120

env_vars {
key: "CONTAINER_IMAGE"
value: "gcr.io/protobuf-build/ruby/linux:jruby-9.3.4.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
value: "gcr.io/protobuf-build/ruby/linux:jruby-9.3.4.0-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
}

env_vars {
key: "BAZEL_TARGETS"
value: "//ruby/..."
}

env_vars {
key: "BAZEL_EXTRA_FLAGS"
value: "--define=ruby_platform=java"
}

action {
define_artifacts {
regex: "**/sponge_log.*"
Expand Down
7 changes: 1 addition & 6 deletions kokoro/linux/ruby25/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ timeout_mins: 120

env_vars {
key: "CONTAINER_IMAGE"
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.5.1-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.5.1-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
}

env_vars {
key: "BAZEL_TARGETS"
value: "//ruby/..."
}

env_vars {
key: "BAZEL_EXTRA_FLAGS"
value: "--define=ruby_platform=c"
}

action {
define_artifacts {
regex: "**/sponge_log.*"
Expand Down
7 changes: 1 addition & 6 deletions kokoro/linux/ruby26/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ timeout_mins: 120

env_vars {
key: "CONTAINER_IMAGE"
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.6.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.6.0-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
}

env_vars {
key: "BAZEL_TARGETS"
value: "//ruby/..."
}

env_vars {
key: "BAZEL_EXTRA_FLAGS"
value: "--define=ruby_platform=c"
}

action {
define_artifacts {
regex: "**/sponge_log.*"
Expand Down
7 changes: 1 addition & 6 deletions kokoro/linux/ruby27/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ timeout_mins: 120

env_vars {
key: "CONTAINER_IMAGE"
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.7.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
value: "gcr.io/protobuf-build/ruby/linux:ruby-2.7.0-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
}

env_vars {
key: "BAZEL_TARGETS"
value: "//ruby/..."
}

env_vars {
key: "BAZEL_EXTRA_FLAGS"
value: "--define=ruby_platform=c"
}

action {
define_artifacts {
regex: "**/sponge_log.*"
Expand Down
7 changes: 1 addition & 6 deletions kokoro/linux/ruby30/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ timeout_mins: 120

env_vars {
key: "CONTAINER_IMAGE"
value: "gcr.io/protobuf-build/ruby/linux:ruby-3.0.2-2f706fd1ab49f4e97af769388be486069b63efee"
value: "gcr.io/protobuf-build/ruby/linux:ruby-3.0.2-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
}

env_vars {
key: "BAZEL_TARGETS"
value: "//ruby/..."
}

env_vars {
key: "BAZEL_EXTRA_FLAGS"
value: "--define=ruby_platform=c"
}

action {
define_artifacts {
regex: "**/sponge_log.*"
Expand Down
7 changes: 1 addition & 6 deletions kokoro/linux/ruby31/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ timeout_mins: 120

env_vars {
key: "CONTAINER_IMAGE"
value: "gcr.io/protobuf-build/ruby/linux:ruby-3.1.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8"
value: "gcr.io/protobuf-build/ruby/linux:ruby-3.1.0-6fe0cedf2f7f54867de2c3a64f93c85661c9f8a4"
}

env_vars {
key: "BAZEL_TARGETS"
value: "//ruby/..."
}

env_vars {
key: "BAZEL_EXTRA_FLAGS"
value: "--define=ruby_platform=c"
}

action {
define_artifacts {
regex: "**/sponge_log.*"
Expand Down
7 changes: 1 addition & 6 deletions kokoro/macos/ruby25/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
# Change to repo root
cd $(dirname $0)/../../..

# Prepare worker environment to run tests
KOKORO_INSTALL_RVM=yes
source kokoro/macos/prepare_build_macos_rc

cd ruby
./travis-test.sh ruby-2.5.1
bash -l kokoro/macos/test_ruby.sh ruby-2.5.1
7 changes: 1 addition & 6 deletions kokoro/macos/ruby26/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
# Change to repo root
cd $(dirname $0)/../../..

# Prepare worker environment to run tests
KOKORO_INSTALL_RVM=yes
source kokoro/macos/prepare_build_macos_rc

cd ruby
./travis-test.sh ruby-2.6.0
bash -l kokoro/macos/test_ruby.sh ruby-2.6.0
7 changes: 1 addition & 6 deletions kokoro/macos/ruby27/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
# Change to repo root
cd $(dirname $0)/../../..

# Prepare worker environment to run tests
KOKORO_INSTALL_RVM=yes
source kokoro/macos/prepare_build_macos_rc

cd ruby
./travis-test.sh ruby-2.7.0
bash -l kokoro/macos/test_ruby.sh ruby-2.7.0
7 changes: 1 addition & 6 deletions kokoro/macos/ruby30/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
# Change to repo root
cd $(dirname $0)/../../..

# Prepare worker environment to run tests
KOKORO_INSTALL_RVM=yes
source kokoro/macos/prepare_build_macos_rc

cd ruby
./travis-test.sh ruby-3.0.2
bash -l kokoro/macos/test_ruby.sh ruby-3.0.2
7 changes: 1 addition & 6 deletions kokoro/macos/ruby31/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,4 @@ cd $(dirname $0)/../../..
# Fix locale issues in Monterey.
export LC_ALL=en_US.UTF-8

# Prepare worker environment to run tests
KOKORO_INSTALL_RVM=yes
source kokoro/macos/prepare_build_macos_rc

cd ruby
./travis-test.sh ruby-3.1.0
bash -l kokoro/macos/test_ruby.sh ruby-3.1.0
24 changes: 24 additions & 0 deletions kokoro/macos/test_ruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -eux

VERSION=$1

# Prepare worker environment to run tests
KOKORO_INSTALL_RVM=yes
source kokoro/macos/prepare_build_macos_rc

# Install dependencies
brew install wget

# Configure system ruby.
# We need to disable unbound variable errors, due to a known issue described in
# https://github.com/rvm/rvm/issues/4618.
set +u
rvm install $VERSION
rvm use $VERSION
rvm current | grep -qe "${RUBY_VERSION}.*" || exit 1;
set -u

# Run tests
bazel test //ruby/... --test_env=KOKORO_RUBY_VERSION=$VERSION
2 changes: 1 addition & 1 deletion kokoro/release/ruby/macos/ruby/ruby_build_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set -e # rvm commands are very verbose
time rvm install 2.5.0
rvm use 2.5.0
gem install rake-compiler --no-document
gem install bundler --no-document
gem install bundler -v 2.3.26 --no-document
time rvm install 3.1.0
rvm use 3.1.0
gem install rake-compiler --no-document
Expand Down
Loading

0 comments on commit 1f46113

Please sign in to comment.