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

Add support for FFI while leaving legacy implementations intact #11483

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 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
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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ vendor/
/bazel-*

# ruby test output
ruby/lib/google/protobuf/any_pb.rb
ruby/lib/google/protobuf/api_pb.rb
ruby/lib/google/protobuf/descriptor_pb.rb
ruby/lib/google/protobuf/duration_pb.rb
ruby/lib/google/protobuf/empty_pb.rb
ruby/lib/google/protobuf/field_mask_pb.rb
ruby/lib/google/protobuf/source_context_pb.rb
ruby/lib/google/protobuf/struct_pb.rb
ruby/lib/google/protobuf/timestamp_pb.rb
ruby/lib/google/protobuf/type_pb.rb
ruby/lib/google/protobuf/wrappers_pb.rb
ruby/tests/basic_test_pb.rb
ruby/tests/basic_test_proto2_pb.rb
ruby/tests/generated_code_pb.rb
Expand Down
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",
sha256 = "347927fd8de6132099fcdc58e8f7eab7bde4eb2fd424546b9cd4f1c6f8f8bad8",
)

if not native.existing_rule("rules_jvm_external"):
Expand Down
7 changes: 6 additions & 1 deletion ruby/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ protobuf-jruby.iml
target/
pkg/
tmp/
tests/google/
tests/google/
/ext/google/protobuf_c/utf8_range.h
/ext/google/protobuf_c/range2-sse.c
/ext/google/protobuf_c/range2-neon.c
/ext/google/protobuf_c/naive.c
/ext/google/x86_64-darwin/
135 changes: 111 additions & 24 deletions ruby/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# See also code generation logic under /src/google/protobuf/compiler/ruby.

load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
Expand All @@ -13,12 +15,67 @@ load("//:protobuf_version.bzl", "PROTOBUF_RUBY_VERSION")
# Ruby Runtime
################################################################################

string_flag(
name = "ffi",
build_setting_default = "disabled",
values = [
"enabled",
"disabled",
],
)

config_setting(
name = "ffi_enabled",
JasonLunn marked this conversation as resolved.
Show resolved Hide resolved
flag_values = {
":ffi": "enabled",
},
)

config_setting(
name = "ffi_disabled",
flag_values = {
":ffi": "disabled",
},
)

selects.config_setting_group(
name = "jruby_ffi",
match_all = [
":ffi_enabled",
"@rules_ruby//ruby/runtime:config_jruby",
],
)

selects.config_setting_group(
name = "jruby_native",
match_all = [
":ffi_disabled",
"@rules_ruby//ruby/runtime:config_jruby",
],
)

selects.config_setting_group(
name = "ruby_ffi",
match_all = [
":ffi_enabled",
"@rules_ruby//ruby/runtime:config_ruby",
],
)

selects.config_setting_group(
name = "ruby_native",
match_all = [
":ffi_disabled",
"@rules_ruby//ruby/runtime:config_ruby",
],
)

ruby_library(
name = "protobuf",
deps = ["//ruby/lib/google:protobuf_lib"],
visibility = [
"//visibility:public",
],
deps = ["//ruby/lib/google:protobuf_lib"],
)

# Note: these can be greatly simplified using inline_sh_binary in Bazel 6,
Expand All @@ -27,12 +84,12 @@ ruby_library(
genrule(
name = "jruby_release",
srcs = [
"//ruby/lib/google:copy_jar",
"//ruby/lib/google:dist_files",
"//:well_known_ruby_protos",
"google-protobuf.gemspec",
"//ruby/lib/google:copy_jar",
"//ruby/lib/google:dist_files",
"//:well_known_ruby_protos",
"google-protobuf.gemspec",
],
outs = ["google-protobuf-"+PROTOBUF_RUBY_VERSION+"-java.gem"],
outs = ["google-protobuf-" + PROTOBUF_RUBY_VERSION + "-java.gem"],
cmd = """
set -eux
mkdir tmp
Expand All @@ -59,14 +116,14 @@ genrule(
genrule(
name = "ruby_release",
srcs = [
"@utf8_range//:utf8_range_srcs",
"@utf8_range//:LICENSE",
"//:well_known_ruby_protos",
"//ruby/ext/google/protobuf_c:dist_files",
"//ruby/lib/google:dist_files",
"google-protobuf.gemspec",
"@utf8_range//:utf8_range_srcs",
"@utf8_range//:LICENSE",
"//:well_known_ruby_protos",
"//ruby/ext/google/protobuf_c:dist_files",
"//ruby/lib/google:dist_files",
"google-protobuf.gemspec",
],
outs = ["google-protobuf-"+PROTOBUF_RUBY_VERSION+".gem"],
outs = ["google-protobuf-" + PROTOBUF_RUBY_VERSION + ".gem"],
cmd = """
set -eux
mkdir tmp
Expand Down Expand Up @@ -102,7 +159,6 @@ filegroup(
tags = ["manual"],
)


################################################################################
# Tests
################################################################################
Expand All @@ -111,34 +167,65 @@ filegroup(
internal_ruby_proto_library(
name = "test_ruby_protos",
srcs = ["//ruby/tests:test_protos"],
deps = ["//:well_known_ruby_protos"],
includes = [".", "src", "ruby/tests"],
includes = [
".",
"ruby/tests",
"src",
],
visibility = [
"//ruby:__subpackages__",
],
deps = ["//:well_known_ruby_protos"],
)


conformance_test(
name = "conformance_test",
failure_list = "//conformance:failure_list_ruby.txt",
target_compatible_with = select({
":ruby_native": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
testee = "//conformance:conformance_ruby",
text_format_failure_list = "//conformance:text_format_failure_list_ruby.txt",
)

conformance_test(
name = "conformance_test_ffi",
env = {
"PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION": "ffi",
},
failure_list = "//conformance:failure_list_ruby.txt",
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_ruby": [],
":ruby_ffi": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
testee = "//conformance:conformance_ruby",
text_format_failure_list = "//conformance:text_format_failure_list_ruby.txt",
)

conformance_test(
name = "conformance_test_jruby",
failure_list = "//conformance:failure_list_jruby.txt",
target_compatible_with = select({
":jruby_native": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
testee = "//conformance:conformance_ruby",
text_format_failure_list = "//conformance:text_format_failure_list_jruby.txt",
)

conformance_test(
name = "conformance_test_jruby_ffi",
env = {
"PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION": "ffi",
},
failure_list = "//conformance:failure_list_jruby_ffi.txt",
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_jruby": [],
":jruby_ffi": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
testee = "//conformance:conformance_ruby",
text_format_failure_list = "//conformance:text_format_failure_list_jruby.txt",
)

################################################################################
Expand All @@ -148,15 +235,15 @@ conformance_test(
pkg_files(
name = "dist_files",
srcs = [
"//ruby/ext/google/protobuf_c:dist_files",
"//ruby/lib/google:dist_files",
"//ruby/src/main/java:dist_files",
"//ruby/tests:dist_files",
".gitignore",
"BUILD.bazel",
"Gemfile",
"Rakefile",
"README.md",
"Rakefile",
"//ruby/ext/google/protobuf_c:dist_files",
"//ruby/lib/google:dist_files",
"//ruby/src/main/java:dist_files",
"//ruby/tests:dist_files",
],
strip_prefix = strip_prefix.from_root(""),
visibility = ["//pkg:__pkg__"],
Expand Down
Loading
Loading