Skip to content

Make UniFFI Config parsing compatible with settings for other languages - #197

Open
markus2610 wants to merge 10 commits into
gobley:mainfrom
markus2610:main
Open

Make UniFFI Config parsing compatible with settings for other languages#197
markus2610 wants to merge 10 commits into
gobley:mainfrom
markus2610:main

Conversation

@markus2610

@markus2610 markus2610 commented Aug 22, 2025

Copy link
Copy Markdown

Changes

The configuration format used in the upstream UniFFI repository stores settings for each language under a dedicated table, e.g., [bindings.<language name>]. However, the bindgen in Gobley tries to read those settings from the root, making it hard to use it with UniFFI bindings of other languages. This PR is to make Gobley read the settings from [bindings.kotlin], making it align with UniFFI bindgens for other languages.

  • Made the bindgen read the settings from the [bindings.kotlin] table.
  • Made the config merge task on the Gradle side reflect the same changes.
  • Changed the default value of Config::kotlin_multiplatform to true.
  • Added a new command-line argument, --no-multiplatform, which makes the bindgen override the
    value of Config::kotlin_multiplatform in the config file and consider it as false.
  • Made the bindgen generate bindings for all Kotlin targets if the given target list is empty.

Testing

  • Inserted [bindgen.kotlin] to all uniffi.toml files in the unit test projects.

Support both [bindings.kotlin] nested format and flat format for backward
compatibility in config parsing. Add default kotlin_targets when
kotlin_multiplatform is enabled but no targets specified.
Features:
- Add --kmp CLI flag to force Kotlin Multiplatform generation
- Support both nested [bindings.kotlin] and flat config formats
- Auto-populate default targets when KMP enabled without explicit targets
- CLI flag overrides config file settings for flexibility

Tests added:
- test_config_parsing_nested_format: Validates [bindings.kotlin] parsing
- test_config_parsing_flat_format: Validates flat format compatibility
- test_kmp_flag_overrides_config: Ensures CLI flag takes precedence
- test_kotlin_targets_defaults: Verifies auto-population of targets
- test_explicit_targets_preserved: Respects user-specified targets
@paxbun

paxbun commented Aug 23, 2025

Copy link
Copy Markdown
Member

Hi! Thanks for the contribution. Are you trying to add KMP support to your UniFFI project that already has bindings to other languages (e.g. Python)?

@paxbun paxbun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be working on these changes if you don't mind. Thanks for the contribution!

Comment thread crates/gobley-uniffi-bindgen/src/main.rs Outdated
Comment thread crates/gobley-uniffi-bindgen/src/lib.rs Outdated
Comment thread crates/gobley-uniffi-bindgen/src/lib.rs Outdated
Comment thread crates/gobley-uniffi-bindgen/src/gen_kotlin_multiplatform/mod.rs
@paxbun paxbun added this to the 0.3.5 milestone Aug 24, 2025
@paxbun paxbun modified the milestones: 0.3.5, 0.4.0 Aug 24, 2025
@paxbun paxbun changed the title Fix Kotlin Multiplatform config parsing and default target generation Make Config parsing compatible with settings for other languages Aug 24, 2025
@paxbun
paxbun requested a review from SalvatoreT August 24, 2025 09:37
@paxbun paxbun changed the title Make Config parsing compatible with settings for other languages Make UniFFI Config parsing compatible with settings for other languages Aug 24, 2025
@paxbun paxbun added uniffi Related to UniFFI, the bindgen, or the bindings enhancement New feature or request labels Aug 24, 2025
@paxbun
paxbun enabled auto-merge (squash) August 24, 2025 09:49
@paxbun paxbun added breaking Introduces huge breaking changes bug Something isn't working / This PR fixes it labels Aug 24, 2025
@paxbun
paxbun disabled auto-merge August 24, 2025 10:31
@SalvatoreT

Copy link
Copy Markdown
Contributor

@markus2610, have you had a chance to try this branch with your project to verify it solves the namespace issue?

@markus2610

Copy link
Copy Markdown
Author

@SalvatoreT Which branch?

@markus2610

Copy link
Copy Markdown
Author

@paxbun No only for IOS and Android

@SalvatoreT

Copy link
Copy Markdown
Contributor

@SalvatoreT Which branch?

your main branch - the one you're using for this pull request

Have you tried a local build of your main branch and seen it resolve the issue completely?

@markus2610

Copy link
Copy Markdown
Author

@SalvatoreT Yes, I use it in my project and it works. I have a shell script that I use to generate my bindings.

@SalvatoreT
SalvatoreT removed their request for review March 26, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Introduces huge breaking changes bug Something isn't working / This PR fixes it enhancement New feature or request uniffi Related to UniFFI, the bindgen, or the bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants