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

Bundle all headers and swift files for multi-crate UniFFI setups #54

Merged
merged 4 commits into from
Apr 9, 2024

Conversation

MarcelStruckWO
Copy link
Contributor

In workspaces where UniFFI types are declared in multiple separate crates, UniFFI bindgen generates a set of Swift files, headers and a header map for each Rust crate that declares UniFFI types.
Currently, only the files corresponding to the main crate (from where cargo swift was called) are added. This PR copies all the files to the resulting xcode project.

@antoniusnaumann
Copy link
Owner

Due to #53 being merged, the code for accessing the Swift config should be altered slightly. I think this is how we can do it:

for output in uniffi_outputs {
        let config = output.bindings.swift;
        let file_name = config.module_name();
        fs::copy(
            out_dir.join(format!("{file_name}.swift")),
            sources.join(format!("{file_name}.swift")),
        )?;

        fs::copy(
            out_dir.join(config.header_filename()),
            headers.join(config.header_filename()),
        )?;
        fs::copy(
            out_dir.join(config.modulemap_filename()),
            headers.join(config.modulemap_filename()),
        )?;
    }

Please update the code in bindings.rs accordingly for this PR to be merged.

Thank you for your contribution! :)

@MarcelStruckWO
Copy link
Contributor Author

Due to #53 being merged, the code for accessing the Swift config should be altered slightly. I think this is how we can do it:

for output in uniffi_outputs {
        let config = output.bindings.swift;
        let file_name = config.module_name();
        fs::copy(
            out_dir.join(format!("{file_name}.swift")),
            sources.join(format!("{file_name}.swift")),
        )?;

        fs::copy(
            out_dir.join(config.header_filename()),
            headers.join(config.header_filename()),
        )?;
        fs::copy(
            out_dir.join(config.modulemap_filename()),
            headers.join(config.modulemap_filename()),
        )?;
    }

Please update the code in bindings.rs accordingly for this PR to be merged.

Thank you for your contribution! :)

Unfortunately the swift property is crate-private in the bindings struct. :/

I guess we could just continue to use the old approach for generating the filenames, just with all the different crate names.

@antoniusnaumann
Copy link
Owner

Due to #53 being merged, the code for accessing the Swift config should be altered slightly. I think this is how we can do it:

for output in uniffi_outputs {
        let config = output.bindings.swift;
        let file_name = config.module_name();
        fs::copy(
            out_dir.join(format!("{file_name}.swift")),
            sources.join(format!("{file_name}.swift")),
        )?;

        fs::copy(
            out_dir.join(config.header_filename()),
            headers.join(config.header_filename()),
        )?;
        fs::copy(
            out_dir.join(config.modulemap_filename()),
            headers.join(config.modulemap_filename()),
        )?;
    }

Please update the code in bindings.rs accordingly for this PR to be merged.
Thank you for your contribution! :)

Unfortunately the swift property is crate-private in the bindings struct. :/

I guess we could just continue to use the old approach for generating the filenames, just with all the different crate names.

Ah, you are right. That was an oversight on my side.

Thanks providing an alternative solution!

@antoniusnaumann
Copy link
Owner

Thank you so much for creating an end-to-end test project for this feature as well. Great contribution!

@antoniusnaumann antoniusnaumann merged commit ae162f7 into antoniusnaumann:main Apr 9, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants