Skip to content

Commit

Permalink
Bug 1766045 - Adding mach command to generate UniFFI files r=glandium
Browse files Browse the repository at this point in the history
Added `mach uniffi generate` which executes `uniffi-bindgen-gecko-js` to
generate UniFFI 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.

Differential Revision: https://phabricator.services.mozilla.com/D144468
  • Loading branch information
bendk committed Aug 3, 2022
1 parent fd4cfd1 commit e965ed0
Show file tree
Hide file tree
Showing 15 changed files with 4,637 additions and 1 deletion.
3 changes: 3 additions & 0 deletions build/mach_initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ def initialize(topsrcdir):
),
"esmify": MachCommandReference("tools/esmify/mach_commands.py"),
"xpcshell": MachCommandReference("js/xpconnect/mach_commands.py"),
"uniffi": MachCommandReference(
"toolkit/components/uniffi-bindgen-gecko-js/mach_commands.py"
),
}

# Set a reasonable limit to the number of open files.
Expand Down
1 change: 1 addition & 0 deletions dom/base/nsINodeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "nsWrapperCache.h"
#include "nsISupports.h"
#include "nsIContent.h"

// IID for the nsINodeList interface
#define NS_INODELIST_IID \
Expand Down
3 changes: 3 additions & 0 deletions toolkit/components/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@ if CONFIG["COMPILE_ENVIRONMENT"]:
EXPORTS.mozilla += [
"!regex_ffi_generated.h",
]

if CONFIG["MOZ_UNIFFI_FIXTURES"]:
DIRS += ["uniffi-bindgen-gecko-js/fixtures"]
36 changes: 36 additions & 0 deletions toolkit/components/uniffi-bindgen-gecko-js/fixtures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This directory contains generated code for the UniFFI examples/fixtures and JS
unit tests for it.

This is only built if the `--enable-uniffi-fixtures` flag is present in
`mozconfig`. There's no benefit to including this in a release build.

To add additional examples/fixtures:
- For most of these steps, find the code for existing fixtures and use it as a template for the new code.
- Edit `toolkit/components/uniffi-bindgen-gecko-js/mach_commands.py`
- Add an entry to `FIXTURE_UDL_FILES`
- Edit `toolkit/library/rust/shared/Cargo.toml`
- Add an optional dependency for the fixture.
- Add the feature to the list of features enabled by `uniffi_fixtures`.
- Edit `toolkit/library/rust/shared/lib.rs`:
- Add an `extern crate [name]` to the `uniffi_fixtures` mod
- Note: [name] is the name from the `[lib]` section in the Cargo.toml
for the example/fixture crate. This does not always match the package
name for the crate.
- Add `[name]::reexport_uniffi_scaffolding` to the `uniffi_fixtures` mod
- Edit `toolkit/components/uniffi-bindgen-gecko-js/fixtures/moz.build` and add the fixture name to the `components`
list.
- Add a test module to the `toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/` directory and an entry for it
in `toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell.ini`
- Run `mach vendor rust` to vendor in the Rust code.
- Run `mach uniffi generate` to generate the scaffolding code.
- Check in any new files

To run the tests:
- Make sure you have a `mozconfig` file containing the line `ac_add_options --enable-uniffi-fixtures`
- Run `mach uniffi generate` if:
- You've added or updated a fixture
- You've made changes to `uniffi-bindgen-gecko-js`
- Run `mach build`
- Run `mach xpcshell-test toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/`
- You can also use a path to specific test file
- For subsequent runs, if you only modify the test files, then you can re-run this step directly
Loading

0 comments on commit e965ed0

Please sign in to comment.