Skip to content

Commit

Permalink
Adding support for external fixture/example tests
Browse files Browse the repository at this point in the history
Added code to allow external bindings crates to find the UDL files and
cdylibs for examples/fixtures.  Made a new crate for this, since I
didn't want to pull in `serde` as a dependency for `uniffi`.
Eventually, this can replace `uniffi/testing.rs` and we can remove some
other dependencies from `uniffi` like `cargo_metadata`.

Standardized the crate names for fixtures/examples.  I think we're going
to need to publish these to crates.io eventually.  Make all
fixtures/examples specify `crate-type = ["lib", "cdylib"]`.  The `lib`
part is needed for moz-central to be able to import these crates and
build them into `libxul`.

Added `Cargo.toml` config section that lists external clates for
`ext-types`

We copy the dylibs for external crates as well as our own.  I think this
should fix #1183.
  • Loading branch information
bendk committed Apr 7, 2022
1 parent 2408156 commit d525e71
Show file tree
Hide file tree
Showing 25 changed files with 322 additions and 37 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"uniffi_bindgen",
"uniffi_build",
"uniffi_macros",
"uniffi_testing",
"uniffi",
"examples/arithmetic",
"examples/callbacks",
Expand Down
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 = ["staticlib", "cdylib", "lib"]
crate-type = ["lib", "cdylib"]
name = "arithmetical"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/callbacks/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", "lib"]
crate-type = ["lib", "cdylib"]
name = "callbacks"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "custom-types"
name = "uniffi-example-custom-types"
edition = "2018"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
Expand Down
2 changes: 1 addition & 1 deletion examples/geometry/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 = ["lib", "cdylib"]
name = "uniffi_geometry"

