Skip to content

Commit c52d80c

Browse files
JasonLunncopybara-github
authored andcommitted
Ruby FFI implementation (#13343)
Supersedes #11483. Closes #13343 COPYBARA_INTEGRATE_REVIEW=#13343 from protocolbuffers:simultaneous_ffi bcb4bb7 PiperOrigin-RevId: 550782245
1 parent d4f2d48 commit c52d80c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4408
-191
lines changed

.github/workflows/test_ruby.yml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
include:
20-
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1}
20+
# Test both FFI and Native implementations on the highest and lowest
21+
# Ruby versions for CRuby and JRuby, but only on Bazel 5.x.
22+
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1, ffi: NATIVE}
23+
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1, ffi: FFI}
2124
- { name: Ruby 3.0, ruby: ruby-3.0.2, bazel: 5.1.1}
2225
- { name: Ruby 3.1, ruby: ruby-3.1.0, bazel: 5.1.1}
23-
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1}
24-
- { name: JRuby 9.2, ruby: jruby-9.2.20.1, bazel: 5.1.1}
25-
- { name: JRuby 9.3, ruby: jruby-9.3.10.0, bazel: 5.1.1}
26-
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1}
26+
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1, ffi: NATIVE}
27+
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1, ffi: FFI}
28+
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1, ffi: NATIVE}
29+
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1, ffi: FFI}
2730
- { name: Ruby 2.7 (Bazel6), ruby: ruby-2.7.0, bazel: 6.0.0}
2831
- { name: JRuby 9.4 (Bazel6), ruby: jruby-9.4.3.0, bazel: 6.0.0}
2932

30-
name: Linux ${{ matrix.name }}
33+
name: Linux ${{ matrix.name }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }}
3134
runs-on: ubuntu-latest
3235
steps:
3336
- name: Checkout pending changes
@@ -40,7 +43,7 @@ jobs:
4043
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:{0}-{1}-508417e5215994ade7585d28ba3aad681a25fa5d', matrix.ruby, matrix.bazel) }}
4144
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
4245
bazel-cache: ruby_linux/${{ matrix.ruby }}_${{ matrix.bazel }}
43-
bazel: test //ruby/... //ruby/tests:ruby_version --test_env=KOKORO_RUBY_VERSION
46+
bazel: test //ruby/... //ruby/tests:ruby_version --test_env=KOKORO_RUBY_VERSION --test_env=BAZEL=true ${{ matrix.ffi == 'FFI' && '--//ruby:ffi=enabled --test_env=PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI' || '' }}
4447

4548
linux-aarch64:
4649
name: Linux aarch64
@@ -78,10 +81,18 @@ jobs:
7881
strategy:
7982
fail-fast: false # Don't cancel all jobs if one fails.
8083
matrix:
81-
# This is the full set of versions we support on MacOS.
82-
version: [ "2.7", "3.0", "3.1", "3.2" ]
84+
include:
85+
# Test both FFI and Native implementations on the highest and lowest
86+
# Ruby versions for CRuby, but only on Bazel 5.x.
87+
# Quote versions numbers otherwise 3.0 will render as 3
88+
- { version: "2.7", ffi: NATIVE }
89+
- { version: "2.7", ffi: FFI }
90+
- { version: "3.0" }
91+
- { version: "3.1" }
92+
- { version: "3.2", ffi: NATIVE }
93+
- { version: "3.2", ffi: FFI }
8394

84-
name: MacOS Ruby ${{ matrix.version }}
95+
name: MacOS Ruby ${{ matrix.version }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }}
8596
runs-on: macos-12
8697
steps:
8798
- name: Checkout pending changes
@@ -102,23 +113,26 @@ jobs:
102113
with:
103114
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
104115
bazel-cache: ruby_macos/${{ matrix.version }}
105-
bazel: test //ruby/... --test_env=KOKORO_RUBY_VERSION=${{ matrix.version }}
116+
bazel: test //ruby/... --test_env=KOKORO_RUBY_VERSION=${{ matrix.version }} --test_env=BAZEL=true ${{ matrix.ffi == 'FFI' && '--//ruby:ffi=enabled --test_env=PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI' || '' }}
106117

