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

Ruby FFI implementation #13343

Closed
wants to merge 85 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
394321f
branch to support FFI
JasonLunn Oct 31, 2022
11fcd23
restore protobuf.rb
JasonLunn Oct 31, 2022
09a7114
native implementation
JasonLunn Oct 31, 2022
1e50c8b
restore protobuf.rb
JasonLunn Oct 31, 2022
6cc806c
Refactor `protobuf.rb` to separate native and ffi implementations.
JasonLunn Oct 31, 2022
dfc7dbb
Fix spelling `Unsupport` -> `Unsupported`
JasonLunn Jan 6, 2023
fb395f8
Fix exception raising by properly instantiating the exception.
JasonLunn Jan 6, 2023
d9767ca
Add check on `PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION` environment varia…
JasonLunn Jan 6, 2023
3792576
Add FFI implementation
JasonLunn Jan 6, 2023
589629d
Add ffi flags
mkruskal-google Jan 10, 2023
2ec3aa3
Refactor convert.c to separate CRuby-specific glue that has dependenc…
JasonLunn Jan 11, 2023
a5ff141
Fix copy/paste casting bug.
JasonLunn Jan 11, 2023
cec7850
Refactor message.c to separate CRuby-specific glue that has dependenc…
JasonLunn Jan 11, 2023
4734f34
Have shared_convert methods invoke shared_message methods directly.
JasonLunn Jan 11, 2023
55cd7fe
branch to support FFI
JasonLunn Oct 31, 2022
2f3838b
restore protobuf.rb
JasonLunn Oct 31, 2022
c8656c4
native implementation
JasonLunn Oct 31, 2022
1c19455
restore protobuf.rb
JasonLunn Oct 31, 2022
f461e72
Refactor `protobuf.rb` to separate native and ffi implementations.
JasonLunn Oct 31, 2022
1b1e64e
Fix spelling `Unsupport` -> `Unsupported`
JasonLunn Jan 6, 2023
4cbcd56
Fix exception raising by properly instantiating the exception.
JasonLunn Jan 6, 2023
5d71437
Stop ignoring shared source files; ignore FFI Compiler output directo…
JasonLunn Jul 6, 2023
b402119
Update function names and arguments.
JasonLunn Jul 6, 2023
f7083f1
Remove references to `PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION`.
JasonLunn Jul 6, 2023
039af51
Relocate shared files.
JasonLunn Jul 6, 2023
8607cda
Temporarily update visibility, pending update to upb repo.
JasonLunn Jul 6, 2023
1a716c0
Create glue.
JasonLunn Jul 6, 2023
e7240f8
Fix unit tests.
JasonLunn Jul 7, 2023
8f95755
Rebase
JasonLunn Oct 31, 2022
1dff209
restore protobuf.rb
JasonLunn Oct 31, 2022
f4c08b2
Rebase
JasonLunn Oct 31, 2022
e32280e
restore protobuf.rb
JasonLunn Oct 31, 2022
536f9b3
Rebase
JasonLunn Oct 31, 2022
c665a79
Fix spelling `Unsupport` -> `Unsupported`
JasonLunn Jan 6, 2023
78a2928
Fix exception raising by properly instantiating the exception.
JasonLunn Jan 6, 2023
a7aa7aa
Rebase
JasonLunn Jan 6, 2023
bcc6f6c
Rebase
JasonLunn Jan 11, 2023
8336d0a
Refactor message.c to separate CRuby-specific glue that has dependenc…
JasonLunn Jan 11, 2023
88f1506
Have shared_convert methods invoke shared_message methods directly.
JasonLunn Jan 11, 2023
3089818
Fix merge damage
JasonLunn Jul 7, 2023
95c4535
Call `upb_Arena_Malloc()` directly.
JasonLunn Jul 7, 2023
0286c71
Address PR feedback.
JasonLunn Jul 7, 2023
2fd1eac
Cleanup debug print.
JasonLunn Jul 7, 2023
3d1d1fe
Revert changes to ruby-upb.h.
JasonLunn Jul 10, 2023
0d575d5
Merge remote-tracking branch 'upstream/main' into simultaneous_ffi
JasonLunn Jul 10, 2023
8920f9d
Update to the new Ruby-native ObjectCache.
JasonLunn Jul 10, 2023
72d6ee8
Allow fallback to native CRuby implementation when FFI doesn't load.
JasonLunn Jul 10, 2023
a3eb317
Introduce a new test that the expected implementation is used.
JasonLunn Jul 12, 2023
bc87afb
Merge remote-tracking branch 'upstream/main' into simultaneous_ffi
JasonLunn Jul 12, 2023
ca80881
Merge branch 'main' into simultaneous_ffi
JasonLunn Jul 13, 2023
2c8d0ef
Use the FFI-fix branch of rules_ruby.
JasonLunn Jul 14, 2023
2a1cf7c
Use backwards compatible range syntax.
JasonLunn Jul 14, 2023
e28e256
Move most calls to `attach_function` out of `ffi.rb`.
JasonLunn Jul 15, 2023
55f2884
Breakout conformance tests by platform and whether FFI is enabled.
JasonLunn Jul 15, 2023
03a32da
Merge remote-tracking branch 'upstream/main' into simultaneous_ffi
JasonLunn Jul 15, 2023
472b653
Remove workaround for access to UPI API functions.
JasonLunn Jul 16, 2023
af40b04
Default JRuby to autodetecting FFI but make CRuby request it explicitly.
JasonLunn Jul 17, 2023
839a3d7
Make all interpreters opt-in for FFI.
JasonLunn Jul 18, 2023
4c56ea0
Merge remote-tracking branch 'upstream/main' into simultaneous_ffi
JasonLunn Jul 18, 2023
47f29ff
Add test configurations for FFI.
JasonLunn Jul 18, 2023
22e814e
Doc update.
JasonLunn Jul 18, 2023
303cefa
Only depend on the FFI apple_bundle when building on macOS
JasonLunn Jul 18, 2023
194ecec
Align linux shared lib name to FFI Compiler's expectations.
JasonLunn Jul 18, 2023
ed78e3a
Github workflow fixes.
JasonLunn Jul 18, 2023
993b612
More Github workflow fixes.
JasonLunn Jul 18, 2023
5294b81
JRuby does not yet support Fixnum keys for WeakMap.
JasonLunn Jul 19, 2023
ed69fdb
Update test expectations.
JasonLunn Jul 19, 2023
502240a
Move FFI related Rake tasks to lib/tasks.
JasonLunn Jul 20, 2023
dc472af
Fix FFI installation.
JasonLunn Jul 20, 2023
12f3b90
Fix test expectations.
JasonLunn Jul 20, 2023
6a5e625
Fix extension loading.
JasonLunn Jul 20, 2023
9a17fea
Include the new Rakefile to fix release targets.
JasonLunn Jul 21, 2023
389cdba
Diagnostics: emit PWD to make it easier to diagnose path problems.
JasonLunn Jul 21, 2023
ab2a999
Merge remote-tracking branch 'upstream/main' into simultaneous_ffi
JasonLunn Jul 21, 2023
d5b8065
Add UTF8 range dependencies to //ruby:jruby_release target for use by…
JasonLunn Jul 21, 2023
d6499d1
Move the task to within the scope of the //ruby/lib:dist_rules scope.
JasonLunn Jul 21, 2023
002dfea
Move .gitignore changes to within scope of ruby directory.
JasonLunn Jul 21, 2023
75c3c7c
Move .gitignore changes to within scope of ruby directory.
JasonLunn Jul 21, 2023
47ff5ae
Update docs.
JasonLunn Jul 21, 2023
4ac2590
Merge remote-tracking branch 'upstream/main' into simultaneous_ffi
JasonLunn Jul 21, 2023
c8d3f86
Use quotes to prevent 3.0 from being truncated to 3.
JasonLunn Jul 24, 2023
a2648d7
Use quotes to prevent 3.0 from being truncated to 3.
JasonLunn Jul 24, 2023
e5cd20f
Use an opaque pointer to represent `MiniTable` instead of a struct.
JasonLunn Jul 24, 2023
6a9cb65
Revert use of `.by_ref` in function signatures that accept an Arena.
JasonLunn Jul 24, 2023
bcb4bb7
Revert "Use an opaque pointer to represent `MiniTable` instead of a s…
JasonLunn Jul 24, 2023
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
53 changes: 34 additions & 19 deletions .github/workflows/test_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ jobs:
fail-fast: false
matrix:
include:
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1}
# Test both FFI and Native implementations on the highest and lowest
# Ruby versions for CRuby and JRuby, but only on Bazel 5.x.
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1, ffi: NATIVE}
mkruskal-google marked this conversation as resolved.
Show resolved Hide resolved
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1, ffi: FFI}
- { name: Ruby 3.0, ruby: ruby-3.0.2, bazel: 5.1.1}
- { name: Ruby 3.1, ruby: ruby-3.1.0, bazel: 5.1.1}
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1}
- { name: JRuby 9.2, ruby: jruby-9.2.20.1, bazel: 5.1.1}
- { name: JRuby 9.3, ruby: jruby-9.3.10.0, bazel: 5.1.1}
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1}
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1, ffi: NATIVE}
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1, ffi: FFI}
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1, ffi: NATIVE}
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1, ffi: FFI}
- { name: Ruby 2.7 (Bazel6), ruby: ruby-2.7.0, bazel: 6.0.0}
- { name: JRuby 9.4 (Bazel6), ruby: jruby-9.4.3.0, bazel: 6.0.0}

