Bug 1890866 - Reorganize the UniFFI fixtures/examples. r=markh

Differential Revision: https://phabricator.services.mozilla.com/D207208
This commit is contained in:
Ben Dean-Kawamura 2024-04-15 18:07:00 +00:00
parent f75e1e2283
commit c3fc8ade58
83 changed files with 248 additions and 316 deletions

View File

@ -90,11 +90,6 @@ git = "https://github.com/mozilla/neqo"
tag = "v0.7.5"
replace-with = "vendored-sources"
[source."git+https://github.com/mozilla/uniffi-rs.git?rev=d52c5460ae42ecad1e73a5b394ac96d48f4769de"]
git = "https://github.com/mozilla/uniffi-rs.git"
rev = "d52c5460ae42ecad1e73a5b394ac96d48f4769de"
replace-with = "vendored-sources"
[source."git+https://github.com/seanmonstar/warp?rev=9d081461ae1167eb321585ce424f4fef6cf0092b"]
git = "https://github.com/seanmonstar/warp"
rev = "9d081461ae1167eb321585ce424f4fef6cf0092b"

6
Cargo.lock generated
View File

@ -6046,6 +6046,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5566fae48a5cb017005bf9cd622af5236b2a203a13fb548afde3506d3c68277"
dependencies = [
"anyhow",
"uniffi_bindgen",
"uniffi_build",
"uniffi_core",
"uniffi_macros",
@ -6070,7 +6071,6 @@ dependencies = [
[[package]]
name = "uniffi-example-arithmetic"
version = "0.22.0"
source = "git+https://github.com/mozilla/uniffi-rs.git?rev=d52c5460ae42ecad1e73a5b394ac96d48f4769de#d52c5460ae42ecad1e73a5b394ac96d48f4769de"
dependencies = [
"thiserror",
"uniffi",
@ -6090,7 +6090,6 @@ dependencies = [
[[package]]
name = "uniffi-example-geometry"
version = "0.22.0"
source = "git+https://github.com/mozilla/uniffi-rs.git?rev=d52c5460ae42ecad1e73a5b394ac96d48f4769de#d52c5460ae42ecad1e73a5b394ac96d48f4769de"
dependencies = [
"uniffi",
]
@ -6098,7 +6097,6 @@ dependencies = [
[[package]]
name = "uniffi-example-rondpoint"
version = "0.22.0"
source = "git+https://github.com/mozilla/uniffi-rs.git?rev=d52c5460ae42ecad1e73a5b394ac96d48f4769de#d52c5460ae42ecad1e73a5b394ac96d48f4769de"
dependencies = [
"uniffi",
]
@ -6106,7 +6104,6 @@ dependencies = [
[[package]]
name = "uniffi-example-sprites"
version = "0.22.0"
source = "git+https://github.com/mozilla/uniffi-rs.git?rev=d52c5460ae42ecad1e73a5b394ac96d48f4769de#d52c5460ae42ecad1e73a5b394ac96d48f4769de"
dependencies = [
"uniffi",
]
@ -6114,7 +6111,6 @@ dependencies = [
[[package]]
name = "uniffi-example-todolist"
version = "0.22.0"
source = "git+https://github.com/mozilla/uniffi-rs.git?rev=d52c5460ae42ecad1e73a5b394ac96d48f4769de#d52c5460ae42ecad1e73a5b394ac96d48f4769de"
dependencies = [
"once_cell",
"thiserror",

View File

@ -228,10 +228,3 @@ mio_0_8 = { package = "mio", git = "https://github.com/glandium/mio", rev = "9a2
# There is not going to be new version of mio 0.6, mio now being >= 0.7.11.
[patch.crates-io.mio]
path = "third_party/rust/mio-0.6.23"
[patch."https://github.com/mozilla/uniffi-rs.git"]
uniffi = "0.27.1"
uniffi_bindgen = "0.27.1"
uniffi_build = "0.27.1"
uniffi_macros = "0.27.1"
weedle2 = "=5.0.0"

View File

@ -1 +0,0 @@
{"files":{"Cargo.toml":"359cffb76e0eac82aeec6a667f7670fa4b88346c2dd7c17febe71731fd6df58b","build.rs":"7d98b49c1d9c868c4199f0417eaa017ab459cdd536e9a29851d5f707941f9ead","src/arithmetic.udl":"8554c6907ece627645f6b896f71430e5412bf19b0ac6becf63eb9a69868d0f7a","src/lib.rs":"c454193443e92d49f997c760f4131192fb66bf213bbac1710c1ebde19e765e5d","tests/bindings/test_arithmetic.kts":"e0e9347755db4e18f70b1b74c2d5a4aa328373015090ed959b46d65c2a205d92","tests/bindings/test_arithmetic.py":"3e41d69e21e96a6830197c760f3b7bddd754edc0c5515b7bd33b79cccb10f941","tests/bindings/test_arithmetic.rb":"ea0fdce0a4c7b557b427db77521da05240cd6e87d60a128ac2307fab3bbbc76d","tests/bindings/test_arithmetic.swift":"455b87d95fc690af9c35f9e43676e9c855dedddd2fc1c9e1cbaa6a02835c2d4c","tests/test_generated_bindings.rs":"26b92d6b3e648f6fadd4182cbdba4f412b73da48a789785fd98cd486b29abf05","uniffi.toml":"a2d4f46fa51dc1be1e8bcdf67ec13223637fc1b6c6437455cf53c2dae065fb45"},"package":null}

View File

@ -1,42 +0,0 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "uniffi-example-arithmetic"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
publish = false
license = "MPL-2.0"
[lib]
name = "arithmetical"
crate-type = [
"lib",
"cdylib",
]
[dependencies]
thiserror = "1.0"
[dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
[dev-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["bindgen-tests"]
[build-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["build"]

View File

@ -1 +0,0 @@
{"files":{"Cargo.toml":"2d2c1ec66f7e2aaa4553b5338e68a7b64d68b84152547e1ccc4eeb019ca97103","build.rs":"fc5da645c8862e15f3b6879db179a1e5eec6161dc1cfbf95a4db9daf107a133f","src/geometry.udl":"7da7a6ec080c7117ec3c25206e23f9ed436e60b1a26fba34f991547680443550","src/lib.rs":"f9d004c97efb1a719368169f0aab181f27439eda3520c1afaca2420433226682","tests/bindings/test_geometry.kts":"e537185e3c699df1c0468525700e8a38f9a504b2a663c38442146b951e38e9a7","tests/bindings/test_geometry.py":"600e74ba0eba4e35d824c8f6d5bd5a2120a470017e8465c32d1e954a1939d323","tests/bindings/test_geometry.rb":"651de70af595f8b52ef030a03356939e8c1d0b40e44b4155b45d565d1d1dcbed","tests/bindings/test_geometry.swift":"a61fec6bfe16020809e20e4da372748c24366767138c5672a0bfff85c4b62d78","tests/test_generated_bindings.rs":"ff8fc093ccb6ee3ee2235c09276c7bb87234ad143667429cb721e46379577f3d"},"package":null}

View File

@ -1,39 +0,0 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "uniffi-example-geometry"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
publish = false
license = "MPL-2.0"
[lib]
name = "uniffi_geometry"
crate-type = [
"lib",
"cdylib",
]
[dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
[dev-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["bindgen-tests"]
[build-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["build"]

View File

@ -1 +0,0 @@
{"files":{"Cargo.toml":"c0706abf631a178bfbc2e53b0b714d4a7b73059c46e1326efa4f52d235dc05f5","build.rs":"ba88cce38ecd3321a7a93623755e3339e255360a7f946d3779ded804662c081a","src/lib.rs":"740d70ab5ca22eefcc291a56a9e4ed84e9669f4cfe3890e7d79bc56ae4b991a3","src/rondpoint.udl":"c903cb8c95b3ec1b103350857c3c3bc428bfd90c86a6c48089db9e0fc6e41eb5","tests/bindings/test_rondpoint.kts":"4aac8353278807f4add95c81f4c6c61187204b9767f882fd64872ed8ac1f6451","tests/bindings/test_rondpoint.py":"af25a56c35da9a934fb9f098c25f57329c53d461be378e4c5089b12a45efa28b","tests/bindings/test_rondpoint.rb":"d4b4523084534266ea7ef3161021b9903cb8d7a75cf4624c59055af9f02d22f9","tests/bindings/test_rondpoint.swift":"fa806e7e09c22ed44496658f6e0781765447bbdd250d7adf4b1152248ed70e69","tests/test_generated_bindings.rs":"5464f89e91c458f164b83a454c6df67a2953873e8a785a4720a2253d843f88e5"},"package":null}

View File

@ -1,39 +0,0 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "uniffi-example-rondpoint"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
publish = false
license = "MPL-2.0"
[lib]
name = "uniffi_rondpoint"
crate-type = [
"lib",
"cdylib",
]
[dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
[dev-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["bindgen-tests"]
[build-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["build"]

View File

@ -1 +0,0 @@
{"files":{"Cargo.toml":"94385b28fdc7e33b7019fada486124c027d29b3d2b11b57e8d488658386f7974","build.rs":"7e9d92d7c8fc17b359a29117b137ffc4d32f6c10b450d03e30a396339d8c9099","src/lib.rs":"d7984c0c10011b1bd939bce71dae7437ebb9090583b5d1b1cc133c2e5f60ab66","src/sprites.udl":"bfd35f04ba0549301189dfb8fc45b0f39bad00956c324f33be0e845fb7ff78aa","tests/bindings/test_sprites.kts":"06ed115325f37ce59ed6f33e2d651cd2aa352fddcc644580f62a6da6ca075844","tests/bindings/test_sprites.py":"f976f2be7ab8b88e8b84def760a849c0d98f4c7b481f054f92b566325d78d52d","tests/bindings/test_sprites.rb":"009d545bb7167b7218211430cfaeeb143cc30617eedcf3e51baafe752ad43241","tests/bindings/test_sprites.swift":"b2c0a6f4d5edfd7de7c2ba77b838865ffda153a6f364f273456175192d3e6e00","tests/test_generated_bindings.rs":"9a22d693c97fc6d90031cc60f61ece1d9279165ad6a92c9fe937448e126e8de6"},"package":null}

View File

@ -1,39 +0,0 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "uniffi-example-sprites"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
publish = false
license = "MPL-2.0"
[lib]
name = "uniffi_sprites"
crate-type = [
"lib",
"cdylib",
]
[dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
[dev-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["bindgen-tests"]
[build-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["build"]

View File

@ -1 +0,0 @@
{"files":{"Cargo.toml":"9b182bf2d363240fe1f7b41c73da4bde96d87562812885e4f3175cb6b92ea56b","build.rs":"709d073560a66876d2b975f5145a2dc36e1e3420d79328c8b62666526cae5b2d","src/lib.rs":"ccf6851beb2a3e481541dd8a3c3e3d2fbd513a410eef820221942098212a8184","src/todolist.udl":"1f8a24049c2340b9184e95facfc191ecdcb91541729ae7f20b4625d67685f13c","tests/bindings/test_todolist.kts":"f3d29b48e0193563fc4f131d91ea697f758174dcdb80ea554f233949e575bf55","tests/bindings/test_todolist.py":"8ea1377fe336adaf4cade0fe073ae5825c3b38c63e46b7f4e92b87c0fe57c036","tests/bindings/test_todolist.rb":"e8840eb81477048718a56c5fa02c0fb2e28cf0a598a20c9393ba2262d6ffb89b","tests/bindings/test_todolist.swift":"d1911b85fe0c8c0b42e5421b5af5d7359c9a65bba477d23560eb4b0f52e80662","tests/test_generated_bindings.rs":"46ef1fbedaac0c4867812ef2632a641eab36ab0ee12f5757567dd037aeddcbd3"},"package":null}

View File

@ -1,43 +0,0 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "uniffi-example-todolist"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
publish = false
license = "MPL-2.0"
[lib]
name = "uniffi_todolist"
crate-type = [
"lib",
"cdylib",
]
[dependencies]
once_cell = "1.12"
thiserror = "1.0"
[dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
[dev-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["bindgen-tests"]
[build-dependencies.uniffi]
version = "0.27"
path = "../../uniffi"
features = ["build"]

View File

@ -1,44 +0,0 @@
from todolist import *
todo = TodoList()
entry = TodoEntry(text="Write bindings for strings in records")
todo.add_item("Write python bindings")
assert(todo.get_last() == "Write python bindings")
todo.add_item("Write tests for bindings")
assert(todo.get_last() == "Write tests for bindings")
todo.add_entry(entry)
assert(todo.get_last() == "Write bindings for strings in records")
assert(todo.get_last_entry().text == "Write bindings for strings in records")
todo.add_item("Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣")
assert(todo.get_last() == "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣")
entry2 = TodoEntry(text="Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣")
todo.add_entry(entry2)
assert(todo.get_last_entry().text == "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣")
todo2 = TodoList()
assert(todo != todo2)
assert(todo is not todo2)
assert(get_default_list() is None)
set_default_list(todo)
assert(todo.get_items() == get_default_list().get_items())
todo2.make_default()
assert(todo2.get_items() == get_default_list().get_items())
todo.add_item("Test liveness after being demoted from default")
assert(todo.get_last() == "Test liveness after being demoted from default")
todo2.add_item("Test shared state through local vs default reference")
assert(get_default_list().get_last() == "Test shared state through local vs default reference")

View File

@ -49,32 +49,32 @@ main = [
[geometry]
crate_name = "uniffi_geometry"
udl_file = "third_party/rust/uniffi-example-geometry/src/geometry.udl"
udl_file = "toolkit/components/uniffi-fixtures/geometry/src/geometry.udl"
fixture = true
[arithmetic]
crate_name = "arithmetical"
udl_file = "third_party/rust/uniffi-example-arithmetic/src/arithmetic.udl"
udl_file = "toolkit/components/uniffi-fixtures/arithmetic/src/arithmetic.udl"
fixture = true
[rondpoint]
crate_name = "uniffi_rondpoint"
udl_file = "third_party/rust/uniffi-example-rondpoint/src/rondpoint.udl"
udl_file = "toolkit/components/uniffi-fixtures/rondpoint/src/rondpoint.udl"
fixture = true
[sprites]
crate_name = "uniffi_sprites"
udl_file = "third_party/rust/uniffi-example-sprites/src/sprites.udl"
udl_file = "toolkit/components/uniffi-fixtures/sprites/src/sprites.udl"
fixture = true
[todolist]
crate_name = "uniffi_todolist"
udl_file = "third_party/rust/uniffi-example-todolist/src/todolist.udl"
udl_file = "toolkit/components/uniffi-fixtures/todolist/src/todolist.udl"
fixture = true
[fixture_refcounts]
crate_name = "uniffi_fixture_refcounts"
udl_file = "toolkit/components/uniffi-fixture-refcounts/src/refcounts.udl"
udl_file = "toolkit/components/uniffi-fixtures/refcounts/src/refcounts.udl"
fixture = true
[fixture_refcounts.receiver_thread]
@ -96,10 +96,10 @@ default = "main"
[custom_types]
crate_name = "uniffi_custom_types"
udl_file = "toolkit/components/uniffi-example-custom-types/src/custom-types.udl"
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-fixture-external-types/src/external-types.udl"
udl_file = "toolkit/components/uniffi-fixtures/external-types/src/external-types.udl"
fixture = true

View File

@ -0,0 +1,21 @@
[package]
name = "uniffi-example-arithmetic"
edition = "2021"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false
[lib]
crate-type = ["lib", "cdylib"]
name = "arithmetical"
[dependencies]
uniffi = { workspace = true }
thiserror = "1.0"
[build-dependencies]
uniffi = { workspace = true, features = ["build"] }
[dev-dependencies]
uniffi = { workspace = true, features = ["bindgen-tests"] }

View File

@ -1,8 +1,8 @@
from arithmetic import *
from arithmetic import InternalError, add, div, equal, sub
try:
add(18446744073709551615, 1)
assert(not("Should have thrown a IntegerOverflow exception!"))
assert not ("Should have thrown a IntegerOverflow exception!")
except ArithmeticError.IntegerOverflow:
# It's okay!
pass
@ -12,7 +12,7 @@ assert add(4, 8) == 12
try:
sub(0, 1)
assert(not("Should have thrown a IntegerOverflow exception!"))
assert not ("Should have thrown a IntegerOverflow exception!")
except ArithmeticError.IntegerOverflow:
# It's okay!
pass
@ -28,7 +28,7 @@ except InternalError:
# It's okay!
pass
else:
assert(not("Should have panicked when dividing by zero"))
assert not ("Should have panicked when dividing by zero")
assert equal(2, 2)
assert equal(4, 4)

View File

@ -7,7 +7,7 @@ license = "MPL-2.0"
publish = false
[dependencies]
uniffi-example-geometry = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "d52c5460ae42ecad1e73a5b394ac96d48f4769de" }
uniffi-example-geometry = { path = "../geometry/" }
uniffi = { workspace = true }
thiserror = "1.0"

View File

@ -0,0 +1,20 @@
[package]
name = "uniffi-example-geometry"
edition = "2021"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false
[lib]
crate-type = ["lib", "cdylib"]
name = "uniffi_geometry"
[dependencies]
uniffi = { workspace = true }
[build-dependencies]
uniffi = { workspace = true, features = ["build"] }
[dev-dependencies]
uniffi = { workspace = true, features = ["bindgen-tests"] }

View File

@ -1,4 +1,4 @@
from geometry import *
from geometry import Line, Point, gradient, intersection
ln1 = Line(start=Point(coord_x=0, coord_y=0), end=Point(coord_x=1, coord_y=2))
ln2 = Line(start=Point(coord_x=1, coord_y=1), end=Point(coord_x=2, coord_y=2))

View File

@ -4,19 +4,23 @@
/// This crate exists to test managing the Rust Arc strong counts as JS objects are
/// created/destroyed. See `test_refcounts.js` for how it's used.
use std::sync::{Arc, Mutex};
pub struct SingletonObject;
impl SingletonObject {
pub fn method(&self) { }
pub fn method(&self) {}
}
static SINGLETON: Mutex<Option<Arc<SingletonObject>>> = Mutex::new(None);
pub fn get_singleton() -> Arc<SingletonObject> {
Arc::clone(SINGLETON.lock().unwrap().get_or_insert_with(|| Arc::new(SingletonObject)))
Arc::clone(
SINGLETON
.lock()
.unwrap()
.get_or_insert_with(|| Arc::new(SingletonObject)),
)
}
pub fn get_js_refcount() -> i32 {

View File

@ -0,0 +1,20 @@
[package]
name = "uniffi-example-rondpoint"
edition = "2021"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false
[lib]
crate-type = ["lib", "cdylib"]
name = "uniffi_rondpoint"
[dependencies]
uniffi = { workspace = true }
[build-dependencies]
uniffi = { workspace = true, features = ["build"] }
[dev-dependencies]
uniffi = { workspace = true, features = ["bindgen-tests"] }

View File

@ -1,18 +1,37 @@
import sys
import ctypes
from rondpoint import *
import sys
dico = Dictionnaire(un=Enumeration.DEUX, deux=True, petit_nombre=0, gros_nombre=123456789)
from rondpoint import (
Dictionnaire,
Enumeration,
EnumerationAvecDonnees,
Retourneur,
Stringifier,
copie_carte,
copie_dictionnaire,
copie_enumeration,
copie_enumerations,
switcheroo,
)
dico = Dictionnaire(
un=Enumeration.DEUX, deux=True, petit_nombre=0, gros_nombre=123456789
)
copyDico = copie_dictionnaire(dico)
assert dico == copyDico
assert copie_enumeration(Enumeration.DEUX) == Enumeration.DEUX
assert copie_enumerations([Enumeration.UN, Enumeration.DEUX]) == [Enumeration.UN, Enumeration.DEUX]
assert copie_carte({
"0": EnumerationAvecDonnees.ZERO(),
"1": EnumerationAvecDonnees.UN(1),
"2": EnumerationAvecDonnees.DEUX(2, "deux"),
}) == {
assert copie_enumerations([Enumeration.UN, Enumeration.DEUX]) == [
Enumeration.UN,
Enumeration.DEUX,
]
assert copie_carte(
{
"0": EnumerationAvecDonnees.ZERO(),
"1": EnumerationAvecDonnees.UN(1),
"2": EnumerationAvecDonnees.DEUX(2, "deux"),
}
) == {
"0": EnumerationAvecDonnees.ZERO(),
"1": EnumerationAvecDonnees.UN(1),
"2": EnumerationAvecDonnees.DEUX(2, "deux"),
@ -30,11 +49,13 @@ assert EnumerationAvecDonnees.UN(1) != EnumerationAvecDonnees.UN(2)
# lowering from rust and lifting into python.
rt = Retourneur()
def affirmAllerRetour(vals, identique):
for v in vals:
id_v = identique(v)
assert id_v == v, f"Round-trip failure: {v} => {id_v}"
MIN_I8 = -1 * 2**7
MAX_I8 = 2**7 - 1
MIN_I16 = -1 * 2**15
@ -65,21 +86,29 @@ affirmAllerRetour([0x00000000, 0x12345678, 0xFFFFFFFF], rt.identique_u32)
# Longs
affirmAllerRetour([MIN_I64, -1, 0, 1, MAX_I64], rt.identique_i64)
affirmAllerRetour([0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], rt.identique_u64)
affirmAllerRetour(
[0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], rt.identique_u64
)
# Floats
affirmAllerRetour([0.0, 0.5, 0.25, 1.0, F32_ONE_THIRD], rt.identique_float)
# Doubles
affirmAllerRetour(
[0.0, 0.5, 0.25, 1.0, 1.0 / 3, sys.float_info.max, sys.float_info.min],
rt.identique_double
[0.0, 0.5, 0.25, 1.0, 1.0 / 3, sys.float_info.max, sys.float_info.min],
rt.identique_double,
)
# Strings
affirmAllerRetour(
["", "abc", "été", "ښي لاس ته لوستلو لوستل", "😻emoji 👨👧👦multi-emoji, 🇨🇭a flag, a canal, panama"],
rt.identique_string
[
"",
"abc",
"été",
"ښي لاس ته لوستلو لوستل",
"😻emoji 👨👧👦multi-emoji, 🇨🇭a flag, a canal, panama",
],
rt.identique_string,
)
# Test one way across the FFI.
@ -97,11 +126,13 @@ affirmAllerRetour(
# together, we've shown the correctness of the return leg.
st = Stringifier()
def affirmEnchaine(vals, toString, rustyStringify=lambda v: str(v).lower()):
for v in vals:
str_v = toString(v)
assert rustyStringify(v) == str_v, f"String compare error {v} => {str_v}"
# Test the efficacy of the string transport from rust. If this fails, but everything else
# works, then things are very weird.
wellKnown = st.well_known_string("python")
@ -124,7 +155,10 @@ affirmEnchaine([0x00000000, 0x12345678, 0xFFFFFFFF], st.to_string_u32)
# Longs
affirmEnchaine([MIN_I64, -1, 0, 1, MAX_I64], st.to_string_i64)
affirmEnchaine([0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], st.to_string_u64)
affirmEnchaine(
[0x0000000000000000, 0x1234567890ABCDEF, 0xFFFFFFFFFFFFFFFF], st.to_string_u64
)
# Floats
def rustyFloatToStr(v):
@ -134,13 +168,16 @@ def rustyFloatToStr(v):
return str(int(v))
return str(v)
affirmEnchaine([0.0, 0.5, 0.25, 1.0], st.to_string_float, rustyFloatToStr)
assert st.to_string_float(F32_ONE_THIRD) == "0.33333334" # annoyingly different string repr
assert (
st.to_string_float(F32_ONE_THIRD) == "0.33333334"
) # annoyingly different string repr
# Doubles
# TODO: float_info.max/float_info.min don't stringify-roundtrip properly yet, TBD.
affirmEnchaine(
[0.0, 0.5, 0.25, 1.0, 1.0 / 3],
st.to_string_double,
rustyFloatToStr,
[0.0, 0.5, 0.25, 1.0, 1.0 / 3],
st.to_string_double,
rustyFloatToStr,
)

View File

@ -0,0 +1,20 @@
[package]
name = "uniffi-example-sprites"
edition = "2021"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false
[lib]
crate-type = ["lib", "cdylib"]
name = "uniffi_sprites"
[dependencies]
uniffi = { workspace = true }
[build-dependencies]
uniffi = { workspace = true, features = ["build"] }
[dev-dependencies]
uniffi = { workspace = true, features = ["bindgen-tests"] }

View File

@ -1,4 +1,4 @@
from sprites import *
from sprites import Point, Sprite, Vector
sempty = Sprite(None)
assert sempty.get_position() == Point(x=0, y=0)
@ -14,4 +14,3 @@ assert s.get_position() == Point(x=-3, y=4)
srel = Sprite.new_relative_to(Point(x=0, y=1), Vector(dx=1, dy=1.5))
assert srel.get_position() == Point(x=1, y=2.5)

View File

@ -0,0 +1,22 @@
[package]
name = "uniffi-example-todolist"
edition = "2021"
version = "0.22.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false
[lib]
crate-type = ["lib", "cdylib"]
name = "uniffi_todolist"
[dependencies]
uniffi = { workspace = true }
once_cell = "1.12"
thiserror = "1.0"
[build-dependencies]
uniffi = { workspace = true, features = ["build"] }
[dev-dependencies]
uniffi = { workspace = true, features = ["bindgen-tests"] }

View File

@ -0,0 +1,56 @@
from todolist import TodoEntry, TodoList, get_default_list, set_default_list
todo = TodoList()
entry = TodoEntry(text="Write bindings for strings in records")
todo.add_item("Write python bindings")
assert todo.get_last() == "Write python bindings"
todo.add_item("Write tests for bindings")
assert todo.get_last() == "Write tests for bindings"
todo.add_entry(entry)
assert todo.get_last() == "Write bindings for strings in records"
assert todo.get_last_entry().text == "Write bindings for strings in records"
todo.add_item(
"Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣"
)
assert (
todo.get_last()
== "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣"
)
entry2 = TodoEntry(
text="Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣"
)
todo.add_entry(entry2)
assert (
todo.get_last_entry().text
== "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣"
)
todo2 = TodoList()
assert todo != todo2
assert todo is not todo2
assert get_default_list() is None
set_default_list(todo)
assert todo.get_items() == get_default_list().get_items()
todo2.make_default()
assert todo2.get_items() == get_default_list().get_items()
todo.add_item("Test liveness after being demoted from default")
assert todo.get_last() == "Test liveness after being demoted from default"
todo2.add_item("Test shared state through local vs default reference")
assert (
get_default_list().get_last()
== "Test shared state through local vs default reference"
)

View File

@ -72,15 +72,15 @@ 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 = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "d52c5460ae42ecad1e73a5b394ac96d48f4769de", optional = true }
uniffi-example-geometry = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "d52c5460ae42ecad1e73a5b394ac96d48f4769de", optional = true }
uniffi-example-rondpoint = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "d52c5460ae42ecad1e73a5b394ac96d48f4769de", optional = true }
uniffi-example-sprites = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "d52c5460ae42ecad1e73a5b394ac96d48f4769de", optional = true }
uniffi-example-todolist = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "d52c5460ae42ecad1e73a5b394ac96d48f4769de", optional = true }
uniffi-example-custom-types = { path = "../../../components/uniffi-example-custom-types/", optional = true }
uniffi-fixture-callbacks = { path = "../../../components/uniffi-fixture-callbacks/", optional = true }
uniffi-fixture-external-types = { path = "../../../components/uniffi-fixture-external-types/", optional = true }
uniffi-fixture-refcounts = { path = "../../../components/uniffi-fixture-refcounts/", optional = true }
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" }

View File

@ -16,10 +16,10 @@ trojan-source:
- third_party/rust/clap_builder/src/output/textwrap/core.rs
- third_party/rust/textwrap/src/core.rs
- third_party/rust/icu_provider/src/hello_world.rs
- third_party/rust/uniffi-example-rondpoint/tests/bindings/test_rondpoint.py
- third_party/rust/error-chain/tests/tests.rs
- third_party/rust/unicode-width/src/tests.rs
- security/nss/gtests/mozpkix_gtest/pkixnames_tests.cpp
- toolkit/components/uniffi-fixtures/rondpoint/tests/bindings/test_rondpoint.py
extensions:
- .c
- .cc