-
Notifications
You must be signed in to change notification settings - Fork 234
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
RFC: Make it easier to call the C-ABI from Rust #2331
Comments
Ben asks:
Currently, the implementation of Futures are tightly coupled with the lifting arguments and lowering of return values. For example:
generates:
If we could have an intermediate function that did the lifting and lowering, we could use other Futures implementations.
For example, now we could generate a low level FFI which in turn uses (say)
Another example:
It doesn't have to be limited to JS: this may be a good way of improving Ruby support, which doesn't seem to support Futures yet. |
IIUC, this could be summarized as allowing a second layer of scaffolding specific to a bindings generator. Seems like good idea to me, although I can't totally picture how it's going to work out. One question I had was about linking: IIUC, you would build the normal library with the UniFFI scaffolding, then build a second library with an extra layer of scaffolding, then link to both? It seems like it would work to me, but it is introducing an extra layer of complexity. For example, should this extra layer also have checksum/version checks? My other big-picture question is if any set of bindings would want to share some of this extra scaffolding? That's kind of what I was trying to do with the
This seems like a no-brainer to me, I can't see any downside to it. Can an
Would this mean something like generating Rust code that uses the |
I was hoping that this could be made easier by the binding generator pass in a trait which changed the behaviour of the scaffolding generation. i.e. the second layer of generated at the same time as the first, but I hadn't worked out the mechanics of how this works.
Yes! I'd hope that the second layer of scaffolding would be relatively straightforward, but paramterizable: though at the moment, I think I'll be able to use type aliasing to most of the work, and switch out a tiny runtime between I'm expecting it to get a bit harder once I start adding callback interfaces. |
Brilliant! Ah yes, I think you're right about the This should be a straightforward change but for one thing: Other than that I think it's a single file change. |
The issue I'd like to address here is to make calling the generated C ABI from Rust easier.
Context
Currently, all uniffi bindings works by:
For languages that can't represent structures directly in C, the bindings need to get to C before calling across into Rust.
For example, the uniffi-bindgen for both gecko-js and React Native, need to generate C++ to call into Rust via the C-ABI.
But:
What about language pairs where compiling C is not feasible?
Intent
The issue I'd like to address here is to make calling this C ABI from Rust easier.
It should be additive to the existing generated Rust.
This will enable writing uniffi adapters for new languages or contexts: e.g. node, via napi.rs; tauri; browser WASM via wasm-bindgen.
It may also open up the way to easier to maintain bindgens for languages with specialized Rust bindings crates (e.g. Ruby, Python, Dart, etc).
To ground this however, my current focus is on WASM, re-using the Typescript bindings generated by
uniffi-bindgen-react-native
. Whether or not we usewasm-bindgen
is an implementation detail for the purpose of this issue.I have been thinking of this proposal as "Rust as a foreign language", though this is not quite accurate: it is only the low-level ABI this proposal is targeting.
Task list
Right now, in order of urgency I think the list of issues that are needed is:
pub
, so it can be accessed from Rust as easily as it can be accessed by C.gen_ffi_function
to add a low-level async caller function to the C-ABIFuture
.extern "C"
code.log!
) to add annotations and code.For WASM specifically:
For now, I think I can get started with just the first.
With the exception of the last one, I don't think any individual issue is a large amount of work.
I don't think any of this is on Mozilla's roadmap, so would be happy to do the engineering.
Next steps?
Call to action
The text was updated successfully, but these errors were encountered: