Bug 1910404 - UniFFI proc-macro support, r=lina,firefox-build-system-reviewers,glandium

Switched to library mode for generating bindings.

Updated our strategy for UniFFI components/fixtures.  There's now a
crate for components and a crate for fixtures.  These crates are a
dependency of gkrust-shared and also built as standalone libraries which
UniFFI uses to generate the bindings.

One upshot of this is that we no longer need the `crate_name` or
`udl_file` config values.  library-mode can figure out the udl paths
automatically.

Differential Revision: https://phabricator.services.mozilla.com/D221824
This commit is contained in:
Ben Dean-Kawamura 2024-09-16 15:18:07 +00:00
parent 6ed932ba2a
commit fba8dd2c1e
84 changed files with 344 additions and 288 deletions

36
Cargo.lock generated
View File

@ -2315,6 +2315,8 @@ dependencies = [
"gecko-profiler",
"gecko_logger",
"geckoservo",
"gkrust-uniffi-components",
"gkrust-uniffi-fixtures",
"gkrust_utils",
"http_sfv",
"idna_glue",
@ -2349,19 +2351,39 @@ dependencies = [
"processtools",
"profiler_helper",
"qcms",
"relevancy",
"rsdparsa_capi",
"rure",
"rusqlite",
"rust_minidump_writer_linux",
"static_prefs",
"storage",
"suggest",
"tabs",
"unic-langid",
"unic-langid-ffi",
"unicode-bidi",
"unicode-bidi-ffi",
"url",
"viaduct",
"webext_storage_bridge",
"webrender_bindings",
"wgpu_bindings",
"wpf-gpu-raster",
"xpcom",
]
[[package]]
name = "gkrust-uniffi-components"
version = "0.1.0"
dependencies = [
"relevancy",
"suggest",
"tabs",
"uniffi",
]
[[package]]
name = "gkrust-uniffi-fixtures"
version = "0.1.0"
dependencies = [
"uniffi",
"uniffi-example-arithmetic",
"uniffi-example-custom-types",
@ -2372,13 +2394,6 @@ dependencies = [
"uniffi-fixture-callbacks",
"uniffi-fixture-external-types",
"uniffi-fixture-refcounts",
"url",
"viaduct",
"webext_storage_bridge",
"webrender_bindings",
"wgpu_bindings",
"wpf-gpu-raster",
"xpcom",
]
[[package]]
@ -6226,6 +6241,7 @@ dependencies = [
"anyhow",
"askama",
"camino",
"cargo_metadata",
"clap",
"extend",
"heck",

View File

@ -43,17 +43,18 @@ You can see an example of this feature in use: [when application-services swappe
Here's how you can create a new set of bindings using UniFFI:
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)
- Follow the steps from the [UniFFI user guide](https://mozilla.github.io/uniffi-rs/0.27/) to add support to your crate.
- UDL and proc-macros are both supported.
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
- Edit `toolkit/components/uniffi-bindgen-gecko-js/components/Cargo.toml` and add a dependency to your library path
- **If the code exists in an external repo:**
- Edit `toolkit/library/rust/shared/Cargo.toml` and add a dependency to your library URL
- Edit `toolkit/components/uniffi-bindgen-gecko-js/components/Cargo.toml` and add a dependency to your library URL
- Run `mach vendor rust` to vendor in your Rust code
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/config.toml`
3. Configure your crate (optional)
- Edit `toolkit/components/uniffi-bindgen-gecko-js/config.toml` and add an entry for your crate.
4. Generate bindings code for your crate
- Run `./mach uniffi generate`
- add your newly generated `Rust{udl-name}.sys.mjs` file to `toolkit/components/uniffi-bindgen-gecko-js/components/moz.build`
- Then simply import your module to the file you want to use it in and start using your APIs!

View File

@ -12,6 +12,7 @@ path = "src/main.rs"
anyhow = "1"
askama = { version = "0.12", default-features = false, features = ["config"] }
clap = { version = "4", default-features = false, features = ["std", "derive", "cargo"] }
cargo_metadata = "0.15"
extend = "1.1"
heck = "0.5"
uniffi = { workspace = true }

View File

@ -0,0 +1,2 @@
This directory contains crates that bundle UniFFI-enabled components together.
This enables uniffi-bindgen-gecko-js to build the components into a shared lib and generate the bindings using library mode.

View File

@ -0,0 +1,22 @@
[package]
name = "gkrust-uniffi-components"
version = "0.1.0"
authors = ["The Mozilla Project Developers"]
license = "MPL-2.0"
description = "UniFFI-enabled Rust components for libxul"
[lib]
crate-type = ["rlib", "staticlib"]
path = "lib.rs"
test = false
doctest = false
bench = false
doc = false
plugin = false
harness = false
[dependencies]
uniffi = { workspace = true }
tabs = "0.1"
suggest = "0.1"
relevancy = "0.1"

View File

@ -0,0 +1,26 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
mod reexport_appservices_uniffi_scaffolding {
tabs::uniffi_reexport_scaffolding!();
relevancy::uniffi_reexport_scaffolding!();
suggest::uniffi_reexport_scaffolding!();
}
// Define extern "C" versions of these UniFFI functions, so that they can be called from C++
#[no_mangle]
pub extern "C" fn uniffi_rustbuffer_alloc(
size: u64,
call_status: &mut uniffi::RustCallStatus,
) -> uniffi::RustBuffer {
uniffi::uniffi_rustbuffer_alloc(size, call_status)
}
#[no_mangle]
pub extern "C" fn uniffi_rustbuffer_free(
buf: uniffi::RustBuffer,
call_status: &mut uniffi::RustCallStatus,
) {
uniffi::uniffi_rustbuffer_free(buf, call_status)
}

View File

@ -9,17 +9,6 @@
# TODO: Upgrade the TOML crate and switch to array of tables syntax.
[sync15]
crate_name = "sync15"
udl_file = "third_party/rust/sync15/src/sync15.udl"
[tabs]
crate_name = "tabs"
udl_file = "third_party/rust/tabs/src/tabs.udl"
[suggest]
crate_name = "suggest"
udl_file = "third_party/rust/suggest/src/suggest.udl"
[suggest.receiver_thread]
default = "worker"
@ -35,10 +24,6 @@ main = [
"SuggestStoreBuilder.build",
]
[relevancy]
crate_name = "relevancy"
udl_file = "third_party/rust/relevancy/src/relevancy.udl"
[relevancy.receiver_thread]
default = "worker"
main = [
@ -47,47 +32,13 @@ main = [
"RelevancyStore.interrupt",
]
[remote_settings]
crate_name = "remote_settings"
udl_file = "third_party/rust/remote_settings/src/remote_settings.udl"
[remote_settings.receiver_thread]
default = "worker"
main = [
"RemoteSettings",
]
[geometry]
crate_name = "uniffi_geometry"
udl_file = "toolkit/components/uniffi-fixtures/geometry/src/geometry.udl"
fixture = true
[arithmetic]
crate_name = "arithmetical"
udl_file = "toolkit/components/uniffi-fixtures/arithmetic/src/arithmetic.udl"
fixture = true
[rondpoint]
crate_name = "uniffi_rondpoint"
udl_file = "toolkit/components/uniffi-fixtures/rondpoint/src/rondpoint.udl"
fixture = true
[sprites]
crate_name = "uniffi_sprites"
udl_file = "toolkit/components/uniffi-fixtures/sprites/src/sprites.udl"
fixture = true
[todolist]
crate_name = "uniffi_todolist"
udl_file = "toolkit/components/uniffi-fixtures/todolist/src/todolist.udl"
fixture = true
[fixture_refcounts]
crate_name = "uniffi_fixture_refcounts"
udl_file = "toolkit/components/uniffi-fixtures/refcounts/src/refcounts.udl"
fixture = true
[fixture_refcounts.receiver_thread]
[uniffi_fixture_refcounts.receiver_thread]
default = "main"
# Temporarily disabled until we can re-enable callback support
@ -95,21 +46,9 @@ default = "main"
# I think this can be done when we implement https://bugzilla.mozilla.org/show_bug.cgi?id=1888668
# [fixture_callbacks]
# crate_name = "uniffi_fixture_callbacks"
# udl_file = "toolkit/components/uniffi-fixture-callbacks/src/callbacks.udl"
# fixture = true
#
# [fixture_callbacks.receiver_thread]
# default = "worker"
# main = [
# "log_even_numbers_main_thread",
# ]
[custom_types]
crate_name = "uniffi_custom_types"
udl_file = "toolkit/components/uniffi-fixtures/custom-types/src/custom-types.udl"
fixture = true
[external_types]
crate_name = "uniffi_fixture_external_types"
udl_file = "toolkit/components/uniffi-fixtures/external-types/src/external-types.udl"
fixture = true

View File

@ -0,0 +1,28 @@
[package]
name = "gkrust-uniffi-fixtures"
version = "0.1.0"
authors = ["The Mozilla Project Developers"]
license = "MPL-2.0"
description = "UniFFI-enabled Rust components for libxul"
[lib]
crate-type = ["rlib", "staticlib"]
path = "lib.rs"
test = false
doctest = false
bench = false
doc = false
plugin = false
harness = false
[dependencies]
uniffi = { workspace = true }
uniffi-example-arithmetic = { path = "arithmetic/" }
uniffi-example-geometry = { path = "geometry/" }
uniffi-example-rondpoint = { path = "rondpoint/" }
uniffi-example-sprites = { path = "sprites/" }
uniffi-example-todolist = { path = "todolist/" }
uniffi-example-custom-types = { path = "custom-types/" }
uniffi-fixture-callbacks = { path = "callbacks/" }
uniffi-fixture-external-types = { path = "external-types/" }
uniffi-fixture-refcounts = { path = "refcounts/" }

View File

@ -473,7 +473,7 @@ export function gradient(ln) {
throw e;
}
return UniFFIScaffolding.callAsync(
63, // geometry:uniffi_uniffi_geometry_fn_func_gradient
60, // geometry:uniffi_uniffi_geometry_fn_func_gradient
FfiConverterTypeLine.lower(ln),
)
}
@ -506,7 +506,7 @@ export function intersection(ln1,ln2) {
throw e;
}
return UniFFIScaffolding.callAsync(
64, // geometry:uniffi_uniffi_geometry_fn_func_intersection
61, // geometry:uniffi_uniffi_geometry_fn_func_intersection
FfiConverterTypeLine.lower(ln1),
FfiConverterTypeLine.lower(ln2),
)

View File

@ -320,7 +320,7 @@ export class SingletonObject {
const liftError = null;
const functionCall = () => {
return UniFFIScaffolding.callSync(
62, // refcounts:uniffi_uniffi_fixture_refcounts_fn_method_singletonobject_method
64, // refcounts:uniffi_uniffi_fixture_refcounts_fn_method_singletonobject_method
FfiConverterTypeSingletonObject.lower(this),
)
}
@ -368,7 +368,7 @@ export function getJsRefcount() {
const liftError = null;
const functionCall = () => {
return UniFFIScaffolding.callSync(
60, // refcounts:uniffi_uniffi_fixture_refcounts_fn_func_get_js_refcount
62, // refcounts:uniffi_uniffi_fixture_refcounts_fn_func_get_js_refcount
)
}
return handleRustResult(functionCall(), liftResult, liftError);
@ -380,7 +380,7 @@ export function getSingleton() {
const liftError = null;
const functionCall = () => {
return UniFFIScaffolding.callSync(
61, // refcounts:uniffi_uniffi_fixture_refcounts_fn_func_get_singleton
63, // refcounts:uniffi_uniffi_fixture_refcounts_fn_func_get_singleton
)
}
return handleRustResult(functionCall(), liftResult, liftError);

View File

@ -0,0 +1,13 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
arithmetical::uniffi_reexport_scaffolding!();
uniffi_fixture_callbacks::uniffi_reexport_scaffolding!();
uniffi_custom_types::uniffi_reexport_scaffolding!();
uniffi_fixture_external_types::uniffi_reexport_scaffolding!();
uniffi_fixture_refcounts::uniffi_reexport_scaffolding!();
uniffi_geometry::uniffi_reexport_scaffolding!();
uniffi_rondpoint::uniffi_reexport_scaffolding!();
uniffi_sprites::uniffi_reexport_scaffolding!();
uniffi_todolist::uniffi_reexport_scaffolding!();

View File

@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import distutils.ccompiler
import os
import subprocess
@ -12,6 +13,27 @@ JS_DIR = "toolkit/components/uniffi-bindgen-gecko-js/components/generated"
FIXTURE_JS_DIR = "toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated"
def build_gkrust_uniffi_library(command_context, package_name):
uniffi_root = crate_root(command_context)
print("Building gkrust-uniffi-components")
cmdline = [
"cargo",
"build",
"--release",
"--manifest-path",
os.path.join(command_context.topsrcdir, "Cargo.toml"),
"--package",
package_name,
]
subprocess.check_call(cmdline, cwd=uniffi_root)
print()
ccompiler = distutils.ccompiler.new_compiler()
return ccompiler.find_library_file(
[os.path.join(command_context.topsrcdir, "target", "release")],
package_name.replace("-", "_"),
)
def build_uniffi_bindgen_gecko_js(command_context):
uniffi_root = crate_root(command_context)
print("Building uniffi-bindgen-gecko-js")
@ -48,9 +70,19 @@ def uniffi(command_context, *runargs, **lintargs):
description="Generate/regenerate bindings",
)
def generate_command(command_context):
library_path = build_gkrust_uniffi_library(
command_context, "gkrust-uniffi-components"
)
fixtures_library_path = build_gkrust_uniffi_library(
command_context, "gkrust-uniffi-fixtures"
)
binary_path = build_uniffi_bindgen_gecko_js(command_context)
cmdline = [
binary_path,
"--library-path",
library_path,
"--fixtures-library-path",
fixtures_library_path,
"--js-dir",
JS_DIR,
"--fixture-js-dir",

View File

@ -13,23 +13,26 @@
//!
//! This module manages the list of ComponentInterface and the object ids.
use crate::render::cpp::exposed_functions;
use crate::{Component, Config, ConfigMap};
use anyhow::{bail, Context, Result};
use camino::Utf8PathBuf;
use std::collections::{BTreeSet, HashMap, HashSet};
use anyhow::{anyhow, bail, Context, Result};
use camino::{Utf8Path, Utf8PathBuf};
use uniffi_bindgen::interface::{CallbackInterface, ComponentInterface, FfiFunction, Object};
use crate::render::cpp::exposed_functions;
use crate::Component;
pub struct ComponentUniverse {
pub components: Vec<Component>,
pub fixture_components: Vec<Component>,
}
impl ComponentUniverse {
pub fn new(config_map: ConfigMap) -> Result<Self> {
pub fn new(library_path: Utf8PathBuf, fixtures_library_path: Utf8PathBuf) -> Result<Self> {
let config_supplier = GeckoJsCrateConfigSupplier::new()?;
let universe = Self {
components: parse_udl_files(&config_map, false)?,
fixture_components: parse_udl_files(&config_map, true)?,
components: find_components(&library_path, &config_supplier)?,
fixture_components: find_components(&fixtures_library_path, &config_supplier)?,
};
universe.check_udl_namespaces_unique()?;
universe.check_callback_interfaces()?;
@ -72,31 +75,65 @@ impl ComponentUniverse {
}
}
fn parse_udl_files(config_map: &ConfigMap, fixture: bool) -> Result<Vec<Component>> {
// Sort config entries to ensure consistent output
let mut entries: Vec<_> = config_map.iter().collect();
entries.sort_by_key(|(key, _)| *key);
entries
fn find_components(
library_path: &Utf8Path,
config_supplier: &GeckoJsCrateConfigSupplier,
) -> Result<Vec<Component>> {
let mut components = uniffi_bindgen::find_components(library_path, config_supplier)?
.into_iter()
.filter_map(|(_, config)| {
if config.fixture == fixture {
Some(parse_udl_file(&config).map(|ci| Component {
ci,
config: config.clone(),
}))
} else {
None
}
// FIXME(Bug 1913982): Need to filter out components that use callback interfaces for now
.filter(|component| {
let namespace = component.ci.namespace();
namespace != "errorsupport" && namespace != "fixture_callbacks"
})
.collect()
.map(|component| {
Ok(Component {
config: toml::Value::Table(component.config).try_into()?,
ci: component.ci,
})
})
.collect::<Result<Vec<Component>>>()?;
// Sort components entries to ensure consistent output
components.sort_by(|c1, c2| c1.ci.namespace().cmp(c2.ci.namespace()));
Ok(components)
}
fn parse_udl_file(config: &Config) -> Result<ComponentInterface> {
let udl_file = Utf8PathBuf::from(&config.udl_file);
let udl = std::fs::read_to_string(udl_file)
.context(format!("Error reading UDL file '{}'", config.udl_file))?;
ComponentInterface::from_webidl(&udl, &config.crate_name)
.context(format!("Failed to parse UDL '{}'", config.udl_file))
/// Responsible for finding UDL files and config values for crates
struct GeckoJsCrateConfigSupplier {
// Used to lookup the UDL files
cargo_crate_config_supplier: uniffi_bindgen::cargo_metadata::CrateConfigSupplier,
// Used to get config values
config_table: toml::map::Map<String, toml::Value>,
}
impl GeckoJsCrateConfigSupplier {
fn new() -> Result<Self> {
Ok(Self {
cargo_crate_config_supplier: cargo_metadata::MetadataCommand::new()
.exec()
.context("error running cargo metadata")?
.into(),
config_table: toml::from_str(include_str!("../config.toml"))?,
})
}
}
impl uniffi_bindgen::BindgenCrateConfigSupplier for GeckoJsCrateConfigSupplier {
fn get_udl(&self, crate_name: &str, udl_name: &str) -> anyhow::Result<String> {
self.cargo_crate_config_supplier
.get_udl(crate_name, udl_name)
}
fn get_toml(&self, crate_name: &str) -> anyhow::Result<Option<toml::value::Table>> {
self.config_table
.get(crate_name)
.map(|v| {
v.as_table()
.ok_or_else(|| anyhow!("Config value not table"))
.cloned()
})
.transpose()
}
}
pub struct FunctionIds<'a> {

View File

@ -7,7 +7,7 @@ use askama::Template;
use camino::Utf8PathBuf;
use clap::Parser;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::fs::File;
use std::io::Write;
@ -26,6 +26,12 @@ use render::js::JSBindingsTemplate;
struct CliArgs {
// This is a really convoluted set of arguments, but we're only expecting to be called by
// `mach_commands.py`
#[clap(long, value_name = "FILE")]
library_path: Utf8PathBuf,
#[clap(long, value_name = "FILE")]
fixtures_library_path: Utf8PathBuf,
#[clap(long, value_name = "FILE")]
js_dir: Utf8PathBuf,
@ -36,18 +42,11 @@ struct CliArgs {
cpp_path: Utf8PathBuf,
}
/// Configuration for all components, read from `uniffi.toml`
type ConfigMap = HashMap<String, Config>;
type Component = uniffi_bindgen::Component<Config>;
/// Configuration for a single Component
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Config {
crate_name: String,
udl_file: String,
#[serde(default)]
fixture: bool,
#[serde(default)]
receiver_thread: ReceiverThreadConfig,
}
@ -113,9 +112,7 @@ fn render_js(
pub fn run_main() -> Result<()> {
let args = CliArgs::parse();
let config_map: ConfigMap =
toml::from_str(include_str!("../config.toml")).expect("Error parsing config.toml");
let components = ComponentUniverse::new(config_map)?;
let components = ComponentUniverse::new(args.library_path, args.fixtures_library_path)?;
let function_ids = FunctionIds::new(&components);
let object_ids = ObjectIds::new(&components);
let callback_ids = CallbackIds::new(&components);

View File

@ -106,13 +106,13 @@ extern "C" {
RustBuffer uniffi_uniffi_custom_types_fn_func_get_custom_types_demo(RustBuffer, RustCallStatus*);
double uniffi_uniffi_fixture_external_types_fn_func_gradient(RustBuffer, RustCallStatus*);
RustBuffer uniffi_uniffi_fixture_external_types_fn_func_intersection(RustBuffer, RustBuffer, RustCallStatus*);
double uniffi_uniffi_geometry_fn_func_gradient(RustBuffer, RustCallStatus*);
RustBuffer uniffi_uniffi_geometry_fn_func_intersection(RustBuffer, RustBuffer, RustCallStatus*);
void* uniffi_uniffi_fixture_refcounts_fn_clone_singletonobject(void*, RustCallStatus*);
void uniffi_uniffi_fixture_refcounts_fn_free_singletonobject(void*, RustCallStatus*);
void uniffi_uniffi_fixture_refcounts_fn_method_singletonobject_method(void*, RustCallStatus*);
int32_t uniffi_uniffi_fixture_refcounts_fn_func_get_js_refcount(RustCallStatus*);
void* uniffi_uniffi_fixture_refcounts_fn_func_get_singleton(RustCallStatus*);
double uniffi_uniffi_geometry_fn_func_gradient(RustBuffer, RustCallStatus*);
RustBuffer uniffi_uniffi_geometry_fn_func_intersection(RustBuffer, RustBuffer, RustCallStatus*);
void* uniffi_uniffi_rondpoint_fn_clone_optionneur(void*, RustCallStatus*);
void uniffi_uniffi_rondpoint_fn_free_optionneur(void*, RustCallStatus*);
void* uniffi_uniffi_rondpoint_fn_constructor_optionneur_new(RustCallStatus*);
@ -2761,6 +2761,92 @@ public:
);
}
};
class ScaffoldingCallHandlerUniffiUniffiGeometryFnFuncGradient : public UniffiHandlerBase {
private:
// PrepareRustArgs stores the resulting arguments in these fields
typename ScaffoldingConverter<RustBuffer>::IntermediateType mLn;
// MakeRustCall stores the result of the call in these fields
typename ScaffoldingConverter<double>::IntermediateType mUniffiReturnValue;
public:
void PrepareRustArgs(const dom::Sequence<dom::UniFFIScaffoldingValue>& aArgs, ErrorResult& aError) override {
ScaffoldingConverter<RustBuffer>::FromJs(aArgs[0], &mLn, aError);
if (aError.Failed()) {
return;
}
}
void MakeRustCall() override {
RustCallStatus callStatus{};
mUniffiReturnValue = ScaffoldingConverter<double>::FromRust(
uniffi_uniffi_geometry_fn_func_gradient(
ScaffoldingConverter<RustBuffer>::IntoRust(std::move(mLn)),
&callStatus
)
);
mUniffiCallStatusCode = callStatus.code;
if (callStatus.error_buf.data) {
mUniffiCallStatusErrorBuf = OwnedRustBuffer(callStatus.error_buf);
}
}
virtual void ExtractSuccessfulCallResult(JSContext* aCx, dom::Optional<dom::UniFFIScaffoldingValue>& aDest, ErrorResult& aError) override {
ScaffoldingConverter<double>::IntoJs(
aCx,
std::move(mUniffiReturnValue),
aDest,
aError
);
}
};
class ScaffoldingCallHandlerUniffiUniffiGeometryFnFuncIntersection : public UniffiHandlerBase {
private:
// PrepareRustArgs stores the resulting arguments in these fields
typename ScaffoldingConverter<RustBuffer>::IntermediateType mLn1;
typename ScaffoldingConverter<RustBuffer>::IntermediateType mLn2;
// MakeRustCall stores the result of the call in these fields
typename ScaffoldingConverter<RustBuffer>::IntermediateType mUniffiReturnValue;
public:
void PrepareRustArgs(const dom::Sequence<dom::UniFFIScaffoldingValue>& aArgs, ErrorResult& aError) override {
ScaffoldingConverter<RustBuffer>::FromJs(aArgs[0], &mLn1, aError);
if (aError.Failed()) {
return;
}
ScaffoldingConverter<RustBuffer>::FromJs(aArgs[1], &mLn2, aError);
if (aError.Failed()) {
return;
}
}
void MakeRustCall() override {
RustCallStatus callStatus{};
mUniffiReturnValue = ScaffoldingConverter<RustBuffer>::FromRust(
uniffi_uniffi_geometry_fn_func_intersection(
ScaffoldingConverter<RustBuffer>::IntoRust(std::move(mLn1)),
ScaffoldingConverter<RustBuffer>::IntoRust(std::move(mLn2)),
&callStatus
)
);
mUniffiCallStatusCode = callStatus.code;
if (callStatus.error_buf.data) {
mUniffiCallStatusErrorBuf = OwnedRustBuffer(callStatus.error_buf);
}
}
virtual void ExtractSuccessfulCallResult(JSContext* aCx, dom::Optional<dom::UniFFIScaffoldingValue>& aDest, ErrorResult& aError) override {
ScaffoldingConverter<RustBuffer>::IntoJs(
aCx,
std::move(mUniffiReturnValue),
aDest,
aError
);
}
};
class ScaffoldingCallHandlerUniffiUniffiFixtureRefcountsFnFuncGetJsRefcount : public UniffiHandlerBase {
private:
// PrepareRustArgs stores the resulting arguments in these fields
@ -2860,92 +2946,6 @@ public:
virtual void ExtractSuccessfulCallResult(JSContext* aCx, dom::Optional<dom::UniFFIScaffoldingValue>& aDest, ErrorResult& aError) override {
}
};
class ScaffoldingCallHandlerUniffiUniffiGeometryFnFuncGradient : public UniffiHandlerBase {
private:
// PrepareRustArgs stores the resulting arguments in these fields
typename ScaffoldingConverter<RustBuffer>::IntermediateType mLn;
// MakeRustCall stores the result of the call in these fields
typename ScaffoldingConverter<double>::IntermediateType mUniffiReturnValue;
public:
void PrepareRustArgs(const dom::Sequence<dom::UniFFIScaffoldingValue>& aArgs, ErrorResult& aError) override {
ScaffoldingConverter<RustBuffer>::FromJs(aArgs[0], &mLn, aError);
if (aError.Failed()) {
return;
}
}
void MakeRustCall() override {
RustCallStatus callStatus{};
mUniffiReturnValue = ScaffoldingConverter<double>::FromRust(
uniffi_uniffi_geometry_fn_func_gradient(
ScaffoldingConverter<RustBuffer>::IntoRust(std::move(mLn)),
&callStatus
)
);
mUniffiCallStatusCode = callStatus.code;
if (callStatus.error_buf.data) {
mUniffiCallStatusErrorBuf = OwnedRustBuffer(callStatus.error_buf);
}
}
virtual void ExtractSuccessfulCallResult(JSContext* aCx, dom::Optional<dom::UniFFIScaffoldingValue>& aDest, ErrorResult& aError) override {
ScaffoldingConverter<double>::IntoJs(
aCx,
std::move(mUniffiReturnValue),
aDest,
aError
);
}
};
class ScaffoldingCallHandlerUniffiUniffiGeometryFnFuncIntersection : public UniffiHandlerBase {
private:
// PrepareRustArgs stores the resulting arguments in these fields
typename ScaffoldingConverter<RustBuffer>::IntermediateType mLn1;
typename ScaffoldingConverter<RustBuffer>::IntermediateType mLn2;
// MakeRustCall stores the result of the call in these fields
typename ScaffoldingConverter<RustBuffer>::IntermediateType mUniffiReturnValue;
public:
void PrepareRustArgs(const dom::Sequence<dom::UniFFIScaffoldingValue>& aArgs, ErrorResult& aError) override {
ScaffoldingConverter<RustBuffer>::FromJs(aArgs[0], &mLn1, aError);
if (aError.Failed()) {
return;
}
ScaffoldingConverter<RustBuffer>::FromJs(aArgs[1], &mLn2, aError);
if (aError.Failed()) {
return;
}
}
void MakeRustCall() override {
RustCallStatus callStatus{};
mUniffiReturnValue = ScaffoldingConverter<RustBuffer>::FromRust(
uniffi_uniffi_geometry_fn_func_intersection(
ScaffoldingConverter<RustBuffer>::IntoRust(std::move(mLn1)),
ScaffoldingConverter<RustBuffer>::IntoRust(std::move(mLn2)),
&callStatus
)
);
mUniffiCallStatusCode = callStatus.code;
if (callStatus.error_buf.data) {
mUniffiCallStatusErrorBuf = OwnedRustBuffer(callStatus.error_buf);
}
}
virtual void ExtractSuccessfulCallResult(JSContext* aCx, dom::Optional<dom::UniFFIScaffoldingValue>& aDest, ErrorResult& aError) override {
ScaffoldingConverter<RustBuffer>::IntoJs(
aCx,
std::move(mUniffiReturnValue),
aDest,
aError
);
}
};
class ScaffoldingCallHandlerUniffiUniffiRondpointFnFuncCopieCarte : public UniffiHandlerBase {
private:
// PrepareRustArgs stores the resulting arguments in these fields
@ -6629,20 +6629,20 @@ UniquePtr<UniffiHandlerBase> GetHandler(uint64_t aId) {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiFixtureExternalTypesFnFuncIntersection>();
}
case 60: {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiFixtureRefcountsFnFuncGetJsRefcount>();
}
case 61: {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiFixtureRefcountsFnFuncGetSingleton>();
}
case 62: {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiFixtureRefcountsFnMethodSingletonobjectMethod>();
}
case 63: {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiGeometryFnFuncGradient>();
}
case 64: {
case 61: {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiGeometryFnFuncIntersection>();
}
case 62: {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiFixtureRefcountsFnFuncGetJsRefcount>();
}
case 63: {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiFixtureRefcountsFnFuncGetSingleton>();
}
case 64: {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiFixtureRefcountsFnMethodSingletonobjectMethod>();
}
case 65: {
return MakeUnique<ScaffoldingCallHandlerUniffiUniffiRondpointFnFuncCopieCarte>();
}

View File

@ -74,19 +74,9 @@ origin-trials-ffi = { path = "../../../../dom/origin-trials/ffi" }
jog = { path = "../../../components/glean/bindings/jog" }
dap_ffi = { path = "../../../components/telemetry/dap/ffi" }
data-encoding-ffi = { path = "../../../../dom/fs/parent/rust/data-encoding-ffi" }
uniffi-example-arithmetic = { path = "../../../components/uniffi-fixtures/arithmetic/", optional = true }
uniffi-example-geometry = { path = "../../../components/uniffi-fixtures/geometry/", optional = true }
uniffi-example-rondpoint = { path = "../../../components/uniffi-fixtures/rondpoint/", optional = true }
uniffi-example-sprites = { path = "../../../components/uniffi-fixtures/sprites/", optional = true }
uniffi-example-todolist = { path = "../../../components/uniffi-fixtures/todolist/", optional = true }
uniffi-example-custom-types = { path = "../../../components/uniffi-fixtures/custom-types/", optional = true }
uniffi-fixture-callbacks = { path = "../../../components/uniffi-fixtures/callbacks/", optional = true }
uniffi-fixture-external-types = { path = "../../../components/uniffi-fixtures/external-types/", optional = true }
uniffi-fixture-refcounts = { path = "../../../components/uniffi-fixtures/refcounts/", optional = true }
binary_http = { path = "../../../../netwerk/protocol/http/binary_http" }
oblivious_http = { path = "../../../../netwerk/protocol/http/oblivious_http" }
mime-guess-ffi = { path = "../../../../dom/fs/parent/rust/mime-guess-ffi" }
uniffi = { workspace = true }
# Note: `modern_sqlite` means rusqlite's bindings file be for a sqlite with
# version less than or equal to what we link to. This isn't a problem because we
@ -116,11 +106,10 @@ fallible_collections = { version = "0.4", features = ["rust_1_57"] }
libz-rs-sys = { git = "https://github.com/memorysafety/zlib-rs", rev = "4aa430ccb77537d0d60dab8db993ca51bb1194c5", features = ["custom-prefix"], optional = true }
[target.'cfg(not(target_os = "android"))'.dependencies]
gkrust-uniffi-components = { path = "../../../components/uniffi-bindgen-gecko-js/components/" }
gkrust-uniffi-fixtures = { path = "../../../components/uniffi-bindgen-gecko-js/fixtures/", optional = true }
viaduct = "0.1"
webext_storage_bridge = { path = "../../../components/extensions/storage/webext_storage_bridge" }
tabs = { version = "0.1" }
suggest = { version = "0.1" }
relevancy = { version = "0.1" }
[target.'cfg(target_os = "windows")'.dependencies]
detect_win32k_conflicts = { path = "../../../xre/detect_win32k_conflicts" }
@ -147,11 +136,7 @@ oxidized_breakpad = ["rust_minidump_writer_linux"]
crashreporter = ["mozannotation_client", "mozannotation_server"]
with_dbus = ["audio_thread_priority/with_dbus"]
thread_sanitizer = ["xpcom/thread_sanitizer"]
uniffi_fixtures = [
"uniffi-example-arithmetic", "uniffi-example-geometry", "uniffi-example-rondpoint", "uniffi-example-sprites",
"uniffi-example-todolist", "uniffi-example-custom-types", "uniffi-fixture-callbacks",
"uniffi-fixture-external-types", "uniffi-fixture-refcounts",
]
uniffi_fixtures = ["gkrust-uniffi-fixtures"]
webmidi_midir_impl = ["midir_impl"]
icu4x = ["jsrust_shared/icu4x"]
icu4x_calendar = ["jsrust_shared/icu4x_calendar"]

View File

@ -56,19 +56,6 @@ extern crate audio_thread_priority;
#[cfg(not(target_os = "android"))]
extern crate webext_storage_bridge;
#[cfg(not(target_os = "android"))]
extern crate tabs;
#[cfg(not(target_os = "android"))]
mod reexport_appservices_uniffi_scaffolding {
tabs::uniffi_reexport_scaffolding!();
relevancy::uniffi_reexport_scaffolding!();
suggest::uniffi_reexport_scaffolding!();
}
#[cfg(not(target_os = "android"))]
extern crate suggest;
#[cfg(feature = "webrtc")]
extern crate mdns_service;
extern crate neqo_glue;
@ -96,6 +83,12 @@ extern crate fluent_fallback;
extern crate l10nregistry_ffi;
extern crate localization_ffi;
#[cfg(not(target_os = "android"))]
extern crate gkrust_uniffi_components;
#[cfg(feature = "uniffi_fixtures")]
extern crate gkrust_uniffi_fixtures;
#[cfg(not(target_os = "android"))]
extern crate viaduct;
@ -129,25 +122,6 @@ extern crate mime_guess_ffi;
#[cfg(feature = "libz-rs-sys")]
extern crate libz_rs_sys;
#[cfg(feature = "uniffi_fixtures")]
mod uniffi_fixtures {
extern crate arithmetical;
extern crate uniffi_geometry;
extern crate uniffi_rondpoint;
extern crate uniffi_sprites;
extern crate uniffi_todolist;
arithmetical::uniffi_reexport_scaffolding!();
uniffi_fixture_callbacks::uniffi_reexport_scaffolding!();
uniffi_custom_types::uniffi_reexport_scaffolding!();
uniffi_fixture_external_types::uniffi_reexport_scaffolding!();
uniffi_fixture_refcounts::uniffi_reexport_scaffolding!();
uniffi_geometry::uniffi_reexport_scaffolding!();
uniffi_rondpoint::uniffi_reexport_scaffolding!();
uniffi_sprites::uniffi_reexport_scaffolding!();
uniffi_todolist::uniffi_reexport_scaffolding!();
}
extern crate log;
use log::info;
@ -176,20 +150,3 @@ pub unsafe extern "C" fn debug_log(target: *const c_char, message: *const c_char
// NOTE: The `info!` log macro is used here because we have the `release_max_level_info` feature set.
info!(target: CStr::from_ptr(target).to_str().unwrap(), "{}", CStr::from_ptr(message).to_str().unwrap());
}
// Define extern "C" versions of these UniFFI functions, so that they can be called from C++
#[no_mangle]
pub extern "C" fn uniffi_rustbuffer_alloc(
size: u64,
call_status: &mut uniffi::RustCallStatus,
) -> uniffi::RustBuffer {
uniffi::uniffi_rustbuffer_alloc(size, call_status)
}
#[no_mangle]
pub extern "C" fn uniffi_rustbuffer_free(
buf: uniffi::RustBuffer,
call_status: &mut uniffi::RustCallStatus,
) {
uniffi::uniffi_rustbuffer_free(buf, call_status)
}

View File

@ -26,7 +26,7 @@ trojan-source:
- security/nss/gtests/mozpkix_gtest/pkixnames_tests.cpp
- testing/web-platform/tests/webdriver/tests/bidi/input/perform_actions/key_tentative.py
- testing/web-platform/tests/webdriver/tests/classic/perform_actions/key_tentative.py
- toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.py
- toolkit/components/uniffi-bindgen-gecko-js/fixtures/rondpoint/tests/bindings/test_rondpoint.py
extensions:
- .c
- .cc