-
Notifications
You must be signed in to change notification settings - Fork 62
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
Swift Vec<primitive>
Return Type and Function Argument
#229
Conversation
This exchanges raw pointers when: - send a Vec from Rust to Swift - receiving a Vec from Swift to Rust In all other cases the behavior is the same as before.
This adds test for both the argument and the return value variant.
Can't actually get these to run: The integration tests seem to already by broken. They fail with something to the tune of > field has incomplete type 'struct __swift_bridge__$tuple$I32ResultTestOpaqueRustTypeString'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the very detailed PR body.
This looks great to me. Left some very minor feedback then after that this is good to go.
// | ||
// String.swift | ||
// SwiftRustIntegrationTestRunner | ||
// | ||
// Created by Frankie Nwafili on 2/18/22. | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete this comment. Xcode typically auto generates them but we don't really need them
} | ||
|
||
fn expected_c_header() -> ExpectedCHeader { | ||
ExpectedCHeader::ContainsAfterTrim("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will pass for all strings string all strings contain ""
.
You can use ExpectedCHeader::ExactAfterTrim("")
here instead.
|
||
import Foundation | ||
|
||
func send_bytes(vec _: RustVec<UInt8>) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets call these swift_arg_vec_u8
and swift_return_vec_u8
.
This way we can more easily distinguish these from other FFI functions.
|
||
import Foundation | ||
|
||
func send_bytes(vec _: RustVec<UInt8>) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this function assert that the bytes are 1, 2, 3, 4, 5
} | ||
} | ||
|
||
fn run_vec_tests() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
} | ||
|
||
fn expected_c_header() -> ExpectedCHeader { | ||
ExpectedCHeader::ContainsAfterTrim("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::ExactAfterTrim
@@ -25,6 +25,28 @@ mod ffi { | |||
arg: Vec<TransparentEnumInsideVecT>, | |||
) -> Vec<TransparentEnumInsideVecT>; | |||
} | |||
|
|||
extern "Rust" { | |||
fn run_vec_tests(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to call this on the Swift side in VecTests.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like:
/// Verify that Rust can pass `RustVec`s to and receive `RustVec`s from Swift.
func testRustCallsSwiftRustVecFunctions() {
run_vec_tests()
}
} else { | ||
"UnsafeMutableRawPointer".to_string() | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, forgot about this one.
Alright, I think I addressed all of the comments, let me know how I did 👍 |
Thanks! |
A UI test is failing but I believe it's fixed in #230 so I'll merge this |
Fixes #228.
This enables the following use case:
This is chiefly intended for easy bidirectional byte exchanges but should work for all primitive types, at least the ones I tested with.
The codegen tests pass but I was unable to get the integration tests to run: They also fail for me on
master
and I don't understand enough of how they work to properly debug them. The (very long) error messages ends with this, which seems to be the culprit:I attempted to add some integration tests for both directions anyway, but given that I'm operating 'blind' on that part I can't assure you whether these work or not.
I'm rather certain that there's still issues with my PR given that this is my first time dealing with this kind of interop work, so by all means do let me know how to address the current weaknesses/problems and I'll do my best to resolve them.