Add support for UniFFI JS bindings
Categories
(Toolkit :: UniFFI Bindings, enhancement, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox105 | --- | fixed |
People
(Reporter: bdk, Assigned: bdk)
References
Details
Attachments
(6 files, 3 obsolete files)
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review |
The UniFFI tool has been developed by several Mozilla teams to provide Swift, Kotlin, and Python bindings for Rust crates. Right now, it's mainly used for the mobile browsers.
It would be good to add support for JS bindings for FF desktop. We could then replace some of our hand-written FFI code including tab syncing and the webext-storage-bridge. It would also open the door to incorporating more Rust components into desktop, for example the application-services storage/sync components could potentially be shared by Desktop, iOS, and Fenix.
Assignee | ||
Comment 1•3 years ago
|
||
Currently supported:
- Toplevel functions
- Records
- Strings
- Primitives
- Sequence, Maps, and Optional
- Enums (both flat and complex)
- Errors (both flat and complex)
- Objects
Still Todo:
- CallbackInterfaces
- Custom and external types
- Datetime and TimeInterval
Assignee | ||
Comment 2•3 years ago
|
||
- Added
--enable-uniffi-fixtures
flag. When set, we will compile in
the UniFFI test fixtures into our shared Rust crate and eventually
intolibxul
. - Vendoring in the Rust crates needed for
uniffi-bindgen-gecko-js
- Updated
vendor_rust.py
now that there are new duplicate Rust crates.
Sinceuniffi-bindgen-gecko-js
is only used as a build-time tool, I
don't think this will result in wasted space in libxul, but it would
be good to reduce in any case. Here's what I can figure out about the
deps:- paste: Gecko is on an older version (0.1 vs 1.0). The version comes
from the rkv dependecy. - semver: Gecko is on an older version (0.9 vs 0.11). The version
comes from the packed_simd dependency, which depends on
rustc_version 0.2.3, which depends on semver 0.9 - semver-parser: Extra fallout from the semver issue
- toml: Gecko is on an older version (0.4 vs 0.4). The version comes
from the neqo-crypto dependency. - nom: Gecko is on an older version (5.x vs 7.x). There are several
dependencies at play here.
- paste: Gecko is on an older version (0.1 vs 1.0). The version comes
Depends on D144466
Assignee | ||
Comment 3•3 years ago
|
||
Added mach uniffi generate
which uses uniffi-bindgen-gecko-js
to
generate JS bindings. It's unfortunate that we need to check these files
in, but I couldn't figure out a way to auto-generate them as part of the
build process.
Adding #include "nsIContent.h"
to dom/base/nsINodeList.h. I think
that should have been present before, but things built okay because of
the way things got combined in the uniffied .cpp files. Adding these new
webIDL files bumped NodeListBinding.cpp
to a new uniffied .cpp file
which caused the build to fail.
Depends on D144467
Assignee | ||
Comment 4•3 years ago
|
||
To test the bindings generation, we generate JS bindings for a set of test
Rust crates, then run xpcshell tests against those bindings.
Currently these tests only run when the --enable-uniffi-fixtures
option is set, so they need to be run manually be a dev. I'd love to
create a system where these can optionally run in CI, but I'm not sure
how to do that.
Depends on D144468
Assignee | ||
Comment 5•3 years ago
|
||
Depends on D144469
Assignee | ||
Comment 6•3 years ago
|
||
Depends on D144470
Assignee | ||
Comment 7•3 years ago
|
||
At this point, it can generate a WebIDL interface to handle the
scaffolding layer, which is a low-level C-ABI layer. The next step is
to generate a JS wrapper on top of this that presents a nice API for
devs.
There's support for both synchronus and async functions, but we haven't
decided the how we want this to be configured. In practice, almost all
functions will need to be async, so for now we're just forcing all
functions to be.
The uniffi-bindgen-gecko-js
crate implements a UniFFI external
bindings generator and will generate the JS bindings. The render
module contains submodules that handling rendering different languages.
The basic system is that each module defines extension traits on the
ComponentInterface
types (Type, Argument, Field, Function, etc.). The
traits are then used by the template code to render things specific to
that language, for example how a function should be named in the WebIDL
file. The extend
library adds some syntactic sugar to allow this
without too much boilerplate.
The uniffi-js directory which contains shared code for
uniffi-bindgen-gecko-js
. Right now this is the OwnedRustBuffer
class, which is responsible for tracking ownership and freeing our
RustBuffer
instances if needed.
UniFFIRustCallResult is a simply WebIDL dictionary that stores the
result of a scaffolding function call.
Updated•3 years ago
|
Assignee | ||
Comment 8•3 years ago
|
||
Commmand
is the new name for App
.
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Comment 9•3 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::JavaScript Engine' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Assignee | ||
Updated•3 years ago
|
Assignee | ||
Comment 10•3 years ago
|
||
This is a repsonse to the build errors I noticed with
build-macosx64-hybrid/plain, build-win64-hybrid/plain, and
build-linux64-hybrid/plain.
I'm not exactly sure why those build had errors but others didn't, but
my guess is that it was a combination of:
- A clang++ producing different warnings/errors.
- The uniffied builds being arranged slightly differently, which
surfaced errors based on missing include statements.
Depends on D144470
Comment 11•3 years ago
|
||
Comment 12•3 years ago
|
||
Backed out for causing Bp-hybrid failures on UniFFIGeneratedScaffolding.cpp
Backout link
Push with failures
Link to failure log
Failure line :
/builds/worker/checkouts/gecko/toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp:44:10: error: 'return' will never be executed [-Werror,-Wunreachable-code-return]
Comment 13•3 years ago
|
||
Comment 14•3 years ago
|
||
Backed out for causing build bustages
Backout link: https://hg.mozilla.org/integration/autoland/rev/7d17c1f11050f689cf57d90729e91078f3c5b9b5
Failure log: https://treeherder.mozilla.org/logviewer?job_id=386273457&repo=autoland&lineNumber=27434
Comment 15•3 years ago
|
||
Assignee | ||
Comment 16•3 years ago
|
||
The first bustage was caused by me not using Lando right and not including all the commits.
The second one was caused by an compiler error that happened in build-linux64-base-toolchains/debug
, but not most other builds.
I'm hoping the third try is the charm.
Comment 17•3 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/cc78aaf0481c
https://hg.mozilla.org/mozilla-central/rev/40c7a52560d2
https://hg.mozilla.org/mozilla-central/rev/9e28580c4505
https://hg.mozilla.org/mozilla-central/rev/6fb10be3b37a
https://hg.mozilla.org/mozilla-central/rev/7c864c151572
https://hg.mozilla.org/mozilla-central/rev/a3cb50eab998
Description
•