[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", "lib"]
crate-type = ["lib", "cdylib"]
name = "uniffi_rondpoint"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/sprites/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 = ["lib", "cdylib"]
name = "uniffi_sprites"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/todolist/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 = ["staticlib", "cdylib"]
crate-type = ["lib", "cdylib"]
name = "uniffi_todolist"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion fixtures/callbacks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "callbacks"
name = "uniffi-fixture-callbacks"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/coverall/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "coverall"
name = "uniffi-fixture-coverall"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/ext-types/guid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ext-types-guid"
name = "uniffi-fixture-ext-types-guid"
edition = "2018"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
Expand Down
19 changes: 14 additions & 5 deletions fixtures/ext-types/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
[package]
name = "ext-types-lib"
name = "uniffi-fixture-ext-types"
edition = "2018"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false

[package.metadata.uniffi.testing]
external-crates = [
"uniffi-fixture-ext-types-guid",
"uniffi-fixture-ext-types-lib-one",
"uniffi-example-custom-types",
]

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

[dependencies]
Expand All @@ -16,13 +23,15 @@ bytes = "1.0"
uniffi_macros = {path = "../../../uniffi_macros"}
uniffi = {path = "../../../uniffi", features=["builtin-bindgen"]}

uniffi-one = {path = "../uniffi-one"}
ext-types-guid = {path = "../guid"}
uniffi-fixture-ext-types-lib-one = {path = "../uniffi-one"}
uniffi-fixture-ext-types-guid = {path = "../guid"}

# Reuse one of our examples.
custom-types = {path = "../../../examples/custom-types"}
uniffi-example-custom-types = {path = "../../../examples/custom-types"}

url = "2.2"

[build-dependencies]
uniffi_build = {path = "../../../uniffi_build", features=["builtin-bindgen"]}


6 changes: 3 additions & 3 deletions fixtures/ext-types/uniffi-one/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
# TODO: modify the crate name to test non-default names.
name = "uniffi-one"
name = "uniffi-fixture-ext-types-lib-one"
edition = "2018"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false

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

[dependencies]
anyhow = "1"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/external-types/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "external_types_lib"
name = "uniffi-fixture-external-types"
edition = "2018"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false

[lib]
crate-type = ["staticlib", "cdylib", "lib"]
crate-type = ["lib", "cdylib"]
name = "uniffi_external_types_lib"

[dependencies]
Expand Down
6 changes: 3 additions & 3 deletions fixtures/reexport-scaffolding-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ edition = "2021"

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

[dependencies]
callbacks = { path = "../callbacks" }
coverall = { path = "../coverall" }
uniffi-fixture-callbacks = { path = "../callbacks" }
uniffi-fixture-coverall = { path = "../coverall" }
uniffi = { path = "../../uniffi", features=["builtin-bindgen"] }

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "cdylib-dependency"
name = "uniffi-fixture-regression-cdylib-dependency"
version = "0.17.0"
authors = ["king6cong <king6cong@gmail.com>"]
edition = "2018"
publish = false

[lib]
crate-type = ["cdylib"]
crate-type = ["lib", "cdylib"]
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "ffi-crate"
name = "uniffi-fixture-regression-cdylib-dependency-ffi-crate"
edition = "2018"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false

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

[dependencies]
uniffi_macros = {path = "../../../../uniffi_macros"}
uniffi = {path = "../../../../uniffi", features=["builtin-bindgen"]}
cdylib-dependency = {path = "../cdylib-dependency"}
uniffi-fixture-regression-cdylib-dependency = {path = "../cdylib-dependency"}

[build-dependencies]
uniffi_build = {path = "../../../../uniffi_build", features=["builtin-bindgen"]}
4 changes: 2 additions & 2 deletions fixtures/regressions/enum-without-i32-helpers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "i356-enum-without-int-helpers"
name = "uniffi-fixture-regression-i356-enum-without-int-helpers"
edition = "2018"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false

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

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions fixtures/regressions/fully-qualified-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "i1015-fully-qualified-types"
name = "uniffi-fixture-regression-i1015-fully-qualified-types"
edition = "2018"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false

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

[dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "kotlin-experimental-unsigned-types"
name = "uniffi-fixture-regression-kotlin-experimental-unsigned-types"
edition = "2018"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
license = "MPL-2.0"
publish = false

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

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions fixtures/swift-omit-labels/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "omit_argument_labels"
name = "uniffi-fixture-swift-omit-argument-labels"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
edition = "2018"
publish = false

[lib]
crate-type = ["staticlib", "cdylib"]
crate-type = ["lib", "cdylib"]
name = "uniffi_omit_argument_labels"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion fixtures/uniffi-fixture-time/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 = ["staticlib", "cdylib"]
crate-type = ["lib", "cdylib"]
name = "uniffi_chronological"

[dependencies]
Expand Down
11 changes: 11 additions & 0 deletions uniffi_testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "uniffi_testing"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1"
cargo_metadata = "0.13"
lazy_static = "1.4"
serde = "1"
serde_json = "1"
18 changes: 18 additions & 0 deletions uniffi_testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This crate contains helper code for testing bindings. Our general system is to
generate bindings for the libraries from the examples and fixtures
directories, then execute a script that tests the bindings.

Each bindings crate can do this in a different way, but the typical system is:

- Construct a `UniFFITestHelper` struct to assist the process
- Call `UniFFITestHelper.create_out_dir()` to create a temp directory to
store testing files
- Call `UniFFITestHelper.copy_cdylibs_to_out_dir()` to copy the dylib
artifacts for the example/fixture library to the `out_dir`. This is needed
because the bindings code dynamically links to or loads from this library.
- Call `UniFFITestHelper.get_compile_sources()` to iterate over (`udl_path`,
`uniffi_config_path`) pairs and generate the bindings from them. This step
is specific to the bindings language, it may mean creating a .jar file,
compiling a binary, or just copying script files over.
- Execute the test script and check if it succeeds. This step is also
specific to the bindings language.
Loading

0 comments on commit d525e71

Please sign in to comment.