Skip to content
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

Generate Firefox Desktop front-end bindings with WebIDL #255

Merged
merged 34 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6fc2f8a
Initial work on Gecko bindings.
linabutler Aug 17, 2020
71eb8a0
Implement remaining C++ type conversions.
linabutler Aug 20, 2020
7de9d33
Nightly check-in. Getting closer to a working demo!
linabutler Aug 21, 2020
9a37750
More comments and TODOs.
linabutler Aug 21, 2020
33a4805
Remove `cargo_metadata` and make other versions match m-c's.
linabutler Aug 25, 2020
f7ce674
Add more templates for Gecko.
linabutler Aug 25, 2020
1cf040d
Stubs for remaining bindings; Rondpoint compiles on Desktop now!
linabutler Aug 26, 2020
d518345
Fix sequence serializer; implement record serializer.
linabutler Aug 26, 2020
5d21dfb
🔥🗑
linabutler Aug 26, 2020
3c2d813
Add remaining Desktop pieces.
linabutler Aug 26, 2020
1c4ed47
It works!
linabutler Aug 27, 2020
d717469
More dependency shenanigans.
linabutler Aug 27, 2020
ba37996
`must_use` annotations; `CheckedInt` for `Size`.
linabutler Aug 27, 2020
e9bdbd3
Clean up FFI macros, remove implicit `[Throws]` for methods.
linabutler Aug 27, 2020
9d21a53
Better docs about what we generate.
linabutler Aug 27, 2020
855f440
Refactor WebIDL argument and return type generation.
linabutler Aug 29, 2020
e309d46
More docs for the new WebIDL types module.
linabutler Aug 29, 2020
ab872d1
Merge branch 'main' into gecko
linabutler Sep 22, 2020
ed8c01f
Clean up and address remaining review feedback.
linabutler Sep 26, 2020
ef73a60
Merge branch 'main' into gecko
linabutler Sep 26, 2020
8ed57bf
Restore `Cargo.toml`.
linabutler Sep 26, 2020
0912308
Replace remaining `MOZ_MUST_USE` with `[[nodiscard]]`.
linabutler Sep 26, 2020
c9ecca7
Comment cleanups, undefine primitive macro, use signed everywhere.
linabutler Sep 26, 2020
f6c7113
Fixes #301 cargo tests by updating and reenabling cargo_metadata (#301)
dmose Sep 29, 2020
c04dd99
Merge pull request #302 from dmose/cargo-test-gekco-fail
linabutler Sep 29, 2020
cafcb95
Finish the fix for #301
dmose Sep 29, 2020
b66630c
Merge pull request #303 from dmose/cargo-test-fix-part-2
linabutler Sep 29, 2020
d0d4e74
Pass a `Context` struct to Gecko JS filters.
linabutler Sep 29, 2020
8d141fd
Move the Rondpoint tests into `gecko_js`.
linabutler Sep 29, 2020
d283aa0
Fix remaining review comments.
linabutler Sep 30, 2020
2ca3547
Fix remaining `RustError` declaration.
linabutler Sep 30, 2020
3461092
Pass the context to all remaining filters.
linabutler Sep 30, 2020
b90b465
Port remaining Rondpoint tests.
linabutler Sep 30, 2020
80def1f
Fix serialization of nullable strings.
linabutler Sep 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions Cargo.toml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/rondpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"

[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "lib"]
name = "uniffi_rondpoint"

[dependencies]
Expand Down
141 changes: 141 additions & 0 deletions examples/rondpoint/tests/gecko/test_rondpoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
add_task(async function test_rondpoint() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't believe this is real 🎉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is add_task? I can see it used in this file, but I can't see it anywhere else.

Copy link
Member

@mhammond mhammond Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine the idea is to run these tests using mach xpcshell-test somehow - no idea what process lina has in mind for having mach find them though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this file is an xpcshell test!

no idea what process lina has in mind for having mach find them though

Haha, my workflow so far has been “symlink rondpoint into m-c and add it to moz.build with all the other stuff”, but that’s not going to fly for anything more than a demo. Still, if you want to take it for a spin locally, there are only 11 easy steps! 😆

linabutler marked this conversation as resolved.
Show resolved Hide resolved
deepEqual(
Rondpoint.copieDictionnaire({
un: "deux",
deux: false,
petitNombre: 0,
grosNombre: 123456789,
}),
{
un: "deux",
deux: false,
petitNombre: 0,
grosNombre: 123456789,
}
);
equal(Rondpoint.copieEnumeration("deux"), "deux");
deepEqual(Rondpoint.copieEnumerations(["un", "deux"]), ["un", "deux"]);
deepEqual(
Rondpoint.copieCarte({
1: "un",
2: "deux",
}),
{
1: "un",
2: "deux",
}
);
ok(Rondpoint.switcheroo(false));
});

add_task(async function test_retourneur() {
let rt = new Retourneur();

// Booleans.
[true, false].forEach(v => strictEqual(rt.identiqueBoolean(v), v));

// Bytes.
[-128, 127].forEach(v => equal(rt.identiqueI8(v), v));
[0x00, 0xff].forEach(v => equal(rt.identiqueU8(v), v));

// Shorts.
[-Math.pow(2, 15), Math.pow(2, 15) - 1].forEach(v =>
equal(rt.identiqueI16(v), v)
);
[0, 0xffff].forEach(v => equal(rt.identiqueU16(v), v));

// Ints.
[0, 1, -1, -Math.pow(2, 31), Math.pow(2, 31) - 1].forEach(v =>
equal(rt.identiqueI32(v), v)
);
[0, Math.pow(2, 32) - 1].forEach(v => equal(rt.identiqueU32(v), v));

// Longs.
[0, 1, -1, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER].forEach(v =>
equal(rt.identiqueI64(v), v)
);
[0, 1, Number.MAX_SAFE_INTEGER].forEach(v => equal(rt.identiqueU64(v), v));

// Floats.
[0, 1, 0.25].forEach(v => equal(rt.identiqueFloat(v), v));

// Doubles.
[0, 1, 0.25].forEach(v => equal(rt.identiqueDouble(v), v));

// Strings.
[
"",
"abc",
linabutler marked this conversation as resolved.
Show resolved Hide resolved
"été",
"ښي لاس ته لوستلو لوستل",
"😻emoji 👨‍👧‍👦multi-emoji, 🇨🇭a flag, a canal, panama",
].forEach(v => equal(rt.identiqueString(v), v));
});

add_task(async function test_stringifier() {
let st = new Stringifier();

let wellKnown = st.wellKnownString("firefox");
equal(wellKnown, "uniffi 💚 firefox!");

let table = {
toStringBoolean: [
[true, "true"],
[false, "false"],
],
toStringI8: [
[-128, "-128"],
[127, "127"],
],
toStringU8: [
[0x00, "0"],
[0xff, "255"],
],
toStringI16: [
[-Math.pow(2, 15), "-32768"],
[Math.pow(2, 15) - 1, "32767"],
],
toStringU16: [
[0, "0"],
[0xffff, "65535"],
],
toStringI32: [
[0, "0"],
[1, "1"],
[-1, "-1"],
[-Math.pow(2, 31), "-2147483648"],
[Math.pow(2, 31) - 1, "2147483647"],
],
toStringU32: [
[0, "0"],
[Math.pow(2, 32) - 1, "4294967295"],
],
toStringI64: [
[0, "0"],
[1, "1"],
[-1, "-1"],
[Number.MIN_SAFE_INTEGER, "-9007199254740991"],
[Number.MAX_SAFE_INTEGER, "9007199254740991"],
],
toStringU64: [
[0, "0"],
[1, "1"],
[Number.MAX_SAFE_INTEGER, "9007199254740991"],
],
toStringFloat: [
[0, "0"],
[1, "1"],
[0.25, "0.25"],
],
toStringDouble: [
[0, "0"],
[1, "1"],
[0.25, "0.25"],
],
};
for (let method in table) {
for (let [v, expected] of table[method]) {
strictEqual(st[method](v), expected);
}
}
});
1 change: 1 addition & 0 deletions examples/rondpoint/tests/gecko/xpcshell.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[test_rondpoint.js]
2 changes: 1 addition & 1 deletion uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ffi-support = "~0.4.2"
lazy_static = "1.4"
log = "0.4"
# Regular dependencies
cargo_metadata = "0.11"
# cargo_metadata = { git = "https://github.com/oli-obk/cargo_metadata", rev = "64ee6d1d169103ed60ae4de5ddf84da751e7d841" }
paste = "1.0"
uniffi_bindgen = { path = "../uniffi_bindgen", optional = true }

Expand Down
5 changes: 4 additions & 1 deletion uniffi/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! the `uniffi_macros` crate.

use anyhow::{bail, Result};
use cargo_metadata::Message;
// use cargo_metadata::Message;
linabutler marked this conversation as resolved.
Show resolved Hide resolved
use lazy_static::lazy_static;
use std::{
collections::HashMap,
Expand Down Expand Up @@ -56,6 +56,8 @@ pub fn run_foreign_language_testcase(pkg_dir: &str, idl_file: &str, test_file: &
/// Internally, this function does a bit of caching and concurrency management to avoid rebuilding
/// the component for multiple testcases.
pub fn ensure_compiled_cdylib(pkg_dir: &str) -> Result<String> {
unimplemented!()
linabutler marked this conversation as resolved.
Show resolved Hide resolved
/*
// Have we already compiled this component?
let mut compiled_components = COMPILED_COMPONENTS.lock().unwrap();
if let Some(cdylib_file) = compiled_components.get(pkg_dir) {
Expand Down Expand Up @@ -106,6 +108,7 @@ pub fn ensure_compiled_cdylib(pkg_dir: &str) -> Result<String> {
// Cache the result for subsequent tests.
compiled_components.insert(pkg_dir.to_string(), cdylib_file.clone());
Ok(cdylib_file)
*/
}

/// Execute the `uniffi-bindgen test` command.
Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "uniffi-bindgen"
path = "src/main.rs"

[dependencies]
cargo_metadata = "0.11"
# cargo_metadata = { git = "https://github.com/oli-obk/cargo_metadata", rev = "64ee6d1d169103ed60ae4de5ddf84da751e7d841" }
weedle = "0.11"
anyhow = "1"
askama = "0.10"
Expand Down
13 changes: 11 additions & 2 deletions uniffi_bindgen/askama.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[general]
# Directories to search for templates, relative to the crate root.
dirs = [ "src/templates", "src/bindings/kotlin/templates", "src/bindings/python/templates", "src/bindings/swift/templates" ]
dirs = [ "src/templates", "src/bindings/kotlin/templates", "src/bindings/python/templates", "src/bindings/swift/templates", "src/bindings/gecko/templates" ]

[[syntax]]
name = "kt"
Expand All @@ -15,4 +15,13 @@ name = "swift"
name = "c"

[[syntax]]
name = "rs"
name = "rs"

[[syntax]]
name = "webidl"

[[syntax]]
name = "xpidl"

[[syntax]]
name = "cpp"
Loading