name: Linux ${{ matrix.name }}
name: Linux ${{ matrix.name }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }}
runs-on: ubuntu-latest
steps:
- name: Checkout pending changes
Expand All @@ -40,7 +43,7 @@ jobs:
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:{0}-{1}-508417e5215994ade7585d28ba3aad681a25fa5d', matrix.ruby, matrix.bazel) }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: ruby_linux/${{ matrix.ruby }}_${{ matrix.bazel }}
bazel: test //ruby/... //ruby/tests:ruby_version --test_env=KOKORO_RUBY_VERSION
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' || '' }}
mkruskal-google marked this conversation as resolved.
Show resolved Hide resolved

linux-aarch64:
name: Linux aarch64
Expand Down Expand Up @@ -78,10 +81,18 @@ jobs:
strategy:
fail-fast: false # Don't cancel all jobs if one fails.
matrix:
# This is the full set of versions we support on MacOS.
version: [ "2.7", "3.0", "3.1", "3.2" ]
include:
# Test both FFI and Native implementations on the highest and lowest
# Ruby versions for CRuby, but only on Bazel 5.x.
# Quote versions numbers otherwise 3.0 will render as 3
- { version: "2.7", ffi: NATIVE }
- { version: "2.7", ffi: FFI }
- { version: "3.0" }
- { version: "3.1" }
- { version: "3.2", ffi: NATIVE }
- { version: "3.2", ffi: FFI }

