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

Handling varying APIs by OS #51

Open
coolbluewater opened this issue Feb 25, 2024 · 1 comment
Open

Handling varying APIs by OS #51

coolbluewater opened this issue Feb 25, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@coolbluewater
Copy link

coolbluewater commented Feb 25, 2024

Hi, thanks for this tool! I was building something similar and found this.

I'm moving from cbindgen and simple xcframeworks to using uniffi and cargo-swift to generate the swift package.

My Rust crate has some differences between the API's exposed for iOS and macOS.
This works fine with xcframeworks, since each target platform has its own set of headers and library within the xcframework.

The generated Greeter swift package for the hello-world example only a single header file, but does contain an xcframework.
This code in package.rs seems to generate bindings for the first provided architecture only:

        let archs = targets
            .first()
            .ok_or("Could not generate UniFFI bindings: No target platform selected!")?
            .architectures();
        let arch = archs.first();
        let lib_path: Utf8PathBuf = format!("{target}/{arch}/{mode}/{lib_file}").into();

Question: Is this due to a limitation of swift packages, or can the generated swift package have multiple swift files, with conditional expressions to indicate which target platform each file is for?

Update: I found this document which indicates that conditional target dependencies are supported by swift packages.

In light of the above, could we please change cargo-swift to emit swift files with conditional dependencies per target os?

@coolbluewater coolbluewater changed the title Handling varying APIs based on platform Handling varying APIs by OS Feb 25, 2024
@antoniusnaumann
Copy link
Owner

Switching features dependent on target os would be a very useful feature indeed!

I'll look into it, but it will take a while until I can work on this myself.

@antoniusnaumann antoniusnaumann added help wanted Extra attention is needed enhancement New feature or request labels Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants