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

Use codegen for FFI / style builder #617

Open
nicoburns opened this issue Feb 13, 2024 · 2 comments
Open

Use codegen for FFI / style builder #617

nicoburns opened this issue Feb 13, 2024 · 2 comments
Labels
code quality Make the code cleaner or prettier.

Comments

@nicoburns
Copy link
Collaborator

nicoburns commented Feb 13, 2024

What problem does this solve or what need does it fill?

Bindings to languages other than Rust require a lot of repetitive type/function definitions (repeated across each set of bindings, and again in the core library).

What solution would you like?

A custom codegen solution similar to Yoga's enums.py (but also covering style getters/setters) that could be used to generate (parts of) each FFI implementation, and also for implementing a style builder in the Rust API (and maybe also for definining the core implementations of some style enums.

What alternative(s) have you considered?

  • Custom code for each FFI binding. This will be hard to maintain / limit the number of language bindings we can support.
  • Using custom derives / macros to generate code. This was initially my preferred approach but doesn't seem viable in practice due to differences in the API required by the specifics of each language (e.g. how one binds to C may be different to how ones binds to JS/WASM)
  • Generic FFI libraries like uniffi. These seem to suffer from similar limitations to the macro approaches, and also have a limited set of languages they support, and are opinionated about how to bind to the language. They may be more viable in future.

Other solutions to solve and/or work around the problem presented.

Additional context


Note: This is not blocking for releasing bindings but will likely be wanted before adding more than one or two sets of bindings.

@nicoburns nicoburns added the code quality Make the code cleaner or prettier. label Feb 13, 2024
@waywardmonkeys
Copy link
Contributor

Is it worth looking at diplomat (used by icu4x)? (I don't know the answer.)

@nicoburns
Copy link
Collaborator Author

nicoburns commented Feb 26, 2024

I think I looked at diplomat, but I'll take another look on your recommendation. So far every tool I've looked at has lacked I'm both language support (they all support a different subset of languages) and flexibility (making it hard to support different approaches in different languages). A lot of them also use a proprietary DSL which isn't always super clear for those unfamiliar (which will be most people as such tools are not widely used).

My feeling is that a small, well-documented 400-500 line script that does simple string-based code generation powered off a JSON file or similar would be easier to maintain and for newcomers to understand. Especially if the generated code is checked into source control and can be easily inspected and played with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Make the code cleaner or prettier.
Projects
None yet
Development

No branches or pull requests

2 participants