Closed chinedufn closed 6 months ago
It is not currently possible to bridge Option<OpaqueSwiftType> in an extern "Rust" function.
Option<OpaqueSwiftType>
extern "Rust"
For example, the following signature does not compile:
#[swift_bridge::bridge] mod ffi { extern "Rust" { fn some_function(arg: Option<SwiftType>) -> Option<SwiftType>; } extern "Swift" { type SwiftType; } }
Review the documentation for supporting a new signature https://github.com/chinedufn/swift-bridge/blob/master/book/src/contributing/adding-support-for-a-signature/README.md
Add fn rust_reflect_option_swift_type(arg: Option<OptTestOpaqueSwiftType>) -> Option<OptTestOpaqueSwiftType> to the Option integration tests https://github.com/chinedufn/swift-bridge/blob/58f4a40f96bb050607c746376422ab3c62e0e771/crates/swift-integration-tests/src/option.rs#L1-L144
fn rust_reflect_option_swift_type(arg: Option<OptTestOpaqueSwiftType>) -> Option<OptTestOpaqueSwiftType>
OptTestOpaqueSwiftType
Add a test that calls rust_reflect_option_swift_type
rust_reflect_option_swift_type
Add a codegen test for a Rust fn accepting an Option<SwiftType> arg to option_codegen_tests.rs
Option<SwiftType>
option_codegen_tests.rs
Add a codegen test for a Rust fn returning an Option<SwiftType> in option_codegen_tests.rs
opaque_swift_type_codegen_tests.rs
Get tests passing
It is not currently possible to bridge
Option<OpaqueSwiftType>
in anextern "Rust"
function.For example, the following signature does not compile:
Potential Solution
Review the documentation for supporting a new signature https://github.com/chinedufn/swift-bridge/blob/master/book/src/contributing/adding-support-for-a-signature/README.md
Add
fn rust_reflect_option_swift_type(arg: Option<OptTestOpaqueSwiftType>) -> Option<OptTestOpaqueSwiftType>
to the Option integration tests https://github.com/chinedufn/swift-bridge/blob/58f4a40f96bb050607c746376422ab3c62e0e771/crates/swift-integration-tests/src/option.rs#L1-L144OptTestOpaqueSwiftType
in here https://github.com/chinedufn/swift-bridge/blob/58f4a40f96bb050607c746376422ab3c62e0e771/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunner/Option.swift#L1-L68Add a test that calls
rust_reflect_option_swift_type
Add a codegen test for a Rust fn accepting an
Option<SwiftType>
arg tooption_codegen_tests.rs
Add a codegen test for a Rust fn returning an
Option<SwiftType>
inoption_codegen_tests.rs
opaque_swift_type_codegen_tests.rs
: https://github.com/chinedufn/swift-bridge/blob/54b9c09337701dd7580010d1d5ef6527b855ee98/crates/swift-bridge-ir/src/codegen/codegen_tests/extern_swift_function_opaque_swift_type_return_codegen_tests.rs#L5-L61Get tests passing