DioxusLabs / taffy

A high performance rust-powered UI layout library
https://docs.rs/taffy
Other
2.06k stars 102 forks source link

Use codegen for FFI / style builder #617

Open nicoburns opened 7 months ago

nicoburns commented 7 months ago

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?

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.

waywardmonkeys commented 6 months ago

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

nicoburns commented 6 months ago

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.