107118
test_ruby_gems:
108119
strategy:
109120
fail-fast: false
110121
matrix:
111122
include:
112-
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1}
123+
# Test both FFI and Native implementations on the highest and lowest
124+
# Ruby versions for CRuby and JRuby, but only on Bazel 5.x.
125+
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1, ffi: NATIVE }
126+
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1, ffi: FFI }
113127
- { name: Ruby 3.0, ruby: ruby-3.0.2, bazel: 5.1.1}
114128
- { name: Ruby 3.1, ruby: ruby-3.1.0, bazel: 5.1.1}
115-
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1}
116-
- { name: JRuby 9.2, ruby: jruby-9.2.20.1, bazel: 5.1.1}
117-
- { name: JRuby 9.3, ruby: jruby-9.3.10.0, bazel: 5.1.1}
118-
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1}
129+
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1, ffi: NATIVE }
130+
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1, ffi: FFI }
131+
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1, ffi: NATIVE }
132+
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1, ffi: FFI }
119133
- { name: Ruby 2.7 (Bazel6), ruby: ruby-2.7.0, bazel: 6.0.0}
120134
- { name: JRuby 9.4 (Bazel6), ruby: jruby-9.4.3.0, bazel: 6.0.0}
121-
name: Install ${{ matrix.name }}
135+
name: Install ${{ matrix.name }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }}
122136
runs-on: ubuntu-latest
123137
steps:
124138
- name: Checkout pending changes
@@ -134,8 +148,9 @@ jobs:
134148
bash: >
135149
bazel --version;
136150
ruby --version;
137-
bazel build //ruby:release //:protoc $BAZEL_FLAGS;
151+
bazel build //ruby:release //:protoc ${{ matrix.ffi == 'FFI' && '--//ruby:ffi=enabled' || '' }} $BAZEL_FLAGS;
138152
gem install bazel-bin/ruby/google-protobuf-*;
139153
bazel-bin/protoc --proto_path=src --proto_path=ruby/tests --proto_path=ruby --ruby_out=ruby tests/test_import_proto2.proto;
140154
bazel-bin/protoc --proto_path=src --proto_path=ruby/tests --proto_path=ruby --ruby_out=ruby tests/basic_test.proto;
141-
ruby ruby/tests/basic.rb
155+
${{ matrix.ffi == 'FFI' && 'PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI' || '' }} ruby ruby/tests/basic.rb;
156+
${{ matrix.ffi == 'FFI' && 'PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI' || '' }} ruby ruby/tests/implementation.rb

conformance/BUILD.bazel

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ exports_files([
2424
"failure_list_python_cpp.txt",
2525
"failure_list_ruby.txt",
2626
"failure_list_jruby.txt",
27+
"failure_list_jruby_ffi.txt",
2728
"text_format_failure_list_cpp.txt",
2829
"text_format_failure_list_csharp.txt",
2930
"text_format_failure_list_java.txt",
@@ -34,6 +35,7 @@ exports_files([
3435
"text_format_failure_list_python_cpp.txt",
3536
"text_format_failure_list_ruby.txt",
3637
"text_format_failure_list_jruby.txt",
38+
"text_format_failure_list_jruby_ffi.txt",
3739
])
3840

3941
cc_proto_library(
@@ -326,12 +328,12 @@ ruby_binary(
326328
name = "conformance_ruby",
327329
testonly = True,
328330
srcs = ["conformance_ruby.rb"],
331+
visibility = ["//ruby:__subpackages__"],
329332
deps = [
330333
":conformance_ruby_proto",
331334
"//:test_messages_proto2_ruby_proto",
332-
"//:test_messages_proto3_ruby_proto",
335+
"//:test_messages_proto3_ruby_proto",
333336
],
334-
visibility = ["//ruby:__subpackages__"],
335337
)
336338

337339
################################################################################
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
2+
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput

protobuf_deps.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def protobuf_deps():
110110
_github_archive(
111111
name = "rules_ruby",
112112
repo = "https://github.com/protocolbuffers/rules_ruby",
113-
commit = "8fca842a3006c3d637114aba4f6bf9695bb3a432",
114-
sha256 = "2619f9a23cee6f6a198d9ef284b6f6cbc901545ee9a9aac9ffa6b83dbf17cf0c",
113+
commit = "b7f3e9756f3c45527be27bc38840d5a1ba690436",
114+
sha256 = "347927fd8de6132099fcdc58e8f7eab7bde4eb2fd424546b9cd4f1c6f8f8bad8",
115115
)
116116

117117
if not native.existing_rule("rules_jvm_external"):

ruby/.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ protobuf-jruby.iml
66
target/
77
pkg/
88
tmp/
9-
tests/google/
9+
tests/google/
10+
ext/google/protobuf_c/third_party/utf8_range/utf8_range.h
11+
ext/google/protobuf_c/third_party/utf8_range/range2-sse.c
12+
ext/google/protobuf_c/third_party/utf8_range/range2-neon.c
13+
ext/google/protobuf_c/third_party/utf8_range/naive.c
14+
ext/google/protobuf_c/third_party/utf8_range/LICENSE
15+
lib/google/protobuf/*_pb.rb

0 commit comments

Comments
 (0)