mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1791851 - Add documentation for using uniffi on desktop r=bdk DONTBUILD
Differential Revision: https://phabricator.services.mozilla.com/D162174
This commit is contained in:
parent
a726096176
commit
7c1951aff7
@ -38,17 +38,33 @@ your project:
|
||||
|
||||
## Creating new bindings with UniFFI
|
||||
|
||||
You can see an example of this feature in use: [when application-services swapped the tabs js sync engine with rust](https://bugzilla.mozilla.org/show_bug.cgi?id=1791851)
|
||||
|
||||
Here's how you can create a new set of bindings using UniFFI:
|
||||
- UniFFI your crate (if it isn't already):
|
||||
|
||||
1. UniFFI your crate (if it isn't already):
|
||||
- [Create a UDL file to describe your interface](https://mozilla.github.io/uniffi-rs/udl_file_spec.html)
|
||||
- [Set up your Rust crate to generate scaffolding](https://mozilla.github.io/uniffi-rs/tutorial/Rust_scaffolding.html)
|
||||
- Add your crate as a Firefox dependency (if it isn't already)
|
||||
- If the code will exist in the mozilla-central repo:
|
||||
2. Add your crate as a Firefox dependency (if it isn't already)
|
||||
- **If the code will exist in the mozilla-central repo:**
|
||||
- Create a new directory for the Rust crate
|
||||
- Edit `toolkit/library/rust/shared/Cargo.toml` and add a dependency to your library path
|
||||
- If the code exists in an external repo:
|
||||
- **If the code exists in an external repo:**
|
||||
- Edit `toolkit/library/rust/shared/Cargo.toml` and add a dependency to your library URL
|
||||
- Run `mach vendor rust` to vendor in your Rust code
|
||||
- Generate bindings code for your crate
|
||||
- TODO: create a system for this and document it here. I think we can do something like we do for the test
|
||||
fixtures, where devs don't need to touch that many moz.build files.
|
||||
3. Generate bindings code for your crate
|
||||
- Add the path of your UDL (that you made in step 1) in `toolkit/components/uniffi-bindgen-gecko-js/mach_commands.py`
|
||||
- Run `./mach uniffi generate`
|
||||
- add your newly generated `Rust{udl-name}.jsm` file to `toolkit/components/uniffi-bindgen-gecko-js/components/moz.build`
|
||||
- Then simply import your `jsm` module to the file you want to use it in and start using your APIs!
|
||||
|
||||
Example from tabs module:
|
||||
|
||||
``` js
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
...
|
||||
TabsStore: "resource://gre/modules/RustTabs.jsm",
|
||||
});
|
||||
...
|
||||
this._rustStore = await lazy.TabsStore.init(path);
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user