-
Notifications
You must be signed in to change notification settings - Fork 183
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
Separate functional from ergonomic API (add cbindgen) #398
Comments
I think the best first step here is to try to get an ICU4X component like PluralRules to compile with cbindgen. It's not hard to get started. I annotated the #[no_mangle]
pub extern fn try_new<'d, D: DataProvider<'d>>(
langid: LanguageIdentifier,
data_provider: &D,
type_: PluralRuleType,
) -> Result<Self, PluralRulesError> And the PluralRules struct with #[repr(C)]
pub struct PluralRules Then I can run
I guess that's a start! I'm not really sure where to go next. In particular, I don't know how to fix the errors on top:
I annotated Once we can get some sort of PluralRules compiling to FFI in ICU4X, the next step will be to work on how the FFI relates to the data provider. I think, at least, we should add a new API that builds a PluralRules directly from data structs and other elementary components, rather than abstract traits/interfaces. |
Do we want cbindgen or cxx? |
I think it needs to be all the way down. What we need to do is one of:
cxx could work, but it has a different model. I figured cbindgen would be useful since you need to do a lot of that work for wasm anyway. Worth trying cxx! |
For generics we'd have to do some kind of dynamic dispatch instead, sadly. |
FWIW. We can not expect that we can just run either The API for the code that you expect to be usable over FFI needs to be designed with FFI in mind. IIUC, Some types such as |
Clearly the FFI layer needs to be written in a way to make it C- and WASM-compatible, with simpler types. In wrapper_layer.md, I proposed making the Rust API wrap over the FFI API. I'm wondering whether this is the right approach, or whether the FFI API should be a "standalone" wrapper over the Rust API, more like in ICU4C. I would prefer making the Rust API wrap FFI, but I don't want to do that if it incurs a significant cost (in safety, performance, maintenance, etc). |
So the typical way to do this is to have intermediate FFI structs that contain the same data and are cheaply convertible to the Rust format. "Rust API wrap FFI" is rarely a good idea since you lose out on all of the benefits of Rust enums/etc. |
We should schedule a deep-dive session where we figure this out, similar to how we did with WASM. |
I might also do some experiments with pluralrules |
FWIW, i've filed mozilla/cbindgen#646, which will eventually let us directly pass TinyStr over FFI, until then we'll have to make a shim type. |
cbindgen (master) is now compatible, opened zbraniecki/tinystr#30 for making tinystr work |
Got some experiments up at #453 |
Any idea when this will be started/implemented? |
We have a rough plan for this and I hope to start implementing it soonish. It should still be a few months out though. |
Currently blocked on mozilla/cbindgen#665 |
I think the design work here was mostly resolved in #552 (and this issue can be closed, or kept around as an FFI tracking issue) |
No description provided.
The text was updated successfully, but these errors were encountered: