Open chinedufn opened 7 months ago
Check out the contributing guide https://chinedufn.github.io/swift-bridge/contributing/adding-support-for-a-signature/index.html
Here's a pull-request where we implemented support for Swift's Equatable
protocol via #[swift_bridge(Equatable)]
.
It should serve as a guide for implementing #[swift_bridge(Sendable)]
support.
https://github.com/chinedufn/swift-bridge/pull/139
unsafe impl Send for MySwiftType {}
and unsafe impl Sync for MySwiftType {}
would go here https://github.com/chinedufn/swift-bridge/blob/dd5bef56af28db4f1a1244d86115def6abede931/crates/swift-bridge-ir/src/codegen/generate_rust_tokens.rs#L236-L248
let impl_send_sync = if ty.attributes.sendable {
quote! {
unsafe impl Send for #ty_name {}
unsafe impl Sync for #ty_name {}
}
} else {
quote!{}
};
The Swift
XCode
test can call a Rust function that:
Example of an integration test:
Here's where SwiftBridgeCore.swift
is generated https://github.com/chinedufn/swift-bridge/blob/7e140ca5e6ec3f969c19001c844f98fe76bd787c/crates/swift-bridge-build/src/generate_core.rs#L21-L32
Right now when generating the Rust representation of a Swift type we create a non-Send and non-Sync type.
If the user knows that
SomeSwiftType
isSendable
then they should be able toSend + Sync
on the Rust side.Then it would generate Swift code like: