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 32 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
2 changes: 1 addition & 1 deletion examples/arithmetic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MPL-2.0"
publish = false

[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "lib"]
linabutler marked this conversation as resolved.
Show resolved Hide resolved
name = "uniffi_arithmetic"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/rondpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MPL-2.0"
publish = false

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

[dependencies]
Expand Down
226 changes: 226 additions & 0 deletions examples/rondpoint/tests/gecko_js/test_rondpoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
/*
* This file is an xpcshell test that exercises the Rondpoint binding in
* Firefox. Non-Gecko JS consumers can safely ignore it.
*
* If you're working on the Gecko JS bindings, you'll want to either copy or
* symlink this folder into m-c, and add the `xpcshell.ini` file in this
* folder to an `XPCSHELL_TESTS_MANIFESTS` section in the `moz.build` file
* that references the generated bindings.
*
* Currently, this must be done manually, though we're looking at ways to
* run `uniffi-bindgen` as part of the Firefox build, and keep the UniFFI
* bindings tests in the tree. https://github.com/mozilla/uniffi-rs/issues/272
* has more details.
*/

add_task(async function test_rondpoint() {
deepEqual(
Rondpoint.copieDictionnaire({
un: "deux",
deux: true,
petitNombre: 0,
grosNombre: 123456789,
}),
{
un: "deux",
deux: true,
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",
"null\0byte",
"été",
"ښي لاس ته لوستلو لوستل",
"😻emoji 👨‍👧‍👦multi-emoji, 🇨🇭a flag, a canal, panama",
].forEach(v => equal(rt.identiqueString(v), v));

[-1, 0, 1].forEach(v => {
let dict = {
petitNombre: v,
courtNombre: v,
nombreSimple: v,
grosNombre: v,
};
deepEqual(rt.identiqueNombresSignes(dict), dict);
});

[0, 1].forEach(v => {
let dict = {
petitNombre: v,
courtNombre: v,
nombreSimple: v,
grosNombre: v,
};
deepEqual(rt.identiqueNombres(dict), dict);
});
});

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);
}
}
});

add_task(async function test_optionneur() {
let op = new Optionneur();

equal(op.sinonString(), "default");
strictEqual(op.sinonBoolean(), false);
deepEqual(op.sinonSequence(), []);

// Nullables.
strictEqual(op.sinonNull(), null);
strictEqual(op.sinonZero(), 0);

// Decimal integers.
equal(op.sinonI8Dec(), -42);
equal(op.sinonU8Dec(), 42);
equal(op.sinonI16Dec(), 42);
equal(op.sinonU16Dec(), 42);
equal(op.sinonI32Dec(), 42);
equal(op.sinonU32Dec(), 42);
equal(op.sinonI64Dec(), 42);
equal(op.sinonU64Dec(), 42);

// Hexadecimal integers.
equal(op.sinonI8Hex(), -0x7f);
equal(op.sinonU8Hex(), 0xff);
equal(op.sinonI16Hex(), 0x7f);
equal(op.sinonU16Hex(), 0xffff);
equal(op.sinonI32Hex(), 0x7fffffff);
equal(op.sinonU32Hex(), 0xffffffff);

// Octal integers.
equal(op.sinonU32Oct(), 493);

// Floats.
equal(op.sinonF32(), 42);
equal(op.sinonF64(), 42.1);

// Enums.
equal(op.sinonEnum(), "trois");

["foo", "bar"].forEach(v => {
equal(op.sinonString(v), v);
});

// Enums.
["un", "deux", "trois"].forEach(v => {
equal(op.sinonEnum(v), v);
});
});
1 change: 1 addition & 0 deletions examples/rondpoint/tests/gecko_js/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 @@ -18,7 +18,7 @@ ffi-support = "~0.4.2"
lazy_static = "1.4"
log = "0.4"
# Regular dependencies
cargo_metadata = "0.11"
cargo_metadata = "0.11.3"
paste = "1.0"
uniffi_bindgen = { path = "../uniffi_bindgen", optional = true, version = "0.2.0" }

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

[dependencies]
cargo_metadata = "0.11"
cargo_metadata = "0.11.3"
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_js/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