Skip to content

Commit dbb9619

Browse files
habermanMaaarcocr
andauthored
Cherry-pick to get Ruby 3.1 support in protobuf 3.20.0 (#9657)
* Allow pre-compiled binaries for ruby 3.1.0 (#9566) * Allow pre-compiled binaries for ruby 3.1.1 * add comment * fix build and use ruby 3.1.0 * add ruby31 to build CI for tests and release * trying to fix ci * install ruby 3.1.0 in ruby_build_environment.sh * use head for rvm to install 3.1.0 * just install master version of rvm in prepare_build_macos_rc * force install of master rvm in ruby_build_environment.sh * Use coroutine=universal when compiling ruby31 * use ucontext * fix filename * fix coroutine name * use git head for rake-compiler-dock * use newest rake-compiler-dock version * Updated CHANGES.txt for Ruby changes. * Fixed Ruby 3.1 tests by marking intersect? as unimplemented. (#9645) * Fixed Ruby 3.1 tests by marking intersect? as unimplemented. * Updated compatibility tests. Co-authored-by: Marco Concetto Rudilosso <marcoconcettorudilosso@gmail.com>
1 parent 2099298 commit dbb9619

File tree

15 files changed

+119
-7
lines changed

15 files changed

+119
-7
lines changed

CHANGES.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
Ruby
44
* Dropped Ruby 2.3 and 2.4 support for CI and releases. (#9311)
5-
* Message.decode/encode: Add max_recursion_depth option (#9218)
6-
* Rename max_recursion_depth to recursion_limit (#9486)
5+
* Added Ruby 3.1 support for CI and releases (#9566).
6+
* Message.decode/encode: Add recursion_limit option (#9218/#9486)
7+
* Allocate with xrealloc()/xfree() so message allocation is visible to the
8+
Ruby GC. In certain tests this leads to much lower memory usage due to more
9+
frequent GC runs (#9586).
710
* Fix conversion of singleton classes in Ruby (#9342)
811
* Suppress warning for intentional circular require (#9556)
912
* JSON will now output shorter strings for double and float fields when possible

kokoro/linux/dockerfile/test/ruby/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ RUN /bin/bash -l -c "rvm install 2.5.1"
3535
RUN /bin/bash -l -c "rvm install 2.6.0"
3636
RUN /bin/bash -l -c "rvm install 2.7.0"
3737
RUN /bin/bash -l -c "rvm install 3.0.0"
38+
RUN /bin/bash -l -c "rvm install 3.1.0"
3839
RUN /bin/bash -l -c "rvm install jruby-9.2.20.1"
3940
RUN /bin/bash -l -c "rvm install jruby-9.3.3.0"
4041

kokoro/linux/ruby31/build.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
#
3+
# This is the top-level script we give to Kokoro as the entry point for
4+
# running the "pull request" project:
5+
#
6+
# This script selects a specific Dockerfile (for building a Docker image) and
7+
# a script to run inside that image. Then we delegate to the general
8+
# build_and_run_docker.sh script.
9+
10+
# Change to repo root
11+
cd $(dirname $0)/../../..
12+
13+
export DOCKERHUB_ORGANIZATION=protobuftesting
14+
export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby
15+
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
16+
export OUTPUT_DIR=testoutput
17+
export TEST_SET="ruby31"
18+
./kokoro/linux/build_and_run_docker.sh

kokoro/linux/ruby31/continuous.cfg

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Config file for running tests in Kokoro
2+
3+
# Location of the build script in repository
4+
build_file: "protobuf/kokoro/linux/ruby31/build.sh"
5+
timeout_mins: 120
6+
7+
action {
8+
define_artifacts {
9+
regex: "**/sponge_log.xml"
10+
}
11+
}

kokoro/linux/ruby31/presubmit.cfg

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Config file for running tests in Kokoro
2+
3+
# Location of the build script in repository
4+
build_file: "protobuf/kokoro/linux/ruby31/build.sh"
5+
timeout_mins: 120
6+
7+
action {
8+
define_artifacts {
9+
regex: "**/sponge_log.xml"
10+
}
11+
}

kokoro/macos/prepare_build_macos_rc

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ if [[ "${KOKORO_INSTALL_RVM:-}" == "yes" ]] ; then
3636
# Old OpenSSL versions cannot handle the SSL certificate used by
3737
# https://get.rvm.io, so as a workaround we download RVM directly from
3838
# GitHub. See this issue for details: https://github.com/rvm/rvm/issues/5133
39-
curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s stable --ruby
39+
curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s master --ruby
4040
fi

kokoro/macos/ruby31/build.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
#
3+
# Build file to set up and run tests
4+
5+
# Change to repo root
6+
cd $(dirname $0)/../../..
7+
8+
# Prepare worker environment to run tests
9+
KOKORO_INSTALL_RVM=yes
10+
source kokoro/macos/prepare_build_macos_rc
11+
12+
./tests.sh ruby31

kokoro/macos/ruby31/continuous.cfg

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Config file for running tests in Kokoro
2+
3+
# Location of the build script in repository
4+
build_file: "protobuf/kokoro/macos/ruby31/build.sh"
5+
timeout_mins: 1440

kokoro/macos/ruby31/presubmit.cfg

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Config file for running tests in Kokoro
2+
3+
# Location of the build script in repository
4+
build_file: "protobuf/kokoro/macos/ruby31/build.sh"
5+
timeout_mins: 1440

kokoro/release/ruby/macos/ruby/ruby_build_environment.sh

+40
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@
33
set -ex
44

55
set +ex # rvm script is very verbose and exits with errorcode
6+
7+
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
8+
curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -
9+
10+
# Old OpenSSL versions cannot handle the SSL certificate used by
11+
# https://get.rvm.io, so as a workaround we download RVM directly from
12+
# GitHub. See this issue for details: https://github.com/rvm/rvm/issues/5133
13+
curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s master --ruby
14+
615
source $HOME/.rvm/scripts/rvm
716
set -e # rvm commands are very verbose
817
time rvm install 2.5.0
918
rvm use 2.5.0
1019
gem install rake-compiler --no-document
1120
gem install bundler --no-document
21+
time rvm install 3.1.0
22+
rvm use 3.1.0
23+
gem install rake-compiler --no-document
24+
gem install bundler --no-document
1225
time rvm install 2.7.0
1326
rvm use 2.7.0 --default
1427
gem install rake-compiler --no-document
@@ -20,6 +33,8 @@ set -ex
2033
rm -rf ~/.rake-compiler
2134

2235
CROSS_RUBY=$(mktemp tmpfile.XXXXXXXX)
36+
CROSS_RUBY31=$(mktemp tmpfile.XXXXXXXX)
37+
2338

2439
curl https://raw.githubusercontent.com/rake-compiler/rake-compiler/72184e51779b6a3b9b8580b036a052fdc3181ced/tasks/bin/cross-ruby.rake > "$CROSS_RUBY"
2540

@@ -52,8 +67,33 @@ patch "$CROSS_RUBY" << EOF
5267
end
5368
EOF
5469

70+
cp $CROSS_RUBY $CROSS_RUBY31
71+
72+
patch "$CROSS_RUBY31" << EOF
73+
--- cross-ruby.rake 2022-03-04 11:49:52.000000000 +0000
74+
+++ patched 2022-03-04 11:58:22.000000000 +0000
75+
@@ -114,6 +114,7 @@
76+
'--enable-static',
77+
'--disable-shared',
78+
'--disable-install-doc',
79+
+ '--with-coroutine=ucontext',
80+
'--without-gmp',
81+
'--with-ext=',
82+
'LDFLAGS=-pipe',
83+
EOF
84+
5585
MAKE="make -j8"
5686

87+
set +x # rvm commands are very verbose
88+
rvm use 3.1.0
89+
set -x
90+
ruby --version | grep 'ruby 3.1.0'
91+
for v in 3.1.0 ; do
92+
ccache -c
93+
rake -f "$CROSS_RUBY31" cross-ruby VERSION="$v" HOST=x86_64-darwin MAKE="$MAKE"
94+
rake -f "$CROSS_RUBY31" cross-ruby VERSION="$v" HOST=aarch64-darwin MAKE="$MAKE"
95+
done
96+
5797
set +x # rvm commands are very verbose
5898
rvm use 2.7.0
5999
set -x

ruby/Rakefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ else
127127
['x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux'].each do |plat|
128128
RakeCompilerDock.sh <<-"EOT", platform: plat
129129
bundle && \
130-
IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.0
130+
IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=3.1.0:3.0.0:2.7.0:2.6.0:2.5.0
131131
EOT
132132
end
133133
end
134134

135135
if RUBY_PLATFORM =~ /darwin/
136136
task 'gem:native' do
137137
system "rake genproto"
138-
system "rake cross native gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.1"
138+
system "rake cross native gem RUBY_CC_VERSION=3.1.0:3.0.0:2.7.0:2.6.0:2.5.1"
139139
end
140140
else
141141
task 'gem:native' => [:genproto, 'gem:windows', 'gem:java']

ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_acts_like_an_array
2121
:nitems, :iter_for_reverse_each, :indexes, :append, :prepend]
2222
arr_methods -= [:union, :difference, :filter!]
2323
arr_methods -= [:intersection, :deconstruct] # ruby 2.7 methods we can ignore
24+
arr_methods -= [:intersect?] # ruby 3.1 methods we can ignore
2425
arr_methods.each do |method_name|
2526
assert m.repeated_string.respond_to?(method_name) == true, "does not respond to #{method_name}"
2627
end

ruby/google-protobuf.gemspec

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ Gem::Specification.new do |s|
1717
else
1818
s.files += Dir.glob('ext/**/*')
1919
s.extensions= ["ext/google/protobuf_c/extconf.rb"]
20-
s.add_development_dependency "rake-compiler-dock", "= 1.1.0"
21-
end
20+
s.add_development_dependency "rake-compiler-dock", "= 1.2.1" end
2221
s.test_files = ["tests/basic.rb",
2322
"tests/stress.rb",
2423
"tests/generated_code_test.rb"]

ruby/tests/repeated_field_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_acts_like_an_array
2121
:nitems, :iter_for_reverse_each, :indexes, :append, :prepend]
2222
arr_methods -= [:union, :difference, :filter!]
2323
arr_methods -= [:intersection, :deconstruct] # ruby 2.7 methods we can ignore
24+
arr_methods -= [:intersect?] # ruby 3.1 methods we can ignore
2425
arr_methods.each do |method_name|
2526
assert m.repeated_string.respond_to?(method_name) == true, "does not respond to #{method_name}"
2627
end

tests.sh

+5
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ build_ruby30() {
422422
internal_build_cpp # For conformance tests.
423423
cd ruby && bash travis-test.sh ruby-3.0.2 && cd ..
424424
}
425+
build_ruby31() {
426+
internal_build_cpp # For conformance tests.
427+
cd ruby && bash travis-test.sh ruby-3.1.0 && cd ..
428+
}
425429

426430
build_jruby92() {
427431
internal_build_cpp # For conformance tests.
@@ -593,6 +597,7 @@ Usage: $0 { cpp |
593597
ruby26 |
594598
ruby27 |
595599
ruby30 |
600+
ruby31 |
596601
jruby92 |
597602
jruby93 |
598603
ruby_all |

0 commit comments

Comments
 (0)