chinedufn / swift-bridge

swift-bridge facilitates Rust and Swift interop.
https://chinedufn.github.io/swift-bridge
Apache License 2.0
842 stars 62 forks source link

SPM setup for rust library #280

Open qiweiii opened 4 months ago

qiweiii commented 4 months ago

Problem

#[swift_bridge::bridge]
mod ffi {
    // Export opaque Rust types, functions and methods for Swift to use.
    extern "Rust" {
        type RingContext;
        type IetfProof;
        type Input;
        type Output;
        type Public;
        type RingProof;
        type Secret;

        type IetfVrfSignature;

        fn ring_context() -> &'static RingContext;

        fn vrf_input_point(vrf_input_data: &[u8]) -> Input;
    }
}

I have this setup for a swift package, I want to access a generated function in swift, and have the following error:

image

It's probably sth wrong with my setup, and I didn't follow https://chinedufn.github.io/swift-bridge/building/swift-packages/index.html as my pacakge later will also need to be run on linux, so I followed https://chinedufn.github.io/swift-bridge/building/swiftc-and-cargo/index.html and tried to make it work in spm

I also tried to include generated folder in sources, but it will give lots of errors like error: cannot find '__swift_bridge__$xxx$xxxx' in scope from generated .swift files

Please check if this scenario can be solved, thanks in advance

Steps