name: MacOS Ruby ${{ matrix.version }}
name: MacOS Ruby ${{ matrix.version }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }}
runs-on: macos-12
steps:
- name: Checkout pending changes
Expand All @@ -102,23 +113,26 @@ jobs:
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: ruby_macos/${{ matrix.version }}
bazel: test //ruby/... --test_env=KOKORO_RUBY_VERSION=${{ matrix.version }}
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' || '' }}
mkruskal-google marked this conversation as resolved.
Show resolved Hide resolved

test_ruby_gems:
strategy:
fail-fast: false
matrix:
include:
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1}
# Test both FFI and Native implementations on the highest and lowest
# Ruby versions for CRuby and JRuby, but only on Bazel 5.x.
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1, ffi: NATIVE }
- { name: Ruby 2.7, ruby: ruby-2.7.0, bazel: 5.1.1, ffi: FFI }
- { name: Ruby 3.0, ruby: ruby-3.0.2, bazel: 5.1.1}
- { name: Ruby 3.1, ruby: ruby-3.1.0, bazel: 5.1.1}
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1}
- { name: JRuby 9.2, ruby: jruby-9.2.20.1, bazel: 5.1.1}
- { name: JRuby 9.3, ruby: jruby-9.3.10.0, bazel: 5.1.1}
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1}
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1, ffi: NATIVE }
- { name: Ruby 3.2, ruby: ruby-3.2.0, bazel: 5.1.1, ffi: FFI }
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1, ffi: NATIVE }
- { name: JRuby 9.4, ruby: jruby-9.4.3.0, bazel: 5.1.1, ffi: FFI }
- { name: Ruby 2.7 (Bazel6), ruby: ruby-2.7.0, bazel: 6.0.0}
- { name: JRuby 9.4 (Bazel6), ruby: jruby-9.4.3.0, bazel: 6.0.0}
name: Install ${{ matrix.name }}
name: Install ${{ matrix.name }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }}
runs-on: ubuntu-latest
steps:
- name: Checkout pending changes
Expand All @@ -134,8 +148,9 @@ jobs:
bash: >
bazel --version;
ruby --version;
bazel build //ruby:release //:protoc $BAZEL_FLAGS;
bazel build //ruby:release //:protoc ${{ matrix.ffi == 'FFI' && '--//ruby:ffi=enabled' || '' }} $BAZEL_FLAGS;
mkruskal-google marked this conversation as resolved.
Show resolved Hide resolved
gem install bazel-bin/ruby/google-protobuf-*;
bazel-bin/protoc --proto_path=src --proto_path=ruby/tests --proto_path=ruby --ruby_out=ruby tests/test_import_proto2.proto;
bazel-bin/protoc --proto_path=src --proto_path=ruby/tests --proto_path=ruby --ruby_out=ruby tests/basic_test.proto;
ruby ruby/tests/basic.rb
${{ matrix.ffi == 'FFI' && 'PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI' || '' }} ruby ruby/tests/basic.rb;
${{ matrix.ffi == 'FFI' && 'PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI' || '' }} ruby ruby/tests/implementation.rb
6 changes: 4 additions & 2 deletions conformance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports_files([
"failure_list_python_cpp.txt",
"failure_list_ruby.txt",
"failure_list_jruby.txt",
"failure_list_jruby_ffi.txt",
"text_format_failure_list_cpp.txt",
"text_format_failure_list_csharp.txt",
"text_format_failure_list_java.txt",
Expand All @@ -34,6 +35,7 @@ exports_files([
"text_format_failure_list_python_cpp.txt",
"text_format_failure_list_ruby.txt",
"text_format_failure_list_jruby.txt",
"text_format_failure_list_jruby_ffi.txt",
])

cc_proto_library(
Expand Down Expand Up @@ -326,12 +328,12 @@ ruby_binary(
name = "conformance_ruby",
testonly = True,
srcs = ["conformance_ruby.rb"],
visibility = ["//ruby:__subpackages__"],
deps = [
":conformance_ruby_proto",
"//:test_messages_proto2_ruby_proto",
"//:test_messages_proto3_ruby_proto",
"//:test_messages_proto3_ruby_proto",
],
visibility = ["//ruby:__subpackages__"],
)

################################################################################
Expand Down
2 changes: 2 additions & 0 deletions conformance/failure_list_jruby_ffi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput
4 changes: 2 additions & 2 deletions protobuf_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def protobuf_deps():
_github_archive(
name = "rules_ruby",
repo = "https://github.com/protocolbuffers/rules_ruby",
commit = "8fca842a3006c3d637114aba4f6bf9695bb3a432",
sha256 = "2619f9a23cee6f6a198d9ef284b6f6cbc901545ee9a9aac9ffa6b83dbf17cf0c",
commit = "b7f3e9756f3c45527be27bc38840d5a1ba690436",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protocolbuffers/rules_ruby@b7f3e97 shows

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

It seems this commit is not part of the main branch is has been deleted

sha256 = "347927fd8de6132099fcdc58e8f7eab7bde4eb2fd424546b9cd4f1c6f8f8bad8",
)

if not native.existing_rule("rules_jvm_external"):
Expand Down
8 changes: 7 additions & 1 deletion ruby/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ protobuf-jruby.iml
target/
pkg/
tmp/
tests/google/
tests/google/
ext/google/protobuf_c/third_party/utf8_range/utf8_range.h
ext/google/protobuf_c/third_party/utf8_range/range2-sse.c
ext/google/protobuf_c/third_party/utf8_range/range2-neon.c
ext/google/protobuf_c/third_party/utf8_range/naive.c
ext/google/protobuf_c/third_party/utf8_range/LICENSE
lib/google/protobuf/*_pb.rb
Loading
Loading