diff --git a/Cargo.lock b/Cargo.lock index f9cb16f2886b..8be190642ffd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,14 +58,14 @@ checksum = "85965b6739a430150bdd138e2374a98af0c3ee0d030b3bb7fc3bddff58d0102e" [[package]] name = "android_logger" -version = "0.10.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9ed09b18365ed295d722d0b5ed59c01b79a826ff2d2a8f73d5ecca8e6fb2f66" +checksum = "b74b7ddf197de32e415d197aa21c1c0cb36e01e4794fd801302280ac7847ee02" dependencies = [ "android_log-sys", - "env_logger 0.8.999", - "lazy_static", + "env_logger 0.9.0", "log", + "once_cell", ] [[package]] @@ -644,13 +644,6 @@ dependencies = [ "serde", ] -[[package]] -name = "cargo_metadata" -version = "0.13.999" -dependencies = [ - "cargo_metadata 0.14.2", -] - [[package]] name = "cargo_metadata" version = "0.14.2" @@ -2277,9 +2270,9 @@ dependencies = [ [[package]] name = "glean" -version = "50.1.0" +version = "50.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0857be0c251ae1fc3b5672237c99f5115a6546cd8b171cb240173098ab5e9629" +checksum = "813fa9059f1a7d9da4fcf6cff6c77e6226fc26f58797d1659d16a8279c4655f2" dependencies = [ "chrono", "crossbeam-channel", @@ -2297,15 +2290,15 @@ dependencies = [ [[package]] name = "glean-core" -version = "50.1.0" +version = "50.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bdfa0e2e6476190b4762c4cdc87c1a7a0347f601864b091cf9ad674a909c68" +checksum = "e5edb2b6cf2938242adda6ece26ac29b2238c693c423331c8a68ce980c348b28" dependencies = [ "android_logger", "bincode", "chrono", "crossbeam-channel", - "env_logger 0.8.999", + "env_logger 0.9.0", "ffi-support", "flate2", "log", @@ -3744,13 +3737,6 @@ dependencies = [ "void", ] -[[package]] -name = "nom" -version = "5.999.999" -dependencies = [ - "nom 6.1.2", -] - [[package]] name = "nom" version = "6.1.2" @@ -5690,13 +5676,14 @@ checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" [[package]] name = "uniffi" -version = "0.18.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0fe14882ae6ea89f31ac922ad8e6f76b3f346f07965791a60ade60cc3bcdd60" +checksum = "bc1de33ad46ce00bc9a31cea44e80ef69175d3a23007335216fe3996880a310d" dependencies = [ "anyhow", "bytes 1.1.0", - "cargo_metadata 0.13.999", + "camino", + "cargo_metadata", "lazy_static", "log", "paste", @@ -5705,15 +5692,18 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.18.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9810482e988792ed22fc6747d872bd32600f7e3bfc11fe93019d155d7e89c" +checksum = "b18e05c55840ddd690ba211f72bb1f2f6ca8c50bfeb7d7211ea5ee60b0f9be07" dependencies = [ "anyhow", "askama", - "cargo_metadata 0.13.999", + "camino", + "cargo_metadata", "clap", + "fs-err", "heck", + "lazy_static", "paste", "serde", "toml 0.5.9", @@ -5722,20 +5712,22 @@ dependencies = [ [[package]] name = "uniffi_build" -version = "0.18.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcb7401cfd8da93541c23a0683c1dab3c782d2a118254536106b0aa4d9b30607" +checksum = "8fff0860625e4e621f0317e5f6ac9e79966262bd86a6cfb2049e8425df23afbd" dependencies = [ "anyhow", + "camino", "uniffi_bindgen", ] [[package]] name = "uniffi_macros" -version = "0.18.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7b60ccb030ef51b0c85eb9ca55f28ff68b82c1a29d2bc0c7053777010af0d3" +checksum = "7956a6c1fb12bff15e537028ea2174f000f90dd4f87912233b276ea782d420f2" dependencies = [ + "camino", "glob", "proc-macro2", "quote", @@ -6093,12 +6085,12 @@ dependencies = [ [[package]] name = "weedle2" -version = "2.0.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a69b360c3d0df7dc1a18124677ee8476576c806418f30a360a6cf6cf4e072a6" +checksum = "5d730d941cf471131c40a64cf2e8a595822009f51e64c05c5afdbc85af155857" dependencies = [ "fs-err", - "nom 5.999.999", + "nom 6.1.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2b499a084142..012a938b13f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -115,13 +115,6 @@ env_logger = { path = "build/rust/env_logger" } # Patch toml 0.4 to 0.5 toml = { path = "build/rust/toml" } -# Patch cargo_metadata 0.13 to 0.14.2 -# FIXME(bug 1772132): To be removed with the next Glean update -cargo_metadata = { path = "build/rust/cargo_metadata" } - -# Patch nom 5 to nom 6 -nom = { path = "build/rust/nom" } - # Patch parking_lot 0.12 down to 0.11, which is compatible for most crates that use it, to avoid # dependencies on windows-sys. parking_lot = { path = "build/rust/parking_lot" } diff --git a/build.gradle b/build.gradle index 813ba09aa3d4..e141a26967f1 100644 --- a/build.gradle +++ b/build.gradle @@ -36,7 +36,7 @@ allprojects { topsrcdir = gradle.mozconfig.topsrcdir topobjdir = gradle.mozconfig.topobjdir - gleanVersion = "50.1.0" + gleanVersion = "50.1.2" if (gleanVersion != getRustVersionFor("glean")) { throw new StopExecutionException("Mismatched Glean version, expected: ${gleanVersion}," + " found ${getRustVersionFor("glean")}") diff --git a/build/rust/cargo_metadata/Cargo.toml b/build/rust/cargo_metadata/Cargo.toml deleted file mode 100644 index 1f8a11d4e521..000000000000 --- a/build/rust/cargo_metadata/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "cargo_metadata" -version = "0.13.999" -edition = "2018" -license = "MPL-2.0" - -[lib] -path = "lib.rs" - -[dependencies] -cargo_metadata = "0.14.2" - -[features] -default = [] -builder = ["cargo_metadata/derive_builder"] diff --git a/build/rust/cargo_metadata/lib.rs b/build/rust/cargo_metadata/lib.rs deleted file mode 100644 index 3a057aa71ebc..000000000000 --- a/build/rust/cargo_metadata/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -/* 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/. */ - -pub use cargo_metadata::*; diff --git a/build/rust/nom/Cargo.toml b/build/rust/nom/Cargo.toml deleted file mode 100644 index e531b35d8c0e..000000000000 --- a/build/rust/nom/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "nom" -version = "5.999.999" -edition = "2018" -license = "MPL-2.0" - -[lib] -path = "lib.rs" - -[dependencies.nom] -version = "6.0" -default-features = false - -[features] -alloc = ["nom/alloc"] -default = ["nom/default"] -lexical = ["nom/lexical-core"] -regexp = ["nom/regex"] -regexp_macros = ["nom/regexp_macros"] -std = ["nom/std"] diff --git a/build/rust/nom/lib.rs b/build/rust/nom/lib.rs deleted file mode 100644 index 3ab7b8e38eee..000000000000 --- a/build/rust/nom/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -/* 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/. */ - -pub use nom::*; - -pub use nom::separated_list0 as separated_list; -pub use nom::separated_list1 as separated_nonempty_list; - -pub type IResult = nom::IResult; diff --git a/gfx/wr/Cargo.lock b/gfx/wr/Cargo.lock index 80f54084c632..26dbe8b6d155 100644 --- a/gfx/wr/Cargo.lock +++ b/gfx/wr/Cargo.lock @@ -31,14 +31,14 @@ checksum = "85965b6739a430150bdd138e2374a98af0c3ee0d030b3bb7fc3bddff58d0102e" [[package]] name = "android_logger" -version = "0.10.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9ed09b18365ed295d722d0b5ed59c01b79a826ff2d2a8f73d5ecca8e6fb2f66" +checksum = "b74b7ddf197de32e415d197aa21c1c0cb36e01e4794fd801302280ac7847ee02" dependencies = [ "android_log-sys", "env_logger", - "lazy_static", "log", + "once_cell", ] [[package]] @@ -236,14 +236,13 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.13.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081e3f0755c1f380c2d010481b6fa2e02973586d5f2b24eebb7a2a1d98b143d8" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", "semver", - "semver-parser", "serde", "serde_json", ] @@ -673,9 +672,9 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" [[package]] name = "env_logger" -version = "0.8.4" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", "humantime", @@ -877,9 +876,9 @@ dependencies = [ [[package]] name = "glean" -version = "50.1.0" +version = "50.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0857be0c251ae1fc3b5672237c99f5115a6546cd8b171cb240173098ab5e9629" +checksum = "813fa9059f1a7d9da4fcf6cff6c77e6226fc26f58797d1659d16a8279c4655f2" dependencies = [ "chrono", "crossbeam-channel", @@ -897,9 +896,9 @@ dependencies = [ [[package]] name = "glean-core" -version = "50.1.0" +version = "50.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bdfa0e2e6476190b4762c4cdc87c1a7a0347f601864b091cf9ad674a909c68" +checksum = "e5edb2b6cf2938242adda6ece26ac29b2238c693c423331c8a68ce980c348b28" dependencies = [ "android_logger", "bincode", @@ -1427,16 +1426,6 @@ dependencies = [ "memoffset", ] -[[package]] -name = "nom" -version = "5.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" -dependencies = [ - "memchr", - "version_check", -] - [[package]] name = "nom" version = "6.2.1" @@ -1670,15 +1659,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - [[package]] name = "pkg-config" version = "0.3.17" @@ -1934,23 +1914,13 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "semver" -version = "0.11.0" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" dependencies = [ - "semver-parser", "serde", ] -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" version = "1.0.137" @@ -2201,12 +2171,6 @@ dependencies = [ "minidl", ] -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" - [[package]] name = "unicase" version = "2.6.0" @@ -2239,12 +2203,13 @@ checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" [[package]] name = "uniffi" -version = "0.18.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0fe14882ae6ea89f31ac922ad8e6f76b3f346f07965791a60ade60cc3bcdd60" +checksum = "bc1de33ad46ce00bc9a31cea44e80ef69175d3a23007335216fe3996880a310d" dependencies = [ "anyhow", "bytes", + "camino", "cargo_metadata", "lazy_static", "log", @@ -2254,15 +2219,18 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.18.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9810482e988792ed22fc6747d872bd32600f7e3bfc11fe93019d155d7e89c" +checksum = "b18e05c55840ddd690ba211f72bb1f2f6ca8c50bfeb7d7211ea5ee60b0f9be07" dependencies = [ "anyhow", "askama", + "camino", "cargo_metadata", "clap", + "fs-err", "heck", + "lazy_static", "paste 1.0.7", "serde", "toml", @@ -2271,20 +2239,22 @@ dependencies = [ [[package]] name = "uniffi_build" -version = "0.18.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcb7401cfd8da93541c23a0683c1dab3c782d2a118254536106b0aa4d9b30607" +checksum = "8fff0860625e4e621f0317e5f6ac9e79966262bd86a6cfb2049e8425df23afbd" dependencies = [ "anyhow", + "camino", "uniffi_bindgen", ] [[package]] name = "uniffi_macros" -version = "0.18.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7b60ccb030ef51b0c85eb9ca55f28ff68b82c1a29d2bc0c7053777010af0d3" +checksum = "7956a6c1fb12bff15e537028ea2174f000f90dd4f87912233b276ea782d420f2" dependencies = [ + "camino", "glob", "proc-macro2", "quote", @@ -2578,12 +2548,12 @@ dependencies = [ [[package]] name = "weedle2" -version = "2.0.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a69b360c3d0df7dc1a18124677ee8476576c806418f30a360a6cf6cf4e072a6" +checksum = "5d730d941cf471131c40a64cf2e8a595822009f51e64c05c5afdbc85af155857" dependencies = [ "fs-err", - "nom 5.1.2", + "nom 6.2.1", ] [[package]] diff --git a/gfx/wr/examples/Cargo.toml b/gfx/wr/examples/Cargo.toml index b164fb9a72fb..245ae8340504 100644 --- a/gfx/wr/examples/Cargo.toml +++ b/gfx/wr/examples/Cargo.toml @@ -55,7 +55,7 @@ debug = ["webrender/capture", "webrender/profiler"] [dependencies] app_units = "0.7" -env_logger = "0.8" +env_logger = "0.9" euclid = "0.22" gleam = "0.13" glutin = "0.28" diff --git a/gfx/wr/webrender/Cargo.toml b/gfx/wr/webrender/Cargo.toml index 6f673b8e1bc6..8acb8fff76fe 100644 --- a/gfx/wr/webrender/Cargo.toml +++ b/gfx/wr/webrender/Cargo.toml @@ -51,7 +51,7 @@ svg_fmt = "0.4" tracy-rs = "0.1.2" derive_more = { version = "0.99", default-features = false, features = ["add_assign"] } etagere = "0.2.6" -glean = "50.1.0" +glean = "50.1.2" fog = { version = "0.1.0", optional = true } swgl = { path = "../swgl", optional = true } topological-sort = "0.1" diff --git a/gfx/wr/wrench/Cargo.toml b/gfx/wr/wrench/Cargo.toml index 7118ce210c6e..5491c9d8d284 100644 --- a/gfx/wr/wrench/Cargo.toml +++ b/gfx/wr/wrench/Cargo.toml @@ -13,7 +13,7 @@ path = "src/main.rs" [dependencies] base64 = "0.13" -env_logger = { version = "0.8.4", optional = true } +env_logger = { version = "0.9", optional = true } gleam = "0.13" glutin = "0.28" clap = { version = "3.1", features = ["yaml"] } @@ -29,7 +29,7 @@ osmesa-src = { version = "0.2", git = "https://github.com/servo/osmesa-src", opt webrender = { path = "../webrender", features = ["capture", "replay", "png", "profiler", "no_static_freetype", "leak_checks"] } winit = "0.26" serde = { version = "1.0", features = ["derive"] } -semver = "0.11.0" +semver = "1.0.12" swgl = { path = "../swgl", optional = true } tracy-rs = "0.1.2" diff --git a/python/sites/mach.txt b/python/sites/mach.txt index 01f4f8c23da3..d8eb608d7496 100644 --- a/python/sites/mach.txt +++ b/python/sites/mach.txt @@ -129,7 +129,7 @@ pth:xpcom/geckoprocesstypes_generator pth:xpcom/idl-parser # glean-sdk may not be installable if a wheel isn't available # and it has to be built from source. -pypi-optional:glean-sdk==50.1.0:telemetry will not be collected +pypi-optional:glean-sdk==50.1.2:telemetry will not be collected # Mach gracefully handles the case where `psutil` is unavailable. # We aren't (yet) able to pin packages in automation, so we have to # support down to the oldest locally-installed version (5.4.2). diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index 940393e788a7..139f48f81331 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -1,6 +1,12 @@ # cargo-vet audits file +[[audits.android_logger]] +who = "Jan-Erik Rediger " +criteria = "safe-to-deploy" +version = "0.11.0" +notes = "Small crate, wrapping Android log functionality, reviewed by janerik" + [[audits.android_system_properties]] who = "Nicolas Silva " criteria = "safe-to-deploy" @@ -57,12 +63,24 @@ criteria = "safe-to-deploy" version = "50.1.0" notes = "Maintained by the Glean team at Mozilla" +[[audits.glean]] +who = "Travis Long " +criteria = "safe-to-deploy" +version = "50.1.2" +notes = "Maintained by the Glean team at Mozilla" + [[audits.glean-core]] who = "Jan-Erik Rediger " criteria = "safe-to-deploy" version = "50.1.0" notes = "Maintained by the Glean team at Mozilla" +[[audits.glean-core]] +who = "Travis Long " +criteria = "safe-to-deploy" +version = "50.1.2" +notes = "Maintained by the Glean team at Mozilla" + [[audits.linked-hash-map]] who = "Aria Beingessner " criteria = "safe-to-deploy" @@ -129,12 +147,42 @@ criteria = "safe-to-deploy" delta = "0.1.19 -> 0.1.20" notes = "I am the author of most of these changes upstream, and prepared the release myself, at which point I looked at the other changes since 0.1.19." +[[audits.uniffi]] +who = "Travis Long " +criteria = "safe-to-deploy" +version = "0.19.3" +notes = "Maintained by the Glean and Application Services teams" + +[[audits.uniffi_bindgen]] +who = "Travis Long " +criteria = "safe-to-deploy" +version = "0.19.3" +notes = "Maintained by the Glean and Application Services teams." + +[[audits.uniffi_build]] +who = "Travis Long " +criteria = "safe-to-deploy" +version = "0.19.3" +notes = "Maintained by the Glean and Application Services teams." + +[[audits.uniffi_macros]] +who = "Travis Long " +criteria = "safe-to-deploy" +version = "0.19.3" +notes = "Maintained by the Glean and Application Services teams." + [[audits.void]] who = "Bobby Holley " criteria = "safe-to-deploy" version = "1.0.2" notes = "Very small crate, just hosts the Void type for easier cross-crate interfacing." +[[audits.weedle2]] +who = "Travis Long " +criteria = "safe-to-deploy" +version = "3.0.0" +notes = "Maintained by the Glean and Application Services teams." + [[audits.webdriver]] who = "Henrik Skupin " criteria = "safe-to-deploy" diff --git a/supply-chain/config.toml b/supply-chain/config.toml index 2c1ef10a8fbe..f585db76e015 100644 --- a/supply-chain/config.toml +++ b/supply-chain/config.toml @@ -177,10 +177,6 @@ criteria = "safe-to-deploy" version = "0.2.0" criteria = "safe-to-deploy" -[[exemptions.android_logger]] -version = "0.10.1" -criteria = "safe-to-deploy" - [[exemptions.anyhow]] version = "1.0.57" criteria = "safe-to-deploy" @@ -1721,22 +1717,6 @@ criteria = "safe-to-deploy" version = "0.2.3" criteria = "safe-to-deploy" -[[exemptions.uniffi]] -version = "0.18.0" -criteria = "safe-to-deploy" - -[[exemptions.uniffi_bindgen]] -version = "0.18.0" -criteria = "safe-to-deploy" - -[[exemptions.uniffi_build]] -version = "0.18.0" -criteria = "safe-to-deploy" - -[[exemptions.uniffi_macros]] -version = "0.18.0" -criteria = "safe-to-deploy" - [[exemptions.unix_path]] version = "1.0.1" criteria = "safe-to-run" @@ -1793,10 +1773,6 @@ criteria = "safe-to-deploy" version = "0.3.9" criteria = "safe-to-deploy" -[[exemptions.weedle2]] -version = "2.0.1" -criteria = "safe-to-deploy" - [[exemptions.wgpu-core]] version = "0.12.0" criteria = "safe-to-deploy" diff --git a/third_party/rust/android_logger/.cargo-checksum.json b/third_party/rust/android_logger/.cargo-checksum.json index 6619831c5375..16a77f479e2c 100644 --- a/third_party/rust/android_logger/.cargo-checksum.json +++ b/third_party/rust/android_logger/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"632df8824223ca0e23352f6b0d103ac994fab57dc51f33c2e6d41c91256e1c4d","LICENSE-APACHE":"99938c5864dd33decb62ab20fd883a9b00181d768ae887a4f19b2d0015c41dc9","LICENSE-MIT":"35043211d1b7be8f7e3f9cad27d981f2189ba9a39d9527b275b3c9740298dfe2","README.md":"7a4f75e61fc014f4dbb907fa947e1983f45993dc2a85104cdb619c0808433f65","src/lib.rs":"bdbd60c12117123c2554b1984949dfbc403d890318a0de637829592f4359de6d","tests/config_log_level.rs":"8aae2c7decbcf12a2a454486c9d4dd4a82a20e01d327c4abf4e9cfded973159d","tests/default_init.rs":"ef18c9ea38687a178623c11acfa3d34d16b9030eaad337ab9ed6a609a2c42ca2","tests/multiple_init.rs":"a6ed4986a758b7b2322c6ad0a18ec99fd06521a6c8767a6622eab2cbf9be601e"},"package":"d9ed09b18365ed295d722d0b5ed59c01b79a826ff2d2a8f73d5ecca8e6fb2f66"} \ No newline at end of file +{"files":{"Cargo.toml":"896268b277c2cd333293139e868abac82c39983de9aa56aead4464c38239b66a","LICENSE-APACHE":"99938c5864dd33decb62ab20fd883a9b00181d768ae887a4f19b2d0015c41dc9","LICENSE-MIT":"35043211d1b7be8f7e3f9cad27d981f2189ba9a39d9527b275b3c9740298dfe2","README.md":"bf2e6227790edeb5959c2be250b71d1a197a3a344dc5fc1638fbb39c73bdfd21","src/lib.rs":"e3a0a6bb68d7bad681a978274b612e77cecc41112b448209a09c96b5b33d029e","tests/config_log_level.rs":"8aae2c7decbcf12a2a454486c9d4dd4a82a20e01d327c4abf4e9cfded973159d","tests/default_init.rs":"ef18c9ea38687a178623c11acfa3d34d16b9030eaad337ab9ed6a609a2c42ca2","tests/multiple_init.rs":"a6ed4986a758b7b2322c6ad0a18ec99fd06521a6c8767a6622eab2cbf9be601e"},"package":"b74b7ddf197de32e415d197aa21c1c0cb36e01e4794fd801302280ac7847ee02"} \ No newline at end of file diff --git a/third_party/rust/android_logger/Cargo.toml b/third_party/rust/android_logger/Cargo.toml index dec0113f159a..02cf115419e3 100644 --- a/third_party/rust/android_logger/Cargo.toml +++ b/third_party/rust/android_logger/Cargo.toml @@ -3,38 +3,46 @@ # 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 +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# 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] name = "android_logger" -version = "0.10.1" +version = "0.11.0" authors = ["The android_logger Developers"] -description = "A logging implementation for `log` which hooks to android log output.\n" +description = """ +A logging implementation for `log` which hooks to android log output. +""" readme = "README.md" -keywords = ["android", "bindings", "log", "logger"] +keywords = [ + "android", + "bindings", + "log", + "logger", +] categories = ["api-bindings"] license = "MIT OR Apache-2.0" repository = "https://github.com/Nercury/android_logger-rs" + [dependencies.android_log-sys] version = "0.2" [dependencies.env_logger] -version = "0.8" +version = "0.9" default-features = false -[dependencies.lazy_static] -version = "1.4" - [dependencies.log] version = "0.4" +[dependencies.once_cell] +version = "1.9" + [features] default = ["regex"] regex = ["env_logger/regex"] + [badges.travis-ci] repository = "Nercury/android_logger-rs" diff --git a/third_party/rust/android_logger/README.md b/third_party/rust/android_logger/README.md index c3b88bf58f17..cc408d65760b 100644 --- a/third_party/rust/android_logger/README.md +++ b/third_party/rust/android_logger/README.md @@ -13,7 +13,7 @@ this library: ```toml [target.'cfg(target_os = "android")'.dependencies] -android_logger = "0.10" +android_logger = "0.11" ``` Example of initialization on activity creation, with log configuration: diff --git a/third_party/rust/android_logger/src/lib.rs b/third_party/rust/android_logger/src/lib.rs index 11a127e4604a..c50ce971cb76 100644 --- a/third_party/rust/android_logger/src/lib.rs +++ b/third_party/rust/android_logger/src/lib.rs @@ -65,15 +65,13 @@ #[cfg(target_os = "android")] extern crate android_log_sys as log_ffi; -#[macro_use] -extern crate lazy_static; +extern crate once_cell; +use once_cell::sync::OnceCell; #[macro_use] extern crate log; extern crate env_logger; -use std::sync::RwLock; - #[cfg(target_os = "android")] use log_ffi::LogPriority; use log::{Level, Log, Metadata, Record}; @@ -105,21 +103,20 @@ fn android_log(_priority: Level, _tag: &CStr, _msg: &CStr) {} /// Underlying android logger backend pub struct AndroidLogger { - config: RwLock, + config: OnceCell, } impl AndroidLogger { /// Create new logger instance from config pub fn new(config: Config) -> AndroidLogger { AndroidLogger { - config: RwLock::new(config), + config: OnceCell::from(config), } } } -lazy_static! { - static ref ANDROID_LOGGER: AndroidLogger = AndroidLogger::default(); -} + +static ANDROID_LOGGER: OnceCell = OnceCell::new(); const LOGGING_TAG_MAX_LEN: usize = 23; const LOGGING_MSG_MAX_LEN: usize = 4000; @@ -128,7 +125,7 @@ impl Default for AndroidLogger { /// Create a new logger with default config fn default() -> AndroidLogger { AndroidLogger { - config: RwLock::new(Config::default()), + config: OnceCell::from(Config::default()), } } } @@ -140,8 +137,7 @@ impl Log for AndroidLogger { fn log(&self, record: &Record) { let config = self.config - .read() - .expect("failed to acquire android_log filter lock for read"); + .get_or_init(Config::default); if !config.filter_matches(record) { return; @@ -155,7 +151,7 @@ impl Log for AndroidLogger { // If no tag was specified, use module name let custom_tag = &config.tag; - let tag = custom_tag.as_ref().map(|s| s.as_bytes()).unwrap_or(module_path.as_bytes()); + let tag = custom_tag.as_ref().map(|s| s.as_bytes()).unwrap_or_else(|| module_path.as_bytes()); // truncate the tag here to fit into LOGGING_TAG_MAX_LEN self.fill_tag_bytes(&mut tag_bytes, tag); @@ -206,6 +202,7 @@ impl AndroidLogger { } /// Filter for android logger. +#[derive(Default)] pub struct Config { log_level: Option, filter: Option, @@ -213,17 +210,6 @@ pub struct Config { custom_format: Option, } -impl Default for Config { - fn default() -> Self { - Config { - log_level: None, - filter: None, - tag: None, - custom_format: None, - } - } -} - impl Config { /// Change the minimum log level. /// @@ -236,7 +222,7 @@ impl Config { fn filter_matches(&self, record: &Record) -> bool { if let Some(ref filter) = self.filter { - filter.matches(&record) + filter.matches(record) } else { true } @@ -365,7 +351,7 @@ impl<'a> PlatformLogWriter<'a> { /// Copy `len` bytes from `index` position to starting position. fn copy_bytes_to_start(&mut self, index: usize, len: usize) { - let src = unsafe { self.buffer.as_ptr().offset(index as isize) }; + let src = unsafe { self.buffer.as_ptr().add(index) }; let dst = self.buffer.as_mut_ptr(); unsafe { ptr::copy(src, dst, len) }; } @@ -423,7 +409,7 @@ impl<'a> fmt::Write for PlatformLogWriter<'a> { /// This action does not require initialization. However, without initialization it /// will use the default filter, which allows all logs. pub fn log(record: &Record) { - ANDROID_LOGGER.log(record) + ANDROID_LOGGER.get_or_init(AndroidLogger::default).log(record) } /// Initializes the global logger with an android logger. @@ -434,16 +420,13 @@ pub fn log(record: &Record) { /// It is ok to call this at the activity creation, and it will be /// repeatedly called on every lifecycle restart (i.e. screen rotation). pub fn init_once(config: Config) { - if let Err(err) = log::set_logger(&*ANDROID_LOGGER) { + let log_level = config.log_level; + let logger = ANDROID_LOGGER.get_or_init(|| AndroidLogger::new(config)); + + if let Err(err) = log::set_logger(logger) { debug!("android_logger: log::set_logger failed: {}", err); - } else { - if let Some(level) = config.log_level { - log::set_max_level(level.to_level_filter()); - } - *ANDROID_LOGGER - .config - .write() - .expect("failed to acquire android_log filter lock for write") = config; + } else if let Some(level) = log_level { + log::set_max_level(level.to_level_filter()); } } @@ -531,7 +514,7 @@ mod tests { fn platform_log_writer_init_values() { let tag = CStr::from_bytes_with_nul(b"tag\0").unwrap(); - let writer = PlatformLogWriter::new(Level::Warn, &tag); + let writer = PlatformLogWriter::new(Level::Warn, tag); assert_eq!(writer.tag, tag); // Android uses LogPriority instead, which doesn't implement equality checks @@ -630,6 +613,6 @@ mod tests { } fn get_tag_writer() -> PlatformLogWriter<'static> { - PlatformLogWriter::new(Level::Warn, &CStr::from_bytes_with_nul(b"tag\0").unwrap()) + PlatformLogWriter::new(Level::Warn, CStr::from_bytes_with_nul(b"tag\0").unwrap()) } } diff --git a/third_party/rust/glean-core/.cargo-checksum.json b/third_party/rust/glean-core/.cargo-checksum.json index 7f7ab5c0ecc0..b12cb9eb1fab 100644 --- a/third_party/rust/glean-core/.cargo-checksum.json +++ b/third_party/rust/glean-core/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"6f7fd23744ab14bdca9eeb5a5e57be09c69a286fec523d68965ecffd77e1e96c","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"026495898699b54608eb4ec16074ffafc57920d80ccb59961c501a1ea28c9985","build.rs":"7dc87a0329262e0954334d1c3959bf4c9937d82f95359fba0b318fd45dd18f1a","src/common_metric_data.rs":"e9f3cc2066487b1feeaae47b7dd130ed77462649871985935ac37491411725c8","src/core/mod.rs":"1126371ab0839c54068c8019af5096be777c3ed08d1e76e32888daed7ce6bc10","src/core_metrics.rs":"8962f9f32ccc0583bc8f635b2c9442712506f3f8912de52b272425d9c6d359ad","src/coverage.rs":"49613fd310bd24d779472720975fbe6c97ec370a95eb55f10afa43f67539c942","src/database/mod.rs":"098b8270709349b81a9086f5a8c4fe8f3a6347700ea8a70c08c8d9889a0d5f62","src/debug.rs":"90158cc5d488ba67b60d06647e54e59a1d7bdeb906087e4fe4cfab4373c1cc6c","src/dispatcher/global.rs":"03ef09170d0b7c654ac0b8dc555e2f6aad0cc10a5c1a73720007896f4faf48cb","src/dispatcher/mod.rs":"7d14f46e818508dd568922e5b59b1935255d7bba9fd381a7442eff62d83f61fd","src/error.rs":"97172a791efdf8b791a04ae7961085fbef4391b313ff3ffb24e9381f2901fccc","src/error_recording.rs":"980262e60d8a4430edc319bdd23243382b986562437515f2c7955b5c5a7af4ef","src/event_database/mod.rs":"95d665a039236ede25dd479b19f0ddc32c0dd79cef2fbcc2ef3bab1540680276","src/fd_logger.rs":"0c9def6fa53db1a2ab93c85795f8a7df57797bcfd3978146923e151752e291a6","src/glean.udl":"3db04f22ec66284f20a927fa019c5941f20db370259a8993804893133d3078c0","src/glean_metrics.rs":"9414fb1453d19f6832df33e4c6ef7383d62203e47026bf5bc9552b083101ddd1","src/histogram/exponential.rs":"389d48bab03f7229445ee4d4c8a4c49f6b43303f658dc954da75142f3c040dc6","src/histogram/functional.rs":"1a63a305b48bcef7bc38136b40d916df4bb8f098dc602514ada54a9b091f6951","src/histogram/linear.rs":"5642c8983c3c1ce9b69c6ac99133c8ed5e67abe2398c5dbcf67e69d66880f4ca","src/histogram/mod.rs":"11e5d3b6440a33a3e5544d0e03ffd69fa2fdcabe603ad75e0327f3ed548e8ce3","src/internal_metrics.rs":"b3008db72c5358d0d7a5f5b6604a3d933ee4f1bf9e9855895ca205b82bd429c8","src/internal_pings.rs":"6468514acda555103f271b8ff80ce455019eb2989b2602d2a3a631516f281f3f","src/lib.rs":"ea09d42ccda4c83d41654d95594ce436bd1caf4d849a3ec6d96b7ae5dc4dc0f1","src/lib_unit_tests.rs":"975b59dca5751a548cc98c6b51e05f888c1275e1d4edd83061b5b60769e4fe0c","src/metrics/boolean.rs":"c0c351ba62dba081f05867402343cb71b23fd6462c6101e7bae460dbf7d2021c","src/metrics/counter.rs":"798bbb83551c2e8e7c22610816a0e6ecfd43173e2263acc33b6db950fb325244","src/metrics/custom_distribution.rs":"945bc8e4a94c14b0151dfbdd2c0d746848a9aceac03bccbc9efe3901385b2f70","src/metrics/datetime.rs":"fee869f6c338b4241b173946f2931e4035277e76991a429b7136baabfe4f9212","src/metrics/denominator.rs":"1bdb4c13b051824f9d04b589826d679e5e28c43a6fe5e95c9f984bec90a9dbc9","src/metrics/event.rs":"9cec5e64f431052c970ef079bd55f86fd031d071d7e9ee674ad5aac1f111b5c2","src/metrics/experiment.rs":"89d41f0e3e03f50838ed5a518babf0b54db3eccb1fbee391ec37a48fc018cc92","src/metrics/labeled.rs":"69536ae68dcd199e16b83c6c3ba1c150e7c373682334acd7b360151431ff8a34","src/metrics/memory_distribution.rs":"f92cc3855c20fe7b672fded06a8bcfe4fda1a6b16ebdca83755b335fdefeed82","src/metrics/memory_unit.rs":"d7a678e5242febd021283b30c0099a9e62729944816a3f17d2d91e2808bc0570","src/metrics/mod.rs":"cfd8d157b039bd124716c2c6a0fd7a023275536bee3300803f7de94203c32933","src/metrics/numerator.rs":"6866f36cb788922d32e1be5158ca7ccc0f0959a677b66910c2fc516d968011cd","src/metrics/ping.rs":"b491ec663f8b4528b600e80731f9ed292d0515375c70886e4f6440ee065ec549","src/metrics/quantity.rs":"c271c78b0560fbae2b775a0d59252556f0f9afaea0a7465420dbaa13f2e46a81","src/metrics/rate.rs":"8cde98d1433fb4ee38bffde47c5904711dde83ad6c5bae1417405e384eaca0dc","src/metrics/recorded_experiment.rs":"17d4e9c874a87ad995700c2fe9eb5778ae7019476955cfedcf9b1e18c232df25","src/metrics/string.rs":"d09164c372f2fae46b1de18851db3de822a69a348969a24a146ed732c6d1c4a9","src/metrics/string_list.rs":"f82c59eb408fc7d5fb2e925568c7103fd203806e9c01210229c1fa592b8c1a6c","src/metrics/text.rs":"59295859a801fa09b724dae2fa4f9ba8de38a4b2cb05249c6c49980ef41565d6","src/metrics/time_unit.rs":"9bb3f6c03b1d385008b254f36ed35daf22f9a6fa2d18e007c9b70aac767cde50","src/metrics/timespan.rs":"a4831b27ad43ed47afa3d6e03afd0c642cf3dc4621092e89539f6cce8a530fd4","src/metrics/timing_distribution.rs":"aad258dc8d7530461b478e92f0587bf03bab5ad723dca86df92095db4ad320e6","src/metrics/url.rs":"f4ddda46fb9a2560a1c074addc80a7087888c1a042fb600ee4279769d0c93db4","src/metrics/uuid.rs":"3e6e2bc69ed7e37a7784eeeda6606dba96f2e5a529cb94f40f5e352778a5e586","src/ping/mod.rs":"83cc8b555fb611ef8b60eff3cb3928a38191596c10e39ed69dfffc9e4139ff3f","src/scheduler.rs":"1a9c79570dc0945ed6017d20231a398199e84240c866ddc0da6d95edb3859cf8","src/storage/mod.rs":"3fd0fb9b743a1ec12b8b1fd07f1a99594db030ec47ab4afe255923e6d11a636a","src/system.rs":"a76ff0998840ab4ad00dfd52dbad6b1558bb4cdcf613fe3725969c9a90e1bfe8","src/traits/boolean.rs":"799804d6babb49066fb0047cc5302c9fe0b428cd16937763ed94a7a0f6a8c1d2","src/traits/counter.rs":"631208036059d498a4485c74c2a80c24a5f13bffeb1053bdf5cce06af0e9d361","src/traits/custom_distribution.rs":"1b3ffda6e857bfa8ad5be412e88f3d9706ededf5a86407364ae19a81f06ef798","src/traits/datetime.rs":"2f4b9e64161c15c912b6a915045dd9840f76229d144a4d1542c54eb4f3b3406b","src/traits/event.rs":"4d917327a2fcf0cb9a1bd7fc309cf01ba90b94afa2cb827d4708d7c276e4ba6d","src/traits/labeled.rs":"7f3281fc0a1a745238e7e260463f397dfa61717408fe9d260dc9767d9c659e52","src/traits/memory_distribution.rs":"0b72ffde68eb97f01a57afbc5c6109565ec9435561984d34696622bf5a57d559","src/traits/mod.rs":"d0aa19a7cd97326fd2e026635406a5a9403953ced4954443a2bcbca32d868554","src/traits/numerator.rs":"3c33c4070b208872ea2924adc0b7b399be22c37713e5a8434f740ec3e822e715","src/traits/ping.rs":"8831c106c03afeb458b0b028fa1ce61f056ebf8e82bc0a171a1bff255d920748","src/traits/quantity.rs":"087d7a4b58f0eb7c766a0202dcf38a52d172ce4edf626211ffe5d94ed02ae754","src/traits/rate.rs":"edd21b6528100d358d4241db793b53d478485563bfe4ac92cf78adf5917ecc55","src/traits/string.rs":"48e5623c7db59b8e6454fbc7fb6e2395f808c9a0fa721d7c07b72abb171eb1ad","src/traits/string_list.rs":"5d5773d5a130323dd82ca95f4ecdccdd6b237afe2eadf8655363bd6b7e8508c1","src/traits/text.rs":"0d7afc7ca0bc51b2f959b24cd4416e2fb153e43a95346efc78458d472b8cb251","src/traits/timespan.rs":"29251233847c5cdd200a61472132c62ded27fe2c13835b09424384bf144d82db","src/traits/timing_distribution.rs":"5e619d445e6ef3f19ca69bcdfe02d19b150c5a46855d195703b6d2f55e538636","src/traits/url.rs":"a01331623af4fa8af6e71becffff60060832bef5e48a15df6dc23b41225f689e","src/traits/uuid.rs":"bd78515611ba406d8b1bda35a9fe30c317512a9afcea7c5dece8fced7d410a92","src/upload/directory.rs":"8b2fd5ea68e4d645891b70e095d0a4976d75d74e79fd84115e030b7a66141f87","src/upload/mod.rs":"c2be82aae712d68a0fc4c37c781819fddcb6c26c825a9dbad64a86eb6d5fdfc1","src/upload/policy.rs":"c250957a37783e74af8002cd80ba06ef9780a389fb0f61b8b665b79688f0a360","src/upload/request.rs":"13493fb509f540c1723a0fe47daba442e7f0e470135a399ad691e7f59584b49d","src/upload/result.rs":"7f0b5886716e7a6510fccec37e342d4702bc0aa6dc4f6d4b16a44b6e06998296","src/util.rs":"c1ecfc1037406d5b10aa185dac4ae28c6a8de603958a5b4969bb1bf130759985","tests/boolean.rs":"76d6014ff108cb6514d9bceb1b2b14749a55b09921f4595a5e30f1bd3546e9f0","tests/common/mod.rs":"a04c2cdf0b0af527a976b9f3def89b29c84f95d9c30a6538d0f297cb7c8c629e","tests/counter.rs":"0146c560be554c56af9612409b8cbeae57e20f52cca6cc2f4c615572e4449c3a","tests/custom_distribution.rs":"32e78ae7ad60a1c583e93a7293788a17004b4d41aad7e358f72a85e51c0cbfd8","tests/datetime.rs":"a991dee34e21a20df518a57b49f4476060b991ec00d519aa4341341085e4d0b3","tests/event.rs":"9a09f701e1b4557bf253aff536a92768e1f6459b04e01ea5c49aeac301dc126e","tests/labeled.rs":"0160023ca3695e9f417cbf09219d45551030275ac236d7f3f7fbe3aaa96299ab","tests/memory_distribution.rs":"aebb81f928874b692775513bdd56cbd9a75459374c4315ce68df40c65b206a0f","tests/ping.rs":"a831cf5de86505c1f5c357898cca71a83cd8f10e68acf8e43f3b76a77fe4fefc","tests/ping_maker.rs":"61b49380f8865b626643879079867571377950aea4701da0665e63cbe88083e0","tests/quantity.rs":"f51e9081b6da0f9e83f7d37c15ae5549c7d56be237894be35709984f0641f366","tests/rate.rs":"4ab4ede8c20fabba82f51ab806e1f5a3ddce5c43b11acc2f3022b3c95882b5b2","tests/storage.rs":"ed65b92d37eed873738717d95f1e70e93adf4ecd8db55f2e52f383e1e71ab3f3","tests/string.rs":"afae8a46ea94639d199f9bf043c571013bba43fd6aef3a2b7316b58fa8563f36","tests/string_list.rs":"e9f1797d09fccd1c326fb145fe692c1197eb3b84ec8afea1face17a16f520d32","tests/text.rs":"2a8c21a3f7e056cff2ab954418f9cf826240be968db15736d4760608ce87ea3b","tests/timespan.rs":"c633c05698c81ea30ef9105c0f8a1149e17925de9d3b8bc370f7ded0674563c7","tests/timing_distribution.rs":"8a308785f6d9330ddbbabc2e7128c8c883de92b8542d37e78bd87c6ff78e319f","tests/uuid.rs":"84ae2378d586219a37b0ae70d3672b79d8f8baeccd5290194f27705f9ee28bdc","uniffi.toml":"6ddc98b686b0925a81abd9d1c769e5c98ac29771b210a1c535931a46dec9a8e3"},"package":"f1bdfa0e2e6476190b4762c4cdc87c1a7a0347f601864b091cf9ad674a909c68"} \ No newline at end of file +{"files":{"Cargo.toml":"04b3598d79949960cc862132f18de5b37c0b9f13bf5dd7954e55045e5a77dc34","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"026495898699b54608eb4ec16074ffafc57920d80ccb59961c501a1ea28c9985","build.rs":"7dc87a0329262e0954334d1c3959bf4c9937d82f95359fba0b318fd45dd18f1a","src/common_metric_data.rs":"e9f3cc2066487b1feeaae47b7dd130ed77462649871985935ac37491411725c8","src/core/mod.rs":"1126371ab0839c54068c8019af5096be777c3ed08d1e76e32888daed7ce6bc10","src/core_metrics.rs":"8962f9f32ccc0583bc8f635b2c9442712506f3f8912de52b272425d9c6d359ad","src/coverage.rs":"49613fd310bd24d779472720975fbe6c97ec370a95eb55f10afa43f67539c942","src/database/mod.rs":"098b8270709349b81a9086f5a8c4fe8f3a6347700ea8a70c08c8d9889a0d5f62","src/debug.rs":"90158cc5d488ba67b60d06647e54e59a1d7bdeb906087e4fe4cfab4373c1cc6c","src/dispatcher/global.rs":"03ef09170d0b7c654ac0b8dc555e2f6aad0cc10a5c1a73720007896f4faf48cb","src/dispatcher/mod.rs":"f9d7f329f86b75b5af573a07271ff4daef22abd4d6ce1c7241fe5e92a3babfe5","src/error.rs":"97172a791efdf8b791a04ae7961085fbef4391b313ff3ffb24e9381f2901fccc","src/error_recording.rs":"443c8c0162cc03ea432ce08f3d66b9859a556191abcd2b3d2e3dac25c374dc72","src/event_database/mod.rs":"95d665a039236ede25dd479b19f0ddc32c0dd79cef2fbcc2ef3bab1540680276","src/fd_logger.rs":"0c9def6fa53db1a2ab93c85795f8a7df57797bcfd3978146923e151752e291a6","src/glean.udl":"3db04f22ec66284f20a927fa019c5941f20db370259a8993804893133d3078c0","src/glean_metrics.rs":"9414fb1453d19f6832df33e4c6ef7383d62203e47026bf5bc9552b083101ddd1","src/histogram/exponential.rs":"58bb1770bae45770d92995515d328eb50a7e78726224f779446ae7d1632a6a3e","src/histogram/functional.rs":"1a63a305b48bcef7bc38136b40d916df4bb8f098dc602514ada54a9b091f6951","src/histogram/linear.rs":"4342a1733175d7f97b2b41adb18100537c206100c9fccb5bd13bd782c9cb3c9a","src/histogram/mod.rs":"eeb7aff80806ab76cdce101dc08887b5552f8b4bdf64683f64f767e0f06a889d","src/internal_metrics.rs":"b3008db72c5358d0d7a5f5b6604a3d933ee4f1bf9e9855895ca205b82bd429c8","src/internal_pings.rs":"6468514acda555103f271b8ff80ce455019eb2989b2602d2a3a631516f281f3f","src/lib.rs":"0a8ed7c36264570efb80d0245efa99fb282923e19060757b4e0e6005a055c933","src/lib_unit_tests.rs":"975b59dca5751a548cc98c6b51e05f888c1275e1d4edd83061b5b60769e4fe0c","src/metrics/boolean.rs":"c0c351ba62dba081f05867402343cb71b23fd6462c6101e7bae460dbf7d2021c","src/metrics/counter.rs":"798bbb83551c2e8e7c22610816a0e6ecfd43173e2263acc33b6db950fb325244","src/metrics/custom_distribution.rs":"945bc8e4a94c14b0151dfbdd2c0d746848a9aceac03bccbc9efe3901385b2f70","src/metrics/datetime.rs":"fee869f6c338b4241b173946f2931e4035277e76991a429b7136baabfe4f9212","src/metrics/denominator.rs":"1bdb4c13b051824f9d04b589826d679e5e28c43a6fe5e95c9f984bec90a9dbc9","src/metrics/event.rs":"9cec5e64f431052c970ef079bd55f86fd031d071d7e9ee674ad5aac1f111b5c2","src/metrics/experiment.rs":"89d41f0e3e03f50838ed5a518babf0b54db3eccb1fbee391ec37a48fc018cc92","src/metrics/labeled.rs":"69536ae68dcd199e16b83c6c3ba1c150e7c373682334acd7b360151431ff8a34","src/metrics/memory_distribution.rs":"f92cc3855c20fe7b672fded06a8bcfe4fda1a6b16ebdca83755b335fdefeed82","src/metrics/memory_unit.rs":"d7a678e5242febd021283b30c0099a9e62729944816a3f17d2d91e2808bc0570","src/metrics/mod.rs":"cfd8d157b039bd124716c2c6a0fd7a023275536bee3300803f7de94203c32933","src/metrics/numerator.rs":"6866f36cb788922d32e1be5158ca7ccc0f0959a677b66910c2fc516d968011cd","src/metrics/ping.rs":"b491ec663f8b4528b600e80731f9ed292d0515375c70886e4f6440ee065ec549","src/metrics/quantity.rs":"c271c78b0560fbae2b775a0d59252556f0f9afaea0a7465420dbaa13f2e46a81","src/metrics/rate.rs":"8cde98d1433fb4ee38bffde47c5904711dde83ad6c5bae1417405e384eaca0dc","src/metrics/recorded_experiment.rs":"33958abee79d8b55dec4cb5d20742640423713010f76314075cefde18b5c118a","src/metrics/string.rs":"d09164c372f2fae46b1de18851db3de822a69a348969a24a146ed732c6d1c4a9","src/metrics/string_list.rs":"f82c59eb408fc7d5fb2e925568c7103fd203806e9c01210229c1fa592b8c1a6c","src/metrics/text.rs":"59295859a801fa09b724dae2fa4f9ba8de38a4b2cb05249c6c49980ef41565d6","src/metrics/time_unit.rs":"b7578010c6270a45b30342b59189a862b2ede9dd24e9afae3e90fa6b970b3d24","src/metrics/timespan.rs":"a4831b27ad43ed47afa3d6e03afd0c642cf3dc4621092e89539f6cce8a530fd4","src/metrics/timing_distribution.rs":"aad258dc8d7530461b478e92f0587bf03bab5ad723dca86df92095db4ad320e6","src/metrics/url.rs":"f4ddda46fb9a2560a1c074addc80a7087888c1a042fb600ee4279769d0c93db4","src/metrics/uuid.rs":"3e6e2bc69ed7e37a7784eeeda6606dba96f2e5a529cb94f40f5e352778a5e586","src/ping/mod.rs":"83cc8b555fb611ef8b60eff3cb3928a38191596c10e39ed69dfffc9e4139ff3f","src/scheduler.rs":"1a9c79570dc0945ed6017d20231a398199e84240c866ddc0da6d95edb3859cf8","src/storage/mod.rs":"3fd0fb9b743a1ec12b8b1fd07f1a99594db030ec47ab4afe255923e6d11a636a","src/system.rs":"a76ff0998840ab4ad00dfd52dbad6b1558bb4cdcf613fe3725969c9a90e1bfe8","src/traits/boolean.rs":"799804d6babb49066fb0047cc5302c9fe0b428cd16937763ed94a7a0f6a8c1d2","src/traits/counter.rs":"631208036059d498a4485c74c2a80c24a5f13bffeb1053bdf5cce06af0e9d361","src/traits/custom_distribution.rs":"1b3ffda6e857bfa8ad5be412e88f3d9706ededf5a86407364ae19a81f06ef798","src/traits/datetime.rs":"2f4b9e64161c15c912b6a915045dd9840f76229d144a4d1542c54eb4f3b3406b","src/traits/event.rs":"4d917327a2fcf0cb9a1bd7fc309cf01ba90b94afa2cb827d4708d7c276e4ba6d","src/traits/labeled.rs":"7f3281fc0a1a745238e7e260463f397dfa61717408fe9d260dc9767d9c659e52","src/traits/memory_distribution.rs":"0b72ffde68eb97f01a57afbc5c6109565ec9435561984d34696622bf5a57d559","src/traits/mod.rs":"d0aa19a7cd97326fd2e026635406a5a9403953ced4954443a2bcbca32d868554","src/traits/numerator.rs":"3c33c4070b208872ea2924adc0b7b399be22c37713e5a8434f740ec3e822e715","src/traits/ping.rs":"8831c106c03afeb458b0b028fa1ce61f056ebf8e82bc0a171a1bff255d920748","src/traits/quantity.rs":"087d7a4b58f0eb7c766a0202dcf38a52d172ce4edf626211ffe5d94ed02ae754","src/traits/rate.rs":"edd21b6528100d358d4241db793b53d478485563bfe4ac92cf78adf5917ecc55","src/traits/string.rs":"48e5623c7db59b8e6454fbc7fb6e2395f808c9a0fa721d7c07b72abb171eb1ad","src/traits/string_list.rs":"5d5773d5a130323dd82ca95f4ecdccdd6b237afe2eadf8655363bd6b7e8508c1","src/traits/text.rs":"0d7afc7ca0bc51b2f959b24cd4416e2fb153e43a95346efc78458d472b8cb251","src/traits/timespan.rs":"29251233847c5cdd200a61472132c62ded27fe2c13835b09424384bf144d82db","src/traits/timing_distribution.rs":"5e619d445e6ef3f19ca69bcdfe02d19b150c5a46855d195703b6d2f55e538636","src/traits/url.rs":"a01331623af4fa8af6e71becffff60060832bef5e48a15df6dc23b41225f689e","src/traits/uuid.rs":"bd78515611ba406d8b1bda35a9fe30c317512a9afcea7c5dece8fced7d410a92","src/upload/directory.rs":"8b2fd5ea68e4d645891b70e095d0a4976d75d74e79fd84115e030b7a66141f87","src/upload/mod.rs":"8913e9e4eccbd8d0e075575992c1adcfc1217ae08cd642169791641e235b4a07","src/upload/policy.rs":"c250957a37783e74af8002cd80ba06ef9780a389fb0f61b8b665b79688f0a360","src/upload/request.rs":"a57fd6780c4d1411a64b0e2cb981310be87896f047db990f804fdb47d61c0a21","src/upload/result.rs":"7f0b5886716e7a6510fccec37e342d4702bc0aa6dc4f6d4b16a44b6e06998296","src/util.rs":"c1ecfc1037406d5b10aa185dac4ae28c6a8de603958a5b4969bb1bf130759985","tests/boolean.rs":"76d6014ff108cb6514d9bceb1b2b14749a55b09921f4595a5e30f1bd3546e9f0","tests/common/mod.rs":"a04c2cdf0b0af527a976b9f3def89b29c84f95d9c30a6538d0f297cb7c8c629e","tests/counter.rs":"0146c560be554c56af9612409b8cbeae57e20f52cca6cc2f4c615572e4449c3a","tests/custom_distribution.rs":"32e78ae7ad60a1c583e93a7293788a17004b4d41aad7e358f72a85e51c0cbfd8","tests/datetime.rs":"a991dee34e21a20df518a57b49f4476060b991ec00d519aa4341341085e4d0b3","tests/event.rs":"9a09f701e1b4557bf253aff536a92768e1f6459b04e01ea5c49aeac301dc126e","tests/labeled.rs":"0160023ca3695e9f417cbf09219d45551030275ac236d7f3f7fbe3aaa96299ab","tests/memory_distribution.rs":"aebb81f928874b692775513bdd56cbd9a75459374c4315ce68df40c65b206a0f","tests/ping.rs":"a831cf5de86505c1f5c357898cca71a83cd8f10e68acf8e43f3b76a77fe4fefc","tests/ping_maker.rs":"61b49380f8865b626643879079867571377950aea4701da0665e63cbe88083e0","tests/quantity.rs":"f51e9081b6da0f9e83f7d37c15ae5549c7d56be237894be35709984f0641f366","tests/rate.rs":"4ab4ede8c20fabba82f51ab806e1f5a3ddce5c43b11acc2f3022b3c95882b5b2","tests/storage.rs":"ed65b92d37eed873738717d95f1e70e93adf4ecd8db55f2e52f383e1e71ab3f3","tests/string.rs":"afae8a46ea94639d199f9bf043c571013bba43fd6aef3a2b7316b58fa8563f36","tests/string_list.rs":"e9f1797d09fccd1c326fb145fe692c1197eb3b84ec8afea1face17a16f520d32","tests/text.rs":"2a8c21a3f7e056cff2ab954418f9cf826240be968db15736d4760608ce87ea3b","tests/timespan.rs":"c633c05698c81ea30ef9105c0f8a1149e17925de9d3b8bc370f7ded0674563c7","tests/timing_distribution.rs":"8a308785f6d9330ddbbabc2e7128c8c883de92b8542d37e78bd87c6ff78e319f","tests/uuid.rs":"84ae2378d586219a37b0ae70d3672b79d8f8baeccd5290194f27705f9ee28bdc","uniffi.toml":"6ddc98b686b0925a81abd9d1c769e5c98ac29771b210a1c535931a46dec9a8e3"},"package":"e5edb2b6cf2938242adda6ece26ac29b2238c693c423331c8a68ce980c348b28"} \ No newline at end of file diff --git a/third_party/rust/glean-core/Cargo.toml b/third_party/rust/glean-core/Cargo.toml index 3853bd96f4c1..3cd288544a7a 100644 --- a/third_party/rust/glean-core/Cargo.toml +++ b/third_party/rust/glean-core/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2018" name = "glean-core" -version = "50.1.0" +version = "50.1.2" authors = [ "Jan-Erik Rediger ", "The Glean Team ", @@ -76,10 +76,10 @@ version = "1.0.4" version = "0.1.40" [dependencies.uniffi] -version = "0.18.0" +version = "0.19.3" [dependencies.uniffi_macros] -version = "0.18.0" +version = "0.19.3" [dependencies.uuid] version = "0.8.1" @@ -95,7 +95,7 @@ version = "0.1.0" version = "0.1.12" [dev-dependencies.env_logger] -version = "0.8.0" +version = "0.9.0" features = [ "termcolor", "atty", @@ -110,14 +110,14 @@ version = "0.4" version = "3.1.0" [build-dependencies.uniffi_build] -version = "0.18.0" +version = "0.19.3" features = ["builtin-bindgen"] [features] rkv-safe-mode = [] [target."cfg(not(target_os = \"android\"))".dependencies.env_logger] -version = "0.8.0" +version = "0.9.0" features = [ "termcolor", "atty", @@ -126,7 +126,7 @@ features = [ default-features = false [target."cfg(target_os = \"android\")".dependencies.android_logger] -version = "0.10.0" +version = "0.11.0" default-features = false [target."cfg(target_os = \"ios\")".dependencies.oslog] diff --git a/third_party/rust/glean-core/src/dispatcher/mod.rs b/third_party/rust/glean-core/src/dispatcher/mod.rs index e787b5a39557..0634bd1038c5 100644 --- a/third_party/rust/glean-core/src/dispatcher/mod.rs +++ b/third_party/rust/glean-core/src/dispatcher/mod.rs @@ -63,7 +63,7 @@ enum Command { } /// The error returned from operations on the dispatcher -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug, PartialEq, Eq)] pub enum DispatchError { /// The worker panicked while running a task #[error("The worker panicked while running a task")] diff --git a/third_party/rust/glean-core/src/error_recording.rs b/third_party/rust/glean-core/src/error_recording.rs index 01466a880119..71468649cf9b 100644 --- a/third_party/rust/glean-core/src/error_recording.rs +++ b/third_party/rust/glean-core/src/error_recording.rs @@ -27,7 +27,7 @@ use crate::Lifetime; /// in the platform-specific code (e.g. `ErrorType.kt`) and with the /// metrics in the registry files. // When adding a new error type ensure it's also added to `ErrorType::iter()` below. -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum ErrorType { /// For when the value to be recorded does not match the metric-specific restrictions InvalidValue, diff --git a/third_party/rust/glean-core/src/histogram/exponential.rs b/third_party/rust/glean-core/src/histogram/exponential.rs index 5ccb441210af..5481c4feb9bd 100644 --- a/third_party/rust/glean-core/src/histogram/exponential.rs +++ b/third_party/rust/glean-core/src/histogram/exponential.rs @@ -56,7 +56,7 @@ fn exponential_range(min: u64, max: u64, bucket_count: usize) -> Vec { /// /// Buckets are pre-computed at instantiation with an exponential distribution from `min` to `max` /// and `bucket_count` buckets. -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct PrecomputedExponential { // Don't serialize the (potentially large) array of ranges, instead compute them on first // access. diff --git a/third_party/rust/glean-core/src/histogram/linear.rs b/third_party/rust/glean-core/src/histogram/linear.rs index 18a576109948..7b30ea8f6cfd 100644 --- a/third_party/rust/glean-core/src/histogram/linear.rs +++ b/third_party/rust/glean-core/src/histogram/linear.rs @@ -36,7 +36,7 @@ fn linear_range(min: u64, max: u64, count: usize) -> Vec { /// /// Buckets are pre-computed at instantiation with a linear distribution from `min` to `max` /// and `bucket_count` buckets. -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct PrecomputedLinear { // Don't serialize the (potentially large) array of ranges, instead compute them on first // access. diff --git a/third_party/rust/glean-core/src/histogram/mod.rs b/third_party/rust/glean-core/src/histogram/mod.rs index be783fb321a5..282b02e0ab59 100644 --- a/third_party/rust/glean-core/src/histogram/mod.rs +++ b/third_party/rust/glean-core/src/histogram/mod.rs @@ -58,7 +58,7 @@ impl TryFrom for HistogramType { /// assert_eq!(10, hist.count()); /// assert_eq!(55, hist.sum()); /// ``` -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Histogram { /// Mapping bucket's minimum to sample count. values: HashMap, diff --git a/third_party/rust/glean-core/src/lib.rs b/third_party/rust/glean-core/src/lib.rs index 4fd0bc66ccc1..9c4016f6aaab 100644 --- a/third_party/rust/glean-core/src/lib.rs +++ b/third_party/rust/glean-core/src/lib.rs @@ -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 https://mozilla.org/MPL/2.0/. +#![allow(clippy::significant_drop_in_scrutinee)] #![deny(rustdoc::broken_intra_doc_links)] #![deny(missing_docs)] diff --git a/third_party/rust/glean-core/src/metrics/recorded_experiment.rs b/third_party/rust/glean-core/src/metrics/recorded_experiment.rs index 1ece6e4592f1..8b9dc35d98f9 100644 --- a/third_party/rust/glean-core/src/metrics/recorded_experiment.rs +++ b/third_party/rust/glean-core/src/metrics/recorded_experiment.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use serde_json::{json, Map as JsonMap, Value as JsonValue}; /// Deserialized experiment data. -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct RecordedExperiment { /// The experiment's branch as set through [`set_experiment_active`](crate::glean_set_experiment_active). pub branch: String, diff --git a/third_party/rust/glean-core/src/metrics/time_unit.rs b/third_party/rust/glean-core/src/metrics/time_unit.rs index 09084527bcfd..6d61a8a2429a 100644 --- a/third_party/rust/glean-core/src/metrics/time_unit.rs +++ b/third_party/rust/glean-core/src/metrics/time_unit.rs @@ -11,7 +11,7 @@ use crate::error::{Error, ErrorKind}; /// Different resolutions supported by the time related /// metric types (e.g. DatetimeMetric). -#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] #[serde(rename_all = "lowercase")] #[repr(i32)] // use i32 to be compatible with our JNA definition pub enum TimeUnit { diff --git a/third_party/rust/glean-core/src/upload/mod.rs b/third_party/rust/glean-core/src/upload/mod.rs index ae09b316c1b0..dad396bfaf17 100644 --- a/third_party/rust/glean-core/src/upload/mod.rs +++ b/third_party/rust/glean-core/src/upload/mod.rs @@ -127,7 +127,7 @@ impl RateLimiter { /// the requester may receive one out of three possible tasks. /// /// If new variants are added, this should be reflected in `glean-core/ffi/src/upload.rs` as well. -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug)] pub enum PingUploadTask { /// An upload task Upload { diff --git a/third_party/rust/glean-core/src/upload/request.rs b/third_party/rust/glean-core/src/upload/request.rs index bb9dc74e039b..43991ef0a285 100644 --- a/third_party/rust/glean-core/src/upload/request.rs +++ b/third_party/rust/glean-core/src/upload/request.rs @@ -180,7 +180,7 @@ impl Builder { } /// Represents a request to upload a ping. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone)] pub struct PingRequest { /// The Job ID to identify this request, /// this is the same as the ping UUID. diff --git a/third_party/rust/glean/.cargo-checksum.json b/third_party/rust/glean/.cargo-checksum.json index df93ac82032f..90afa7d4c083 100644 --- a/third_party/rust/glean/.cargo-checksum.json +++ b/third_party/rust/glean/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"0b561e6268bc36b36c8c29d82fde25a451bd8fb7d618efa2145255033616a73b","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"5bc5b1c46695f628e1023662752272e938a963b535d5686bd1ecc433f9e018c4","src/common_test.rs":"68f6d408cb7b683fa32c8b38a4df1e6c45bfd77c0c90ca35976ea7548bbc4b2f","src/configuration.rs":"37ad5b3e7d4e31dd04a7d6690179168b5f2768d87dd36056dee5d08bdbe20fb2","src/core_metrics.rs":"76ac5350cb6f82d9a193d519b085a08f138dceba77da3514bd0c636bcdefefca","src/lib.rs":"e342d497d60abceca3c84d35523a54d187b0282220a112da53e4ab1cf76da205","src/net/http_uploader.rs":"43812a70d19a38e8d7a093c8076c2b6345372c3c861b0f3511428762700a65e0","src/net/mod.rs":"86cbcb0b46f9d13923a20db9e482b65da49d7daa4e335a3f3092f1d760f572b0","src/private/event.rs":"f6cd799c7764c53510180a1cef6a5a9b435fae27b87270519d5b4e59201e8ecc","src/private/mod.rs":"0364ecf5f0439443a5b209583f4ff2c474b79f7c253c981ab0b7cdc528368698","src/private/ping.rs":"cbdc57f41fc9d46e56b4dfff91ac683753d1f8b3ecd0aa9bc3419e3595b8b81b","src/system.rs":"ff23a5b94f52dab484342dfed702412bc29ab1bbfd5af326033d8e07e7b9075f","src/test.rs":"30d62d967c56a7ca76c097e27bfb6d6d3779ccd5d374cf5a07a04216e4e0880b","tests/common/mod.rs":"37cd4c48e140c793b852ae09fb3e812da28a4412977295015bcbffd632fcf294","tests/init_fails.rs":"9b78226a4e3220de5b64a205a97b8d5778d1700391b5b71c7819b6cdd120747e","tests/never_init.rs":"1f33b8ce7ca3514b57b48cc16d98408974c85cf8aa7d13257ffc2ad878ebb295","tests/no_time_to_init.rs":"494dcddce49f279c6508f484ee59cf8bb83e7324de07bdbc1142f2a066b7f6a1","tests/overflowing_preinit.rs":"396206d5078b7e6c148bbf2aecb0f963cfaa4d7eff3fc7bf6590125076ee6113","tests/persist_ping_lifetime.rs":"2297d4b208e14188e6dcca2d4806b805cfc7dd824d21bd143a7803b95e0709f4","tests/persist_ping_lifetime_nopanic.rs":"06f1f3ca3b8a6c8b7fc4d6fc48d0e1d2ccffd32139f080db0a95003e9edd507d","tests/schema.rs":"a96089f828928b6be1fad7815e3269f5693af1b773e570312b357a29af28122a","tests/simple.rs":"a1d72af899293390bb955ca379baafb89c29bb746630409f8c51f453d222dbad"},"package":"0857be0c251ae1fc3b5672237c99f5115a6546cd8b171cb240173098ab5e9629"} \ No newline at end of file +{"files":{"Cargo.toml":"22631469f647eb393b83eccffadea1ff3124ba4e79e402b754aab30926d384c0","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"5bc5b1c46695f628e1023662752272e938a963b535d5686bd1ecc433f9e018c4","src/common_test.rs":"68f6d408cb7b683fa32c8b38a4df1e6c45bfd77c0c90ca35976ea7548bbc4b2f","src/configuration.rs":"37ad5b3e7d4e31dd04a7d6690179168b5f2768d87dd36056dee5d08bdbe20fb2","src/core_metrics.rs":"76ac5350cb6f82d9a193d519b085a08f138dceba77da3514bd0c636bcdefefca","src/lib.rs":"e342d497d60abceca3c84d35523a54d187b0282220a112da53e4ab1cf76da205","src/net/http_uploader.rs":"43812a70d19a38e8d7a093c8076c2b6345372c3c861b0f3511428762700a65e0","src/net/mod.rs":"86cbcb0b46f9d13923a20db9e482b65da49d7daa4e335a3f3092f1d760f572b0","src/private/event.rs":"f6cd799c7764c53510180a1cef6a5a9b435fae27b87270519d5b4e59201e8ecc","src/private/mod.rs":"0364ecf5f0439443a5b209583f4ff2c474b79f7c253c981ab0b7cdc528368698","src/private/ping.rs":"cbdc57f41fc9d46e56b4dfff91ac683753d1f8b3ecd0aa9bc3419e3595b8b81b","src/system.rs":"ff23a5b94f52dab484342dfed702412bc29ab1bbfd5af326033d8e07e7b9075f","src/test.rs":"30d62d967c56a7ca76c097e27bfb6d6d3779ccd5d374cf5a07a04216e4e0880b","tests/common/mod.rs":"37cd4c48e140c793b852ae09fb3e812da28a4412977295015bcbffd632fcf294","tests/init_fails.rs":"9b78226a4e3220de5b64a205a97b8d5778d1700391b5b71c7819b6cdd120747e","tests/never_init.rs":"1f33b8ce7ca3514b57b48cc16d98408974c85cf8aa7d13257ffc2ad878ebb295","tests/no_time_to_init.rs":"494dcddce49f279c6508f484ee59cf8bb83e7324de07bdbc1142f2a066b7f6a1","tests/overflowing_preinit.rs":"396206d5078b7e6c148bbf2aecb0f963cfaa4d7eff3fc7bf6590125076ee6113","tests/persist_ping_lifetime.rs":"2297d4b208e14188e6dcca2d4806b805cfc7dd824d21bd143a7803b95e0709f4","tests/persist_ping_lifetime_nopanic.rs":"06f1f3ca3b8a6c8b7fc4d6fc48d0e1d2ccffd32139f080db0a95003e9edd507d","tests/schema.rs":"a96089f828928b6be1fad7815e3269f5693af1b773e570312b357a29af28122a","tests/simple.rs":"a1d72af899293390bb955ca379baafb89c29bb746630409f8c51f453d222dbad"},"package":"813fa9059f1a7d9da4fcf6cff6c77e6226fc26f58797d1659d16a8279c4655f2"} \ No newline at end of file diff --git a/third_party/rust/glean/Cargo.toml b/third_party/rust/glean/Cargo.toml index 3b17025f8244..1c9486e986ec 100644 --- a/third_party/rust/glean/Cargo.toml +++ b/third_party/rust/glean/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2018" name = "glean" -version = "50.1.0" +version = "50.1.2" authors = [ "Jan-Erik Rediger ", "The Glean Team ", @@ -41,7 +41,7 @@ features = ["serde"] version = "0.5" [dependencies.glean-core] -version = "50.1.0" +version = "50.1.2" [dependencies.inherent] version = "1" @@ -73,7 +73,7 @@ features = ["v4"] version = "0.1.2" [dev-dependencies.env_logger] -version = "0.8.0" +version = "0.9.0" features = [ "termcolor", "atty", diff --git a/third_party/rust/uniffi/.cargo-checksum.json b/third_party/rust/uniffi/.cargo-checksum.json index c06e94435179..6d938d55cf03 100644 --- a/third_party/rust/uniffi/.cargo-checksum.json +++ b/third_party/rust/uniffi/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"629736f65f72d44b4e972c6e21bc998f7cc0ab5880863d80ce462df9fe3c86e4","release.toml":"a6602545cd6eb46e44d89ce946d7954957ac00f1c955de54c736fa2cb560b1df","src/ffi/ffidefault.rs":"c7ab752fffed17c3fabb60e818ad1d093482f95dd0bdeae6871287695c583e48","src/ffi/foreignbytes.rs":"6dfd91c7c9371620d45a2e950ff7c16470a7f917e034a5f1c04672bcc45682d3","src/ffi/foreigncallbacks.rs":"e19a038128d25e7d945034935f0d296ea8603ad2f5a8da4bfe6d95c78a5f76b3","src/ffi/mod.rs":"3fb3b74607066e0052fc91168e9473dbf82dbae562f85c33774a7f5f6b350616","src/ffi/rustbuffer.rs":"93ca5e8608ef1cae0da76106aa2244e50e998c99b2530cb613ff735483cd914c","src/ffi/rustcalls.rs":"79192b82878fee2c09a74ec7cef1f8efdf5b7a84692a9f3a42b512bcf3400bed","src/lib.rs":"ef06d0f87da668edf8fda2381bf484a612d35d7507a0e3bf807390077b664b7d","src/panichook.rs":"de3c63909691efc014ff528c767aa346109dccedf8b529c339e6715784780ae5","src/testing.rs":"e474fc7486cd8101449284d15b71c5b3f70ac17fe8214ab0c495e94d761b6c19","tests/ui/version_mismatch.rs":"16ea359e5853517ee0d0704c015ae8c825533109fbefd715130d0f4a51f15898","tests/ui/version_mismatch.stderr":"aadbd8f3847f5663022d8dd75d6afa3b25dfc8abccd30b386a681f98587d4ceb"},"package":"d0fe14882ae6ea89f31ac922ad8e6f76b3f346f07965791a60ade60cc3bcdd60"} \ No newline at end of file +{"files":{"Cargo.toml":"2d5f07251fa9e9b2422003e9ac5d8d1d8ba4656b656ee3c493e8531266dc82ed","release.toml":"a6602545cd6eb46e44d89ce946d7954957ac00f1c955de54c736fa2cb560b1df","src/ffi/ffidefault.rs":"c7ab752fffed17c3fabb60e818ad1d093482f95dd0bdeae6871287695c583e48","src/ffi/foreignbytes.rs":"37061e2da7135576abccb86fe27b4fefc054586a040f2ca81fe9858d5649e887","src/ffi/foreigncallbacks.rs":"e19a038128d25e7d945034935f0d296ea8603ad2f5a8da4bfe6d95c78a5f76b3","src/ffi/mod.rs":"3fb3b74607066e0052fc91168e9473dbf82dbae562f85c33774a7f5f6b350616","src/ffi/rustbuffer.rs":"b773637d9e4651b80cd16f7a02ed75846d02ce0a9e32b718ce644cdba3a83cdd","src/ffi/rustcalls.rs":"79192b82878fee2c09a74ec7cef1f8efdf5b7a84692a9f3a42b512bcf3400bed","src/lib.rs":"a2dba349d0c0c2f31b314f145bf576a4d0c8855fe265f987542ddbbe638ca87f","src/panichook.rs":"de3c63909691efc014ff528c767aa346109dccedf8b529c339e6715784780ae5","src/testing.rs":"6dc9b93d8bd500a0abd552a1830b968718ac6c2f713af4c325ed46c3f0a7a6c4","tests/ui/version_mismatch.rs":"16ea359e5853517ee0d0704c015ae8c825533109fbefd715130d0f4a51f15898","tests/ui/version_mismatch.stderr":"aadbd8f3847f5663022d8dd75d6afa3b25dfc8abccd30b386a681f98587d4ceb"},"package":"bc1de33ad46ce00bc9a31cea44e80ef69175d3a23007335216fe3996880a310d"} \ No newline at end of file diff --git a/third_party/rust/uniffi/Cargo.toml b/third_party/rust/uniffi/Cargo.toml index f938095caeba..ab0aa6e6fe06 100644 --- a/third_party/rust/uniffi/Cargo.toml +++ b/third_party/rust/uniffi/Cargo.toml @@ -10,9 +10,9 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" +edition = "2021" name = "uniffi" -version = "0.18.0" +version = "0.19.3" authors = ["Firefox Sync Team "] description = "a multi-language bindings generator for rust (runtime support code)" homepage = "https://mozilla.github.io/uniffi-rs" @@ -23,6 +23,7 @@ keywords = [ ] license = "MPL-2.0" repository = "https://github.com/mozilla/uniffi-rs" +resolver = "2" [dependencies.anyhow] version = "1" @@ -30,8 +31,11 @@ version = "1" [dependencies.bytes] version = "1.0" +[dependencies.camino] +version = "1.0.8" + [dependencies.cargo_metadata] -version = "0.13" +version = "0.14" [dependencies.lazy_static] version = "1.4" @@ -46,7 +50,7 @@ version = "1.0" version = "1.1.0" [dependencies.uniffi_bindgen] -version = "=0.18.0" +version = "=0.19.3" optional = true [dev-dependencies.trybuild] diff --git a/third_party/rust/uniffi/src/ffi/foreignbytes.rs b/third_party/rust/uniffi/src/ffi/foreignbytes.rs index 561173efd605..5ec93118ad7e 100644 --- a/third_party/rust/uniffi/src/ffi/foreignbytes.rs +++ b/third_party/rust/uniffi/src/ffi/foreignbytes.rs @@ -2,8 +2,6 @@ * 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/. */ -use std::convert::TryInto; - /// Support for reading a slice of foreign-language-allocated bytes over the FFI. /// /// Foreign language code can pass a slice of bytes by providing a data pointer diff --git a/third_party/rust/uniffi/src/ffi/rustbuffer.rs b/third_party/rust/uniffi/src/ffi/rustbuffer.rs index 6722f32d524c..63af586fb610 100644 --- a/third_party/rust/uniffi/src/ffi/rustbuffer.rs +++ b/third_party/rust/uniffi/src/ffi/rustbuffer.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use crate::ffi::{call_with_output, ForeignBytes, RustCallStatus}; -use std::convert::{TryFrom, TryInto}; /// Support for passing an allocated-by-Rust buffer of bytes over the FFI. /// diff --git a/third_party/rust/uniffi/src/lib.rs b/third_party/rust/uniffi/src/lib.rs index 67060880ee7a..3eb2f5a83b55 100644 --- a/third_party/rust/uniffi/src/lib.rs +++ b/third_party/rust/uniffi/src/lib.rs @@ -514,7 +514,7 @@ impl RustBufferFfiConverter for Vec { // TODO: would be nice not to panic here :-/ let len = i32::try_from(obj.len()).unwrap(); buf.put_i32(len); // We limit arrays to i32::MAX items - for item in obj.into_iter() { + for item in obj { ::write(item, buf); } } @@ -548,7 +548,7 @@ where // TODO: would be nice not to panic here :-/ let len = i32::try_from(obj.len()).unwrap(); buf.put_i32(len); // We limit HashMaps to i32::MAX entries - for (key, value) in obj.into_iter() { + for (key, value) in obj { ::write(key, buf); ::write(value, buf); } diff --git a/third_party/rust/uniffi/src/testing.rs b/third_party/rust/uniffi/src/testing.rs index 3bca139c8933..90df0fd5f593 100644 --- a/third_party/rust/uniffi/src/testing.rs +++ b/third_party/rust/uniffi/src/testing.rs @@ -9,12 +9,12 @@ //! and should instead use the `build_foreign_language_testcases!` macro provided by //! the `uniffi_macros` crate. -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; +use camino::{Utf8Path, Utf8PathBuf}; use cargo_metadata::Message; use lazy_static::lazy_static; use std::{ collections::HashMap, - path::Path, process::{Command, Stdio}, sync::Mutex, }; @@ -23,7 +23,7 @@ use std::{ // They map uniffi component crate directories to data about build steps that have already // been executed by this process. lazy_static! { - static ref COMPILED_COMPONENTS: Mutex> = Mutex::new(HashMap::new()); + static ref COMPILED_COMPONENTS: Mutex> = Mutex::new(HashMap::new()); // Since uniffi-bindgen does the actual generating/compiling of bindings and script files, // we ensure that only one call happens at once (making tests pretty much serialized sorry :/). static ref UNIFFI_BINDGEN: Mutex = Mutex::new(0); @@ -41,11 +41,10 @@ pub fn run_foreign_language_testcase( test_file: &str, ) -> Result<()> { let cdylib_file = ensure_compiled_cdylib(pkg_dir)?; - let out_dir = Path::new(cdylib_file.as_str()) + let out_dir = cdylib_file .parent() - .ok_or_else(|| anyhow::anyhow!("Generated cdylib has no parent directory"))? - .to_str() - .unwrap(); + .context("Generated cdylib has no parent directory")? + .as_str(); let _lock = UNIFFI_BINDGEN.lock(); run_uniffi_bindgen_test(out_dir, udl_files, test_file)?; Ok(()) @@ -59,11 +58,13 @@ pub fn run_foreign_language_testcase( /// /// 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 { +pub fn ensure_compiled_cdylib(pkg_dir: &str) -> Result { + let pkg_dir = Utf8Path::new(pkg_dir); + // Have we already compiled this component? let mut compiled_components = COMPILED_COMPONENTS.lock().unwrap(); if let Some(cdylib_file) = compiled_components.get(pkg_dir) { - return Ok(cdylib_file.to_string()); + return Ok(cdylib_file.to_owned()); } // Nope, looks like we'll have to compile it afresh. let mut cmd = Command::new("cargo"); @@ -123,10 +124,10 @@ pub fn ensure_compiled_cdylib(pkg_dir: &str) -> Result { if cdylib_files.len() != 1 { bail!("Failed to build exactly one cdylib file, it must not be a uniffi component"); } - let cdylib_file = cdylib_files[0].to_string(); + let cdylib_file = cdylib_files[0]; // Cache the result for subsequent tests. - compiled_components.insert(pkg_dir.to_string(), cdylib_file.clone()); - Ok(cdylib_file) + compiled_components.insert(pkg_dir.to_owned(), cdylib_file.to_owned()); + Ok(cdylib_file.to_owned()) } /// Execute the `uniffi-bindgen test` command. @@ -151,5 +152,5 @@ fn run_uniffi_bindgen_test(out_dir: &str, udl_files: &[&str], test_file: &str) - #[cfg(feature = "builtin-bindgen")] fn run_uniffi_bindgen_test(out_dir: &str, udl_files: &[&str], test_file: &str) -> Result<()> { - uniffi_bindgen::run_tests(out_dir, udl_files, vec![test_file], None) + uniffi_bindgen::run_tests(out_dir, udl_files, &[test_file], None) } diff --git a/third_party/rust/uniffi_bindgen/.cargo-checksum.json b/third_party/rust/uniffi_bindgen/.cargo-checksum.json index 3caf4b363de6..c912724671e9 100644 --- a/third_party/rust/uniffi_bindgen/.cargo-checksum.json +++ b/third_party/rust/uniffi_bindgen/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.lock":"67ac96763fe16c87f53a1a7eb9081ea4798d126e5c83504875320c8b91fb0bc8","Cargo.toml":"01fbff68a3ebc5ef517b677eff63f7ad991bfd87809d884abf1f902de96cbd4d","askama.toml":"1a245b7803adca782837e125c49100147d2de0d5a1c949ff95e91af1701f6058","src/backend/config.rs":"4861dbf251dbb10beb1ed7e3eea7d79499a0de1cd9ce9ee8381a0e729c097dea","src/backend/declarations.rs":"12b8d6e651f84634de5cd02a47601965df7438f64f1a73f136bd89b6b5d515cf","src/backend/mod.rs":"899cd3b816d0467e35789b92ac3b8d5910f6dab98156d405db4803da8721fd36","src/backend/oracle.rs":"9e2b8a45af604a6e4952644e81f43f6aec6e0a1d03939c68b582529dd01a51e0","src/backend/types.rs":"43b738e442e74f5bae5826de55fd6e9a34985dc4d478b60b7ee50a1e6a194eba","src/bindings/kotlin/gen_kotlin/callback_interface.rs":"b7fe795670830f3aa8a955c787b1127fe68313ee751013948527948fe5526b01","src/bindings/kotlin/gen_kotlin/compounds.rs":"d1e9a4237ff2ff711a3eae7a564c39e26f598c156ebfd34c0f04879e3533dd4f","src/bindings/kotlin/gen_kotlin/custom.rs":"4176f6ed5f66504f8fd981198bbfbae795dab5ef0d0281881d19b697f5560c44","src/bindings/kotlin/gen_kotlin/enum_.rs":"f85ae8dcb55c8f274139bf321af0ba237ae69894165ad6bd693d793f58af8e5e","src/bindings/kotlin/gen_kotlin/error.rs":"867f583aea5da7aabeb9b6d2544d7e52984cdea4aa008ce5f2ec941074735e1a","src/bindings/kotlin/gen_kotlin/external.rs":"1f7e91d7439891fe3c403274e35880ee4fc3a0da555510bdfa23c1ed2bbd8020","src/bindings/kotlin/gen_kotlin/miscellany.rs":"644ee5bb1f3619be5a36b2b3900af554ea38073cd054004f421e69c3cb8d50bc","src/bindings/kotlin/gen_kotlin/mod.rs":"aa98838c4dcd7fe4daa443359a6feef749c9a142af8bc6bb012af35529a26b23","src/bindings/kotlin/gen_kotlin/object.rs":"6478a3e9d5e66186521730d0d481abd1ee4f123050ea050ac5a483842f08b003","src/bindings/kotlin/gen_kotlin/primitives.rs":"914d1f8253ed6a2937f67e8bd8f04f46aef4f22455ceb8a6caa84427adc2093e","src/bindings/kotlin/gen_kotlin/record.rs":"7961fcfbec5ebf8fc010b564ea4bd59402c919f6922898d48226d8c995569dd7","src/bindings/kotlin/mod.rs":"5f94a4621acb04eb7483b383104c295e7ebbfcfe1406bae96ead6969e5aff68a","src/bindings/kotlin/templates/BooleanHelper.kt":"28e8a5088c8d58c9bfdbc575af8d8725060521fdd7d092684a8044b24ae567c7","src/bindings/kotlin/templates/CallbackInterfaceRuntime.kt":"6ede374b0fcbb3bcc939894e6f4729b3bec7ec7356831a60fba96ca38dc91aa8","src/bindings/kotlin/templates/CallbackInterfaceTemplate.kt":"22a289c3545fa8aa0973f40aada5bd0157cc2e2933e5cf1206d78b4603de86b9","src/bindings/kotlin/templates/CustomTypeTemplate.kt":"5d4dacf29e89bcdcc46d155d993e6059d2df704e775dc853469310198253b231","src/bindings/kotlin/templates/DurationHelper.kt":"414a98161538a26f3a9b357353270c1f245ad6ceed99496aca7162cf473a92fd","src/bindings/kotlin/templates/EnumTemplate.kt":"ab3e2063aad3b91188db839dceb59b854a6a8b60fb35e545e270e64fee7c73fa","src/bindings/kotlin/templates/ErrorTemplate.kt":"16fafca68672842bf8edd13a3b4eea0e0e98871cb640d1a09ef00a244a4c69d3","src/bindings/kotlin/templates/ExternalTypeTemplate.kt":"2097e0b830640ef18c79449ffa376d1dd35a8c4a5230e413c915f3b868aae872","src/bindings/kotlin/templates/FfiConverterTemplate.kt":"aa22962aaa9f641d48ccf44cb56d9f8a7736cbfaa01e1a1656662cfe5dd5c1d7","src/bindings/kotlin/templates/Float32Helper.kt":"662d95af3b629d143fb4d47cb7e9aa26ed28a5f3846de0341e28b0f9fb08bc25","src/bindings/kotlin/templates/Float64Helper.kt":"a77d099fa7d91e8702c1700e7949ffb6aaba9c6e8041ff48bab34b8e1fc9a0aa","src/bindings/kotlin/templates/Helpers.kt":"46c07798a26b53b06405c8bbbf86e3fcf38fadc1484ea04ce9d482defea89288","src/bindings/kotlin/templates/Int16Helper.kt":"7f83c4a48e1f3b2a59a3ca6a2662be8bc9baf3a5a748b31223cb3f51721ef249","src/bindings/kotlin/templates/Int32Helper.kt":"e02e4702175554b09fd2dd6ac3089dcd2c395f08ec60e762159566a9c9889450","src/bindings/kotlin/templates/Int64Helper.kt":"7a6fd6ca486852c89399c699935a9dfa1c32b9356d9a965cfde532581f05d9fa","src/bindings/kotlin/templates/Int8Helper.kt":"0554545494b6b9a76ce94f9c1723f8cf4230a13076feb75d620b1c9ca1ac4668","src/bindings/kotlin/templates/MapTemplate.kt":"399569d6443e8ad01e2deb95d78d8d2d15bf8eccee8be4fbe9ce4b8ebc0a6101","src/bindings/kotlin/templates/NamespaceLibraryTemplate.kt":"1eba4e77381155c2c96a6af2ef30fca881ade4957852f730fd10aa4f3d9cd3c4","src/bindings/kotlin/templates/ObjectRuntime.kt":"c11d233de41405caa55a56bcaa3bb69ce153ffa6fdff2aa218051929f5c4aeec","src/bindings/kotlin/templates/ObjectTemplate.kt":"b67e9508e1c958cc7454e72bee3a64f5bcca35adea46cfdda153bab6ac5a032c","src/bindings/kotlin/templates/OptionalTemplate.kt":"5f9f2c1baa829ed3c9b61c3edb0f1fccf5ea3cccc052a69cf8966715d8fcf149","src/bindings/kotlin/templates/RecordTemplate.kt":"193ecdad9322fb5483b95bf2a259270a9b22ba054790794e9abb3fd219196bc5","src/bindings/kotlin/templates/RustBufferTemplate.kt":"415637f80a78c12b3d00db063c14a7ab5c61b098bdb1fc81a0be8bae9511776b","src/bindings/kotlin/templates/SequenceTemplate.kt":"786693b20c608a4f059b91df115278f5f12122b4c14a2e7ce18b6fc9b22b1296","src/bindings/kotlin/templates/StringHelper.kt":"060839663580d8199671b7c3bb3dce5e9106aa766ce2c6e0afc2d2bd788a1d83","src/bindings/kotlin/templates/TimestampHelper.kt":"353c2890f06ad6dda238e9aebb4bdff7bb838e17e46abf351ed3ff1fbc4e6580","src/bindings/kotlin/templates/TopLevelFunctionTemplate.kt":"73c46330c281ab88d5f20e42d06b5d5da2e085ee4ec642ec5d3aa226b27727d4","src/bindings/kotlin/templates/Types.kt":"c948860793d9cbba37ae707394501f0677d7211957dcffe9a428789d59248642","src/bindings/kotlin/templates/UInt16Helper.kt":"e84a1f30a5a899ba2c5db614d3f3c74f25bccf6dd99bf68b8830829332d051e9","src/bindings/kotlin/templates/UInt32Helper.kt":"7cdf08cc580046935f27ba07b53685968608a102e0a6be305111037c63d7ddf8","src/bindings/kotlin/templates/UInt64Helper.kt":"fd7baacbf3ab6202ff83edcc66e5f7beb11a10053ba66d0b49547616cc7cbe1f","src/bindings/kotlin/templates/UInt8Helper.kt":"bbf5a6d66c995aea9fe2fa9840c6bfa78b03520a09469b984f0e1d43191e453a","src/bindings/kotlin/templates/macros.kt":"aba8eebc89ee5f72da254ea3e8e985c9dd078c33ef96110c8107716822eea3cc","src/bindings/kotlin/templates/wrapper.kt":"5e9da58e5d654d6a4c2a99982dd8343a56c7f17e49e8ba4e93195ca6837c2e80","src/bindings/mod.rs":"1d74890fec042e6ee4e8f2b73c7f5806076afaf8537aa39e8cfb17b905a40cd4","src/bindings/python/gen_python/callback_interface.rs":"fd1536b44428e590ee204d7abc4b504fd06078f1802a92b69326437f53f364d3","src/bindings/python/gen_python/compounds.rs":"f8d1b81185ac79131568832259642c5ed7a9cad4d5871dc437a787d960a27583","src/bindings/python/gen_python/custom.rs":"4b5f883b229a5fe9c2b02bb379767474c0508e2a1abafac1dc3267df2c6af746","src/bindings/python/gen_python/enum_.rs":"a89627b9ac200b15940347e72e9f789ab429a7f7954096f60bcec4438c503456","src/bindings/python/gen_python/error.rs":"69d4d8f5c54560654144752a4ffb3f4a449ab6c16f05c488abce46018c8efdf3","src/bindings/python/gen_python/external.rs":"ed27d7cdc9d15fc50b3d5a921c0bf2af306b1f24dc1c435b7be36e0bb58c40aa","src/bindings/python/gen_python/function.rs":"c02d1fc972ed73a45c67596b43048807dbbf904aceaf4721e1dff34c7cdbb345","src/bindings/python/gen_python/miscellany.rs":"b3343c4bee357aaa9282b91c6f18ae5537ad9bf8e7f77a389f912ef07c9d1136","src/bindings/python/gen_python/mod.rs":"1a02d20807463b58e06fb21beb14e01ac397375f597e192634eefd10d33197a1","src/bindings/python/gen_python/object.rs":"43afcb62bf997ed14fde4c2e2a435b9a8700be6a63abb330b1958674fb891279","src/bindings/python/gen_python/primitives.rs":"d4f41e9e643917d38f1c2db591dd9d150fd3a36447414da82cc3f245e0bdc05e","src/bindings/python/gen_python/record.rs":"0b51d2f5a445ca4e44d0eeea9b18ee595fa68adb795112efe2b1d5ce4d660d50","src/bindings/python/mod.rs":"9b963cf9950d25bc7d5d81f2512efd9e67a04d080b961d258dc8c08a8e857313","src/bindings/python/templates/BooleanHelper.py":"d384ffeefcb5982c4875e819d06e919a295eaa9ff57735e6fef0801bb810d5c9","src/bindings/python/templates/CallbackInterfaceRuntime.py":"7ffef485fc008e2d9efcd07326102f300bd4673b4351353e9e2908355936c3d7","src/bindings/python/templates/CallbackInterfaceTemplate.py":"900688e02bfb421059833b2767a2d5a1f6f0921e27ae86c5ba4f683dba21b7fc","src/bindings/python/templates/CustomType.py":"2b0b43a629e9587042ca0310a86d0c28d01eec55d8a2171ede7c7b7ba653a71d","src/bindings/python/templates/DurationHelper.py":"179c14dccd8cc7dc9791f896414f0b5d124ec116eb78173371bd8a0743208da1","src/bindings/python/templates/EnumTemplate.py":"977fe8353b8a425add8fc317e589c7cdd7b5c9f5aeb281452a10406753138e03","src/bindings/python/templates/ErrorTemplate.py":"7d3183ad4b9daa4aa1869ad2444338ca534cb80421db7613d3a849b6fd1c47bc","src/bindings/python/templates/ExternalTemplate.py":"b722d06e66b7717e819d7554e7b261d1cf97c012bf4f68dbac1e230de639797e","src/bindings/python/templates/Float32Helper.py":"7dbc51889cff47ebf1600fad490849e4a87cac4fc0d1756eebd21609eb80b4a9","src/bindings/python/templates/Float64Helper.py":"ba9f334d1339b6eaedcacc1e35068939727170a684f41dec9ee04762ed98cec1","src/bindings/python/templates/Helpers.py":"68f03f651c38c810fa453e123e26f7c94b7a1f9178e0d863b985c3c8fabaa642","src/bindings/python/templates/Int16Helper.py":"60c22fb8b445841ebb3c68be11b81c9eba84a680eaa0e30770953361231da9b5","src/bindings/python/templates/Int32Helper.py":"aff0a017cf767394174e46d8c4fe5a5a704a8e6384fcc38d227634dfe7826916","src/bindings/python/templates/Int64Helper.py":"6c314b91699a6c6ad7db3ef636713bc2a0af9609c82acfd6062b0588177c0026","src/bindings/python/templates/Int8Helper.py":"a6e2d121b1a6d59886fceab3949e571aba1abc06dfede52666954bf15366fb6f","src/bindings/python/templates/MapTemplate.py":"a101635d4fa0b353174a7f2af550f06e37781407b37f56f21959c60a01a01b80","src/bindings/python/templates/NamespaceLibraryTemplate.py":"4726dbeb61508a71153436126bc04d03af966dca4f5b37511beb8bcfb6f1f307","src/bindings/python/templates/ObjectTemplate.py":"2a701fb18894183691f8e04b60a84e122356324c2360191dc0a31a4e09939f80","src/bindings/python/templates/OptionalTemplate.py":"2b24a6b98afaaa0672799ab43862bd32506ec8e8c213e950f3ecd8002a968259","src/bindings/python/templates/RecordTemplate.py":"ac1bca6a8b98b50edc8250511ceeab9e8b990c3698f6a1082f7bcb553f44fc18","src/bindings/python/templates/RustBufferHelper.py":"11f733051e63733c637fb19c4758cb58a40d045792028465f36891f89c7c5f36","src/bindings/python/templates/RustBufferTemplate.py":"90950cfeeb7a028aac9b65aeca897b217eddcfa165a0d59e8af037e834f34146","src/bindings/python/templates/SequenceTemplate.py":"80510288fdc27db5737248f6a59eec3873e4210f112563fa95e676b7af36b4d1","src/bindings/python/templates/StringHelper.py":"941a7ad71d9598701efa15323df93766934583a55f4266d26db31e6b744603fc","src/bindings/python/templates/TimestampHelper.py":"b412cea69117858c05bae3210d378c6296658ed02a50e87c52c392dcb62c7892","src/bindings/python/templates/TopLevelFunctionTemplate.py":"03f22922ec5812563564072ab8e59fce74304231b6efac26cc58cc105ebb4f75","src/bindings/python/templates/UInt16Helper.py":"06be5c9dacdf20e586f8236ed75cf2ca2470078fd8570843ea97c581b25bf860","src/bindings/python/templates/UInt32Helper.py":"41bb9bbf9b7be1060945e1267b1cc052585ec43696b1591f0ee779a0be0feaff","src/bindings/python/templates/UInt64Helper.py":"ba2825fc295a07292d9fb4aeebe74dabb9e6dbe505643e2347875ab12e511f31","src/bindings/python/templates/UInt8Helper.py":"dca5b3fc4a429fb233326224f85c4eccd3a7802ca9958ec309c7f197d59b4e3d","src/bindings/python/templates/macros.py":"75a49928a1b5823e4942d1f7d208cd37b3585a3ae15273f5ed9924fbdc9faa81","src/bindings/python/templates/wrapper.py":"f2b0daba7a4694826a62a723ed7c63a5c77f4b5aee59da5f3ea9949e2e9e7dde","src/bindings/ruby/gen_ruby/mod.rs":"0cb14356ec4b14031d86d783e8a21f2d0c65dbb6042db4c80a8b511a424d39b3","src/bindings/ruby/gen_ruby/tests.rs":"7dcb86b08e643c43503f4cac6396833497f6988b004321c0067700ee29ffbf32","src/bindings/ruby/mod.rs":"351079b8eac312c4ed165db19a08d2cd2bc722f8c0215ac1f87a2c9d5c173c66","src/bindings/ruby/templates/EnumTemplate.rb":"5480edb347f5829e478d19474691babd72f37616ed846d519b5a61cb1d6cf047","src/bindings/ruby/templates/ErrorTemplate.rb":"8621d252c10b0bbcb992f27ce5678fe64432bf3a529d419b42d16ed5dcb6cc08","src/bindings/ruby/templates/NamespaceLibraryTemplate.rb":"9b1454208bc83ef8f26aef33713d681e2284dbfea986ec0dd6c9b9c8b7d65e4a","src/bindings/ruby/templates/ObjectTemplate.rb":"c2d2fa2db62d48322b66b53888dcc6de2fc3e579a6b8d0a9f24029c18fffcbb5","src/bindings/ruby/templates/RecordTemplate.rb":"4aeff886928ca972e5dc9b799581b30c66a6f6dce446af3285dd3ed6b422dea9","src/bindings/ruby/templates/RustBufferBuilder.rb":"9f117e844092dbeeb66ee5453c95aa4a67a5edcafbd103435280070fb924d76c","src/bindings/ruby/templates/RustBufferStream.rb":"3c28de360692a64e4f0e2db96f2f8a8dc0d9e67dd1292a981d8af6c6c810cd8c","src/bindings/ruby/templates/RustBufferTemplate.rb":"e0cd9771d06f2026ea1040f67c90e2b37154906c2f1ee0a0e1352aaf1523275f","src/bindings/ruby/templates/TopLevelFunctionTemplate.rb":"a8e14e8de740a74193cea605bd114d0431665f318d287ca3208a5a9959605923","src/bindings/ruby/templates/macros.rb":"c0e07ee89247aba8340d95972e187e954be6a033f363a8770f16e40aaf350abc","src/bindings/ruby/templates/wrapper.rb":"674b6af4572e91b6bf4d1aac92a2c8057b1e67957267a4772946d793c5f097ca","src/bindings/swift/gen_swift/callback_interface.rs":"735e253b614ceb38c8a7f584dd8f5029e12e2db7ab6f27bf22a39172276ba024","src/bindings/swift/gen_swift/compounds.rs":"540976a51fb43fa708ae3c504f8a0e637f13ac845d460987ee2135575a0f8b6e","src/bindings/swift/gen_swift/custom.rs":"e095a4b6449c12075afe67fc77ca6837840b65c23ce8f24504d758a8f8b71ff2","src/bindings/swift/gen_swift/enum_.rs":"70a0c62819926625dfd36934279199fc06175dc148ffdada4492b2eb9467cf17","src/bindings/swift/gen_swift/error.rs":"2006739082608d2aafd69a5ab844673b7cc269bdd9a47bdb49d20aa16449adf2","src/bindings/swift/gen_swift/function.rs":"afb52b270695956b6c64e68bdcaf5b505bb6bcfcf0e0bce10a66d2f6971719ab","src/bindings/swift/gen_swift/miscellany.rs":"73746ae4a11944a46dec2b123c0addd4be8400f0e59c6320dde46b1a1897cde6","src/bindings/swift/gen_swift/mod.rs":"ac73df0629beda967bbbf87b3376ecc5062ea27eb9a232d6236d30e3e6cbc124","src/bindings/swift/gen_swift/object.rs":"be3ae4e2c9cc332722cafc30728289029bce4a7ec87a16eeb327df2f361a209b","src/bindings/swift/gen_swift/primitives.rs":"49929effeab90bf4df1392d9b9f9bcc991b5f3fa80ca9810b0e3534b3c027d60","src/bindings/swift/gen_swift/record.rs":"f5e97d34631c8adc0699dc31125c2c6c43f3db6017def8748f0b622dde57b892","src/bindings/swift/mod.rs":"6b9994a5e1209b5f508e5c2a681a667016455d2631a08df016d8246021e2f3dc","src/bindings/swift/templates/BooleanHelper.swift":"f607928c4d598893421fe9c9f183bab2f23a877a07afeb123dbe90515249ec86","src/bindings/swift/templates/BridgingHeaderTemplate.h":"93a289e393ecdbe1bf986215c3b19d2aed7677d47f79b1833ce73cf6f8762e80","src/bindings/swift/templates/CallbackInterfaceRuntime.swift":"aac01eb4269151be9dde8c95ee8eba7e8d0841b3c2b1dbd88885f01ac64ee147","src/bindings/swift/templates/CallbackInterfaceTemplate.swift":"147f44e8b7802b73281a0cd6fa7dfd5e881ba2125923e36da16d8b72ee5f7f3b","src/bindings/swift/templates/CustomType.swift":"59171c1af527fb7fc6836bd23262e913a32c089df81f45a694582cb8fc43a317","src/bindings/swift/templates/DurationHelper.swift":"bca4a6498b27fe0c877df3c7fbe148538eeda03e68d4e760a7c8a6a15f2067ff","src/bindings/swift/templates/EnumTemplate.swift":"b48de94cfbcefb33ea20ac8aab88dee15761e7f62ac8c385cff91015b7f6d317","src/bindings/swift/templates/ErrorTemplate.swift":"0f8fddf8d3f500086c886203e47aa565adc8895034c856521a9f7da3d6bd1142","src/bindings/swift/templates/Float32Helper.swift":"6c1a4da059dd4c6c4392511c93fe9daf4ddeeab71e39afd122797b0e19254318","src/bindings/swift/templates/Float64Helper.swift":"f741568cdfb8e1421369a9a1dc845630a3a0e2dc2d6acf157afd80cd3ef5966f","src/bindings/swift/templates/Helpers.swift":"3cf3a5342a1ef0c7e078b0e58c32ae4437c4fb5dc41acbbd56b1128393c76602","src/bindings/swift/templates/Int16Helper.swift":"76eec2a54a65790c5959380cc9a7362b1e2e201632cccb789153c52e10c8dc4f","src/bindings/swift/templates/Int32Helper.swift":"5afc5e103bf637813fd4b77ab63e47ed38893525101a483218a339f222710061","src/bindings/swift/templates/Int64Helper.swift":"c1a6f6661ef1ad3bd00e8d0bf81adaa6539686eee2b481b046b76dbd87681adf","src/bindings/swift/templates/Int8Helper.swift":"bc46598c966e579cca22d336748c74cdce5674eaaaf75fc24e5fdaa36a43cf9c","src/bindings/swift/templates/MapTemplate.swift":"97ddfb36ddf3b77ccebf839ef3e0aac46c624cd6ce5b30aad95435c1a2f7b2c2","src/bindings/swift/templates/ModuleMapTemplate.modulemap":"99ad1e9bf550a21497296f9248ecd4385dd6d0b5892951d24cf990cdbf3eec2c","src/bindings/swift/templates/ObjectTemplate.swift":"302ae6e8b1f05b0b75f7fadad0a44bda3aac658069e80f3c648e33b87ef77e21","src/bindings/swift/templates/OptionalTemplate.swift":"256ab3c7d5550b4b26f07f4b1f67efae61d3a692c335ce557c1669c2a018eeb8","src/bindings/swift/templates/RecordTemplate.swift":"8bc53c4f6123213dc4920b787448200dd1ebc0faa86cd98af2a06cffed4bf31a","src/bindings/swift/templates/RustBufferTemplate.swift":"ed16f20cecd264f086c923cd92a5198f444aec99aad4d39e9012f09f530ca809","src/bindings/swift/templates/SequenceTemplate.swift":"b0fda40722df6f5a72754d2c236ef8f3e884388aae99b0d8077fb1ef7b083082","src/bindings/swift/templates/StringHelper.swift":"b773c2b3a03f30338ff233881d1b0c0238831b812eff6eb9f0fafcb32ab0743a","src/bindings/swift/templates/TimestampHelper.swift":"6e22e370feae1199bff16bcc6f431decfb7700b02e6afdd84693a0c474eb045e","src/bindings/swift/templates/TopLevelFunctionTemplate.swift":"4db57fd9baa14ca890d6f5416afafdb3a2318c44a58434d6160f61e4791a30f8","src/bindings/swift/templates/UInt16Helper.swift":"16adb3b50403dad114fad0b86bc220c5adc3bd987c57c290aee7c6407891dfbc","src/bindings/swift/templates/UInt32Helper.swift":"680ddd2815184f520723820f10698a089c222df0388bc0f7734c6d5234194aec","src/bindings/swift/templates/UInt64Helper.swift":"b752852162028a0c132f79f9005c47c263a4dab98833e86758cd7b467e305629","src/bindings/swift/templates/UInt8Helper.swift":"54f4821e704969eeb5c0e002b890d975a20eda3ddc3ee56169ee3c615dfa1079","src/bindings/swift/templates/macros.swift":"0141248dafedff630069f90e361aaa750a4044505f18502bd6e2d99ad09e699b","src/bindings/swift/templates/wrapper.swift":"436c35c3b91bb328fbe1830aea1d82195088c67ea397319c3e1d12984b40867d","src/interface/attributes.rs":"a97e4d0e9aee4c53e19ac085a60cce33649850b6a69f03f4d111dd32fa2b4b37","src/interface/callbacks.rs":"b6116ec9fd292cc958d75aaf1cd082b8581b2f61e0048c5cf05272c4e1cd418b","src/interface/enum_.rs":"bff40d304206a13e54ec9d62c74a5c47cdfff7575860397afa469496f2c33e72","src/interface/error.rs":"5d22a06827ed1d54ef604ada5926dc705954582e2b14414d48a1ae8a71f08d88","src/interface/ffi.rs":"dea51fcaa131ce9ca17118eb8351db048f1dc70b0105edc3c704d51622a785a5","src/interface/function.rs":"66ce91ebd229278da41b49114e24b68e85286af646752ffa1507b095713f86b1","src/interface/literal.rs":"3d2102cb47ff658f329d66d6c867b13a50e7f56535f23c1b414f857741360358","src/interface/mod.rs":"8155a462111e58e24539116c3d2c7deb958beef257b25657318045d96b65e750","src/interface/namespace.rs":"e6f3c494bcedc129ba48113f57e36c1f470b4930aa917888b9761073a74328aa","src/interface/object.rs":"b8e82683758ecbb8ea03ecbca4f86da332b2d99552b9a961b73125732103d353","src/interface/record.rs":"9789bc62ff758765e2ffb2b536f87a8b6f434cdc4abc15a35a037708a326f8ab","src/interface/types/finder.rs":"a54133ec4b04401234067be73f46bb0e211efaab781b8e6721cc24324d2bbda4","src/interface/types/mod.rs":"bc794dfd8bf32c0fe25af90f5184cca47e30bf046c1d1ecb579952a16a0dfd2f","src/interface/types/resolver.rs":"2047a564d08163d7d98975cdd0aeb5955ec2322e0e0528fc96bc22b5bcbbb9ad","src/lib.rs":"7d828df66f7aeee8e790a7a436fe29f4c239db34706423c013a00d41fc85f3d3","src/main.rs":"bbf8e9942d398387e7518533f9b9dc42bfa66156430a87a17605a80a356c0dea","src/scaffolding/mod.rs":"a2b69394a43996f3be2a5aa13cf6dc9db41f39962418a113d84a33727fa64a91","src/scaffolding/templates/CallbackInterfaceTemplate.rs":"ebf9e68e7c5be583de7b40457024804413d58a0bca71b49fdb2e0501bbe06e86","src/scaffolding/templates/EnumTemplate.rs":"dafd638727cdbe482d5fa9e894f17465c58f7f472e082a31f69c345e3db2898d","src/scaffolding/templates/ErrorTemplate.rs":"20ef4a3e818c831bc1e0f76f2e3b17e02361158728829bfcf9c43df3b7d64077","src/scaffolding/templates/ExternalTypesTemplate.rs":"166338dba83c288dccc053b363100587618ef614cfead5e66d62865ead9a51d5","src/scaffolding/templates/ObjectTemplate.rs":"464d2f16e52ce06e3bdf8a5b372e68c16cd7b2d56ebe0302ebf905650651cc8d","src/scaffolding/templates/RecordTemplate.rs":"37905d769a6ed7e53d7a8e64d1470d6ba558f1ad148df07e1ab804fbd3b64342","src/scaffolding/templates/ReexportUniFFIScaffolding.rs":"559a17c8e39c473ff1effe9651f05b83d443ecd8abed13e03f2b63872d7e1593","src/scaffolding/templates/RustBuffer.rs":"ccf7521012d93c41265375c6d2e80ce861ec93b41383da83c37718386dd726f6","src/scaffolding/templates/TopLevelFunctionTemplate.rs":"f06a96c32fdbcdf46531515493c75a379afb39ed50fc527853cfb720b02ffa88","src/scaffolding/templates/macros.rs":"996436f017c76bff92da0755f06f98085c05f68cafc0d4273b079c981b4c3a80","src/scaffolding/templates/scaffolding_template.rs":"dcd16ef1561c52d899d84f036ef2b7c07fcc85ba8f7a301e270cf8617f6598cb"},"package":"49a9810482e988792ed22fc6747d872bd32600f7e3bfc11fe93019d155d7e89c"} \ No newline at end of file +{"files":{"Cargo.lock":"f0e682ec13e3bb5864ebe0e482b3f177aa516f19653e15f8cea049aa3c4de558","Cargo.toml":"ff86e42652ae565f5bd63ee93ee9d1fe2ee9fd48c8bb84861e68772dd064c56f","askama.toml":"1a245b7803adca782837e125c49100147d2de0d5a1c949ff95e91af1701f6058","src/backend/config.rs":"4861dbf251dbb10beb1ed7e3eea7d79499a0de1cd9ce9ee8381a0e729c097dea","src/backend/declarations.rs":"12b8d6e651f84634de5cd02a47601965df7438f64f1a73f136bd89b6b5d515cf","src/backend/mod.rs":"899cd3b816d0467e35789b92ac3b8d5910f6dab98156d405db4803da8721fd36","src/backend/oracle.rs":"9e2b8a45af604a6e4952644e81f43f6aec6e0a1d03939c68b582529dd01a51e0","src/backend/types.rs":"43b738e442e74f5bae5826de55fd6e9a34985dc4d478b60b7ee50a1e6a194eba","src/bindings/kotlin/gen_kotlin/callback_interface.rs":"b7fe795670830f3aa8a955c787b1127fe68313ee751013948527948fe5526b01","src/bindings/kotlin/gen_kotlin/compounds.rs":"d1e9a4237ff2ff711a3eae7a564c39e26f598c156ebfd34c0f04879e3533dd4f","src/bindings/kotlin/gen_kotlin/custom.rs":"4176f6ed5f66504f8fd981198bbfbae795dab5ef0d0281881d19b697f5560c44","src/bindings/kotlin/gen_kotlin/enum_.rs":"f85ae8dcb55c8f274139bf321af0ba237ae69894165ad6bd693d793f58af8e5e","src/bindings/kotlin/gen_kotlin/error.rs":"867f583aea5da7aabeb9b6d2544d7e52984cdea4aa008ce5f2ec941074735e1a","src/bindings/kotlin/gen_kotlin/external.rs":"1f7e91d7439891fe3c403274e35880ee4fc3a0da555510bdfa23c1ed2bbd8020","src/bindings/kotlin/gen_kotlin/miscellany.rs":"644ee5bb1f3619be5a36b2b3900af554ea38073cd054004f421e69c3cb8d50bc","src/bindings/kotlin/gen_kotlin/mod.rs":"4e620cd6790c299ce8b87f27c65835c614dec861ecad4b4e6e461b0f7c9f3195","src/bindings/kotlin/gen_kotlin/object.rs":"6478a3e9d5e66186521730d0d481abd1ee4f123050ea050ac5a483842f08b003","src/bindings/kotlin/gen_kotlin/primitives.rs":"914d1f8253ed6a2937f67e8bd8f04f46aef4f22455ceb8a6caa84427adc2093e","src/bindings/kotlin/gen_kotlin/record.rs":"7961fcfbec5ebf8fc010b564ea4bd59402c919f6922898d48226d8c995569dd7","src/bindings/kotlin/mod.rs":"e68f2ea29e66ee62a56704e1e4464eea6d28bbdb52ab187bbe7a57ab3f362ea7","src/bindings/kotlin/templates/BooleanHelper.kt":"28e8a5088c8d58c9bfdbc575af8d8725060521fdd7d092684a8044b24ae567c7","src/bindings/kotlin/templates/CallbackInterfaceRuntime.kt":"6ede374b0fcbb3bcc939894e6f4729b3bec7ec7356831a60fba96ca38dc91aa8","src/bindings/kotlin/templates/CallbackInterfaceTemplate.kt":"22a289c3545fa8aa0973f40aada5bd0157cc2e2933e5cf1206d78b4603de86b9","src/bindings/kotlin/templates/CustomTypeTemplate.kt":"5d4dacf29e89bcdcc46d155d993e6059d2df704e775dc853469310198253b231","src/bindings/kotlin/templates/DurationHelper.kt":"414a98161538a26f3a9b357353270c1f245ad6ceed99496aca7162cf473a92fd","src/bindings/kotlin/templates/EnumTemplate.kt":"ab3e2063aad3b91188db839dceb59b854a6a8b60fb35e545e270e64fee7c73fa","src/bindings/kotlin/templates/ErrorTemplate.kt":"16fafca68672842bf8edd13a3b4eea0e0e98871cb640d1a09ef00a244a4c69d3","src/bindings/kotlin/templates/ExternalTypeTemplate.kt":"2097e0b830640ef18c79449ffa376d1dd35a8c4a5230e413c915f3b868aae872","src/bindings/kotlin/templates/FfiConverterTemplate.kt":"aa22962aaa9f641d48ccf44cb56d9f8a7736cbfaa01e1a1656662cfe5dd5c1d7","src/bindings/kotlin/templates/Float32Helper.kt":"662d95af3b629d143fb4d47cb7e9aa26ed28a5f3846de0341e28b0f9fb08bc25","src/bindings/kotlin/templates/Float64Helper.kt":"a77d099fa7d91e8702c1700e7949ffb6aaba9c6e8041ff48bab34b8e1fc9a0aa","src/bindings/kotlin/templates/Helpers.kt":"46c07798a26b53b06405c8bbbf86e3fcf38fadc1484ea04ce9d482defea89288","src/bindings/kotlin/templates/Int16Helper.kt":"7f83c4a48e1f3b2a59a3ca6a2662be8bc9baf3a5a748b31223cb3f51721ef249","src/bindings/kotlin/templates/Int32Helper.kt":"e02e4702175554b09fd2dd6ac3089dcd2c395f08ec60e762159566a9c9889450","src/bindings/kotlin/templates/Int64Helper.kt":"7a6fd6ca486852c89399c699935a9dfa1c32b9356d9a965cfde532581f05d9fa","src/bindings/kotlin/templates/Int8Helper.kt":"0554545494b6b9a76ce94f9c1723f8cf4230a13076feb75d620b1c9ca1ac4668","src/bindings/kotlin/templates/MapTemplate.kt":"399569d6443e8ad01e2deb95d78d8d2d15bf8eccee8be4fbe9ce4b8ebc0a6101","src/bindings/kotlin/templates/NamespaceLibraryTemplate.kt":"1eba4e77381155c2c96a6af2ef30fca881ade4957852f730fd10aa4f3d9cd3c4","src/bindings/kotlin/templates/ObjectRuntime.kt":"c11d233de41405caa55a56bcaa3bb69ce153ffa6fdff2aa218051929f5c4aeec","src/bindings/kotlin/templates/ObjectTemplate.kt":"b67e9508e1c958cc7454e72bee3a64f5bcca35adea46cfdda153bab6ac5a032c","src/bindings/kotlin/templates/OptionalTemplate.kt":"5f9f2c1baa829ed3c9b61c3edb0f1fccf5ea3cccc052a69cf8966715d8fcf149","src/bindings/kotlin/templates/RecordTemplate.kt":"193ecdad9322fb5483b95bf2a259270a9b22ba054790794e9abb3fd219196bc5","src/bindings/kotlin/templates/RustBufferTemplate.kt":"415637f80a78c12b3d00db063c14a7ab5c61b098bdb1fc81a0be8bae9511776b","src/bindings/kotlin/templates/SequenceTemplate.kt":"786693b20c608a4f059b91df115278f5f12122b4c14a2e7ce18b6fc9b22b1296","src/bindings/kotlin/templates/StringHelper.kt":"060839663580d8199671b7c3bb3dce5e9106aa766ce2c6e0afc2d2bd788a1d83","src/bindings/kotlin/templates/TimestampHelper.kt":"353c2890f06ad6dda238e9aebb4bdff7bb838e17e46abf351ed3ff1fbc4e6580","src/bindings/kotlin/templates/TopLevelFunctionTemplate.kt":"31405f60ef1f8169ac2a3ac65186d2532c9923a7c43b54c352dedd389a98ed70","src/bindings/kotlin/templates/Types.kt":"db7ed7384b4391a4bc1425ec3a89e0c890538ad30f5e115bae4998c059c8a21b","src/bindings/kotlin/templates/UInt16Helper.kt":"e84a1f30a5a899ba2c5db614d3f3c74f25bccf6dd99bf68b8830829332d051e9","src/bindings/kotlin/templates/UInt32Helper.kt":"7cdf08cc580046935f27ba07b53685968608a102e0a6be305111037c63d7ddf8","src/bindings/kotlin/templates/UInt64Helper.kt":"fd7baacbf3ab6202ff83edcc66e5f7beb11a10053ba66d0b49547616cc7cbe1f","src/bindings/kotlin/templates/UInt8Helper.kt":"bbf5a6d66c995aea9fe2fa9840c6bfa78b03520a09469b984f0e1d43191e453a","src/bindings/kotlin/templates/macros.kt":"2e8aed970ebed853b0cd68709bbc659948dd622ef8e2dfa1935b8d7e8c99f5cb","src/bindings/kotlin/templates/wrapper.kt":"dd81cf28a4e07c685d29c87a4053eccb6339835cfc7fce3cf581d3d111fed4f5","src/bindings/mod.rs":"51ac55a3d505d5a88eedc83cf12623c2738277a9cd22bf3bbe05be1244de078b","src/bindings/python/gen_python/callback_interface.rs":"e3ffb8ba1aa8ac8ddcfff6554e7ec0d2d695d12955a98a04d114d2d6ca5dacc8","src/bindings/python/gen_python/compounds.rs":"e406c773c3b66368ea74973df742cdcba3014521812048f15de7c0e783eedfaf","src/bindings/python/gen_python/custom.rs":"33756f6bdafbd9b1a3a439c1cced3c83dc1fdb82b5ec235c064e69670ea6086c","src/bindings/python/gen_python/enum_.rs":"634c8406b07cbd24ea4f71cae4c971169e4989ce8019188f4bcd515bc3c77c5d","src/bindings/python/gen_python/error.rs":"d1a3b3edb91d9502064463cc3324770a1a6e0f234d6b49b5d7c43636bfe81d59","src/bindings/python/gen_python/external.rs":"8920b7a2a3b39a9647ec17cdff44308db3bfe9a582f026b060003edd76407599","src/bindings/python/gen_python/miscellany.rs":"f3898b75cf494b39662d886eb78d9cc06685650265fc8a1e87e5de67baa342ae","src/bindings/python/gen_python/mod.rs":"83aabf3fe84466518cb3a1c0145ffdbcff2e4e8df55104d365ef0546ea8a12c5","src/bindings/python/gen_python/object.rs":"b4d3d8a935d4acd689cf1f3857d461dbab3a51c7c8bd821890198fb58ef3a63f","src/bindings/python/gen_python/primitives.rs":"928523bb91d2192d615d044f1fef3714681140562b740cf72dce3168e660e276","src/bindings/python/gen_python/record.rs":"f961dfe8dd1e5caa633754de7ecc684c2211c9b6633a5e6beb6053e60500b9f2","src/bindings/python/mod.rs":"bcf295b334b332c7fd1214ddfdaa727cfe37fed531c3862ce25906b3a70b71c7","src/bindings/python/templates/BooleanHelper.py":"d384ffeefcb5982c4875e819d06e919a295eaa9ff57735e6fef0801bb810d5c9","src/bindings/python/templates/CallbackInterfaceRuntime.py":"7ffef485fc008e2d9efcd07326102f300bd4673b4351353e9e2908355936c3d7","src/bindings/python/templates/CallbackInterfaceTemplate.py":"d083f14226bff668f70b02a78dade850b6bff5026febf8d2a9b46db5c0cb66ff","src/bindings/python/templates/CustomType.py":"db3309b3f944fb813d4cef47a04d67a86f824183f7e31289184683155fd985d9","src/bindings/python/templates/DurationHelper.py":"179c14dccd8cc7dc9791f896414f0b5d124ec116eb78173371bd8a0743208da1","src/bindings/python/templates/EnumTemplate.py":"825ca373286f1b3b252b8a1263e29c9e2f0d3e170ceb364bd6c28d6c4595597b","src/bindings/python/templates/ErrorTemplate.py":"943924ec1d3b39d27a5742265bdd1a568591bdc4853ad2ce88446fa2f1b34dfd","src/bindings/python/templates/ExternalTemplate.py":"f582a6e872fe9f8275d33d36ffe017028ca459fe7c53aa680a2512718d0c0fda","src/bindings/python/templates/Float32Helper.py":"7dbc51889cff47ebf1600fad490849e4a87cac4fc0d1756eebd21609eb80b4a9","src/bindings/python/templates/Float64Helper.py":"ba9f334d1339b6eaedcacc1e35068939727170a684f41dec9ee04762ed98cec1","src/bindings/python/templates/Helpers.py":"68f03f651c38c810fa453e123e26f7c94b7a1f9178e0d863b985c3c8fabaa642","src/bindings/python/templates/Int16Helper.py":"60c22fb8b445841ebb3c68be11b81c9eba84a680eaa0e30770953361231da9b5","src/bindings/python/templates/Int32Helper.py":"aff0a017cf767394174e46d8c4fe5a5a704a8e6384fcc38d227634dfe7826916","src/bindings/python/templates/Int64Helper.py":"6c314b91699a6c6ad7db3ef636713bc2a0af9609c82acfd6062b0588177c0026","src/bindings/python/templates/Int8Helper.py":"a6e2d121b1a6d59886fceab3949e571aba1abc06dfede52666954bf15366fb6f","src/bindings/python/templates/MapTemplate.py":"bbe609b865010b98b38c58f2d4fcc97f2adec3e931903bf67263a5e440a84400","src/bindings/python/templates/NamespaceLibraryTemplate.py":"4726dbeb61508a71153436126bc04d03af966dca4f5b37511beb8bcfb6f1f307","src/bindings/python/templates/ObjectTemplate.py":"68302f6da6e4e80fc0cc8eb4ef2d4353d19ad3e9955112a2fabec8bf1b1293c7","src/bindings/python/templates/OptionalTemplate.py":"ab6da433370ba7c1316e266247ee1b7165bc02f6f288e40a7c68806c018e3282","src/bindings/python/templates/RecordTemplate.py":"98cef2adbc2b890e5c67257fb32a57380070988ef4112408eeca85e0b87b566b","src/bindings/python/templates/RustBufferHelper.py":"11f733051e63733c637fb19c4758cb58a40d045792028465f36891f89c7c5f36","src/bindings/python/templates/RustBufferTemplate.py":"90950cfeeb7a028aac9b65aeca897b217eddcfa165a0d59e8af037e834f34146","src/bindings/python/templates/SequenceTemplate.py":"faf2b1d5272a66258972d88c29d5b527cf9e589c8399e30f7ad5a0503133ce9b","src/bindings/python/templates/StringHelper.py":"941a7ad71d9598701efa15323df93766934583a55f4266d26db31e6b744603fc","src/bindings/python/templates/TimestampHelper.py":"b412cea69117858c05bae3210d378c6296658ed02a50e87c52c392dcb62c7892","src/bindings/python/templates/TopLevelFunctionTemplate.py":"2b2883b14f324e543cfeea5293d2a4907fa9ebe93b779da7174a58929d8b0442","src/bindings/python/templates/Types.py":"2eee78ca838f65b7e8ff8f760558c71ca80ad314aaa44efd1d1b8e13b349f1bc","src/bindings/python/templates/UInt16Helper.py":"06be5c9dacdf20e586f8236ed75cf2ca2470078fd8570843ea97c581b25bf860","src/bindings/python/templates/UInt32Helper.py":"41bb9bbf9b7be1060945e1267b1cc052585ec43696b1591f0ee779a0be0feaff","src/bindings/python/templates/UInt64Helper.py":"ba2825fc295a07292d9fb4aeebe74dabb9e6dbe505643e2347875ab12e511f31","src/bindings/python/templates/UInt8Helper.py":"dca5b3fc4a429fb233326224f85c4eccd3a7802ca9958ec309c7f197d59b4e3d","src/bindings/python/templates/macros.py":"3f02a32941e20aea15e136780c24c9695021dbcae08044c4f654f75aadcbd1e1","src/bindings/python/templates/wrapper.py":"627a6e18e72040909887261b8ad918c68104b15110df26b2205d7827c690e8c3","src/bindings/ruby/gen_ruby/mod.rs":"9f9a0e58f51f97935f7a2860b6d95c3a689d3a01dc0dcf46fdecbdf9d76d0e96","src/bindings/ruby/gen_ruby/tests.rs":"7dcb86b08e643c43503f4cac6396833497f6988b004321c0067700ee29ffbf32","src/bindings/ruby/mod.rs":"f57fccdfc544210e8cc70e01e4991cee6e72d258ede9d2bb226baad24a3ef0d7","src/bindings/ruby/templates/EnumTemplate.rb":"5480edb347f5829e478d19474691babd72f37616ed846d519b5a61cb1d6cf047","src/bindings/ruby/templates/ErrorTemplate.rb":"89f24a19f70af1d04090f9b1ffd3229ec987c7dc866cfee6819f06d15d7b6e1f","src/bindings/ruby/templates/NamespaceLibraryTemplate.rb":"9b1454208bc83ef8f26aef33713d681e2284dbfea986ec0dd6c9b9c8b7d65e4a","src/bindings/ruby/templates/ObjectTemplate.rb":"c2d2fa2db62d48322b66b53888dcc6de2fc3e579a6b8d0a9f24029c18fffcbb5","src/bindings/ruby/templates/RecordTemplate.rb":"4aeff886928ca972e5dc9b799581b30c66a6f6dce446af3285dd3ed6b422dea9","src/bindings/ruby/templates/RustBufferBuilder.rb":"9f117e844092dbeeb66ee5453c95aa4a67a5edcafbd103435280070fb924d76c","src/bindings/ruby/templates/RustBufferStream.rb":"3c28de360692a64e4f0e2db96f2f8a8dc0d9e67dd1292a981d8af6c6c810cd8c","src/bindings/ruby/templates/RustBufferTemplate.rb":"e0cd9771d06f2026ea1040f67c90e2b37154906c2f1ee0a0e1352aaf1523275f","src/bindings/ruby/templates/TopLevelFunctionTemplate.rb":"88213e7e25bef664da939c04dd5621f438af735ffcb4d2d0c24a529538630069","src/bindings/ruby/templates/macros.rb":"c0e07ee89247aba8340d95972e187e954be6a033f363a8770f16e40aaf350abc","src/bindings/ruby/templates/wrapper.rb":"542cdf46fb871e66089c9f008cf472cca411fe217d8c66a0a66776c35469aab5","src/bindings/swift/gen_swift/callback_interface.rs":"e331871ac6c9ac9b9533848fb6ddfcabc1e605970343cad307b6d86b72ebe96a","src/bindings/swift/gen_swift/compounds.rs":"b86c1ae0bd32e74551bf05219a5b8edf8d6d88b2ee8b8f9296055171f2cbaf8d","src/bindings/swift/gen_swift/custom.rs":"45cdfa35ef7345dc353d0d2f3cebb17d726e90abdf5ef49422d6b2db65f8fd25","src/bindings/swift/gen_swift/enum_.rs":"018eea78ef85c9f8d715a5bc15c8273030d4f6ba297019949eb578c5cc6276fd","src/bindings/swift/gen_swift/error.rs":"bd95c3303e40f03a321f2cdc8e15a0251f4c7ddbc3c32c4c57eb9569db218488","src/bindings/swift/gen_swift/miscellany.rs":"66f16968f6cccc0b61c544e336a49b96218551731dcce566a176903c9afb3b57","src/bindings/swift/gen_swift/mod.rs":"594a44e31b47f1a858ac07e43d4c6c95cd51f7ed35b1467537502dd47674cd33","src/bindings/swift/gen_swift/object.rs":"072a44f484cc66694c57a9fa41ba50a531c9ce19738e11ce9df17cdfc007648f","src/bindings/swift/gen_swift/primitives.rs":"b37b8f3ad3aa7e769e6d465a31282e377f93cd69e4dcf39a56dc833f412ed412","src/bindings/swift/gen_swift/record.rs":"48296332960be3731b9139dc664d4b8a5d56d04cffa34dc995b62cf202b4dbfd","src/bindings/swift/mod.rs":"0ad4afd667ef17b3b577ded9a09cdaa5595afbdb24e7474c6b1e6a8e0a024593","src/bindings/swift/templates/BooleanHelper.swift":"f607928c4d598893421fe9c9f183bab2f23a877a07afeb123dbe90515249ec86","src/bindings/swift/templates/BridgingHeaderTemplate.h":"93a289e393ecdbe1bf986215c3b19d2aed7677d47f79b1833ce73cf6f8762e80","src/bindings/swift/templates/CallbackInterfaceRuntime.swift":"aac01eb4269151be9dde8c95ee8eba7e8d0841b3c2b1dbd88885f01ac64ee147","src/bindings/swift/templates/CallbackInterfaceTemplate.swift":"d50e1b06e632007ad094e1dadfeb06f7b17076d6f4956c6d38a1de7b98a56132","src/bindings/swift/templates/CustomType.swift":"fe6414f2ce3ea7b148742e2fecf2206d7e69935dd78d56e014aec70f4d6ad3ec","src/bindings/swift/templates/DurationHelper.swift":"bca4a6498b27fe0c877df3c7fbe148538eeda03e68d4e760a7c8a6a15f2067ff","src/bindings/swift/templates/EnumTemplate.swift":"e61bdf7949aa5a7b55a2c10c243e960f683c862e5977f06e7f5956646b4ccb49","src/bindings/swift/templates/ErrorTemplate.swift":"58fb5907d20b7a6db67b128e5f6350015278990fef5945be42477a5b5f82bb18","src/bindings/swift/templates/Float32Helper.swift":"6c1a4da059dd4c6c4392511c93fe9daf4ddeeab71e39afd122797b0e19254318","src/bindings/swift/templates/Float64Helper.swift":"f741568cdfb8e1421369a9a1dc845630a3a0e2dc2d6acf157afd80cd3ef5966f","src/bindings/swift/templates/Helpers.swift":"3cf3a5342a1ef0c7e078b0e58c32ae4437c4fb5dc41acbbd56b1128393c76602","src/bindings/swift/templates/Int16Helper.swift":"76eec2a54a65790c5959380cc9a7362b1e2e201632cccb789153c52e10c8dc4f","src/bindings/swift/templates/Int32Helper.swift":"5afc5e103bf637813fd4b77ab63e47ed38893525101a483218a339f222710061","src/bindings/swift/templates/Int64Helper.swift":"c1a6f6661ef1ad3bd00e8d0bf81adaa6539686eee2b481b046b76dbd87681adf","src/bindings/swift/templates/Int8Helper.swift":"bc46598c966e579cca22d336748c74cdce5674eaaaf75fc24e5fdaa36a43cf9c","src/bindings/swift/templates/MapTemplate.swift":"8b5a9cb41a1ad41b5566fbe3906a1449e5453289208a9fc6a611de1eb937142a","src/bindings/swift/templates/ModuleMapTemplate.modulemap":"99ad1e9bf550a21497296f9248ecd4385dd6d0b5892951d24cf990cdbf3eec2c","src/bindings/swift/templates/ObjectTemplate.swift":"98f744d7baf41e28d9184ae7e1aa9522b1bd951d507e0987879b11d7995782aa","src/bindings/swift/templates/OptionalTemplate.swift":"73f777d2df4fdf42daf0d6035436d168b0d5f0abc15153b97029bc305408f597","src/bindings/swift/templates/RecordTemplate.swift":"af0dc13b32d34254b4cfef3b74f52fd4611aa6c32e055e203414511fd3bbb00a","src/bindings/swift/templates/RustBufferTemplate.swift":"ed16f20cecd264f086c923cd92a5198f444aec99aad4d39e9012f09f530ca809","src/bindings/swift/templates/SequenceTemplate.swift":"977f1409909ff08018c0a80c1330737023b39a8f9fa9a13f5bf9ab4806cac199","src/bindings/swift/templates/StringHelper.swift":"b773c2b3a03f30338ff233881d1b0c0238831b812eff6eb9f0fafcb32ab0743a","src/bindings/swift/templates/TimestampHelper.swift":"6e22e370feae1199bff16bcc6f431decfb7700b02e6afdd84693a0c474eb045e","src/bindings/swift/templates/TopLevelFunctionTemplate.swift":"ca7fcbaa06ee31c7433fd6aa238b6c1135a843f469d9b4f37d4874d514fd80d0","src/bindings/swift/templates/Types.swift":"2f42430cb4ffba8e9b5084c0cf8790fb5bae151878134b8a21e745acf75d2b08","src/bindings/swift/templates/UInt16Helper.swift":"16adb3b50403dad114fad0b86bc220c5adc3bd987c57c290aee7c6407891dfbc","src/bindings/swift/templates/UInt32Helper.swift":"680ddd2815184f520723820f10698a089c222df0388bc0f7734c6d5234194aec","src/bindings/swift/templates/UInt64Helper.swift":"b752852162028a0c132f79f9005c47c263a4dab98833e86758cd7b467e305629","src/bindings/swift/templates/UInt8Helper.swift":"54f4821e704969eeb5c0e002b890d975a20eda3ddc3ee56169ee3c615dfa1079","src/bindings/swift/templates/macros.swift":"0141248dafedff630069f90e361aaa750a4044505f18502bd6e2d99ad09e699b","src/bindings/swift/templates/wrapper.swift":"ca1af5fe47bca972c76fb8c9f52b18f727d4343204408de3dd0aae384f0a4171","src/interface/attributes.rs":"2f76377eebdd62e770bb9089885482a49a57e1f8405320bb778353f3e8974447","src/interface/callbacks.rs":"289e053160e71439a5d15b9376863bb073692e02c97872297d4e3003475b3436","src/interface/enum_.rs":"9dd600e6582c10dfb410cf9b5f61e46c772714a82daea69066555e7529a66a9b","src/interface/error.rs":"f31fc0a7e41b4c8f4b81d06958fda14af6f05bfa318206098e0ec351cf4db809","src/interface/ffi.rs":"22d24e4dda327fa78c7632a6e5bbe374ecac0165acc550007feb729d8f4d6adf","src/interface/function.rs":"d769806d0553f6dbd8d8e1f555e85b1d0a7ab24545b189a0558d7bcbb60fe62f","src/interface/literal.rs":"3d2102cb47ff658f329d66d6c867b13a50e7f56535f23c1b414f857741360358","src/interface/mod.rs":"570d5e259171c23336171b972730fbf379f7a9136ca5385e7ca9307012e3f90d","src/interface/namespace.rs":"ab0f63241bb6a0a32f9fd2a1544468cb6daa1f91f6116b7246b52a4a94e4f461","src/interface/object.rs":"c5827d9e96c268a36aedcdd9140861af8f0141251ad5964af5f3597da101593a","src/interface/record.rs":"02e19d90634a94ac72200f4f7aeff04ee696f4bc4c9daac4be46ddfcb8ce0b83","src/interface/types/finder.rs":"a27f24e64b5bfc796378d1012b5e72001f0a442e8185fdc4430b106595d4b819","src/interface/types/mod.rs":"f9b8cac26199ae01820f6d2c09e981db9575f928d91fb57e99e95d294c0bc741","src/interface/types/resolver.rs":"63b478ef4a4e6f8fa8f2084fca90ac07c869a7c817334add014cd94b8c79fc52","src/lib.rs":"12510e082c24e61e94101162bb4a956f7cb540d279b4cbbd91c425d1bc6132a2","src/main.rs":"bbf8e9942d398387e7518533f9b9dc42bfa66156430a87a17605a80a356c0dea","src/scaffolding/mod.rs":"3e1254b3ff08adaeba5e60c3ce1740bfb5ee44f4793b6c3c45c86a361645289e","src/scaffolding/templates/CallbackInterfaceTemplate.rs":"1c011bc4ca21af7ddda488dc3e8fc3f40dfb23f228e47e649f770f43989ce8bf","src/scaffolding/templates/EnumTemplate.rs":"eb8802f04f1fd1c9451ad72c1195c136288fdb4e488922b24db75b2fdae65cd7","src/scaffolding/templates/ErrorTemplate.rs":"7bed0545e475fec4d9766a41db2a966457110b0372034c5df5e540bc5393a6b5","src/scaffolding/templates/ExternalTypesTemplate.rs":"8ecc805cf119abac8c5f60605f9183ee9ec8d37f9ec75bba5e18bb8b482a1abb","src/scaffolding/templates/ObjectTemplate.rs":"4b1c1be6cc652ac6577ad28b654874c730fbf6dfcd54c3e45dfe4cba6a1585f4","src/scaffolding/templates/RecordTemplate.rs":"e8d5af954f46f023a243721d6fc70aa176c3a4c0a9dd340048bfe46f3eeed783","src/scaffolding/templates/ReexportUniFFIScaffolding.rs":"559a17c8e39c473ff1effe9651f05b83d443ecd8abed13e03f2b63872d7e1593","src/scaffolding/templates/RustBuffer.rs":"ccf7521012d93c41265375c6d2e80ce861ec93b41383da83c37718386dd726f6","src/scaffolding/templates/TopLevelFunctionTemplate.rs":"4aad8a043cc45f4febc2c674835d146fc4c8dbcaa8512049d941eb4624001ac5","src/scaffolding/templates/macros.rs":"a41c9690d411074c59fc4609f897431669b9d939625a08f5304a71a88901ba7c","src/scaffolding/templates/scaffolding_template.rs":"3589f8e8e1f9b194ff4a6245665d3a421c771dec3cc947c4264bfcd34573550e"},"package":"b18e05c55840ddd690ba211f72bb1f2f6ca8c50bfeb7d7211ea5ee60b0f9be07"} \ No newline at end of file diff --git a/third_party/rust/uniffi_bindgen/Cargo.lock b/third_party/rust/uniffi_bindgen/Cargo.lock index 117418f286d5..c5127748beb9 100644 --- a/third_party/rust/uniffi_bindgen/Cargo.lock +++ b/third_party/rust/uniffi_bindgen/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" [[package]] name = "askama" @@ -77,10 +77,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "camino" -version = "1.0.7" +name = "bitvec" +version = "0.19.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f3132262930b0522068049f5870a856ab8affc80c70d08b6ecb785771a6fc23" +checksum = "55f93d0ef3363c364d5976646a38f04cf67cfe1d4c8d160cdea02cab2c116b33" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "camino" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "869119e97797867fd90f5e22af7d0bd274bd4635ebb9eb68c04f3f513ae6c412" dependencies = [ "serde", ] @@ -96,23 +108,22 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.13.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081e3f0755c1f380c2d010481b6fa2e02973586d5f2b24eebb7a2a1d98b143d8" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", "semver", - "semver-parser", "serde", "serde_json", ] [[package]] name = "clap" -version = "3.1.15" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85a35a599b11c089a7f49105658d089b8f2cf0882993c17daf6de15285c2c35d" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" dependencies = [ "atty", "bitflags", @@ -127,9 +138,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.1.7" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1" +checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" dependencies = [ "heck", "proc-macro-error", @@ -140,18 +151,30 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.0" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" dependencies = [ "os_str_bytes", ] [[package]] -name = "hashbrown" -version = "0.11.2" +name = "fs-err" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "5bd79fa345a495d3ae89fb7165fec01c0e72f41821d642dda363a1e97975652e" + +[[package]] +name = "funty" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" + +[[package]] +name = "hashbrown" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" [[package]] name = "heck" @@ -170,9 +193,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.8.1" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown", @@ -180,9 +203,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "lazy_static" @@ -192,15 +215,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.125" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "memchr" -version = "2.5.0" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "mime" @@ -226,10 +249,12 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "nom" -version = "5.1.2" +version = "6.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +checksum = "9c5c51b9083a3c620fa67a2a635d1ce7d95b897e957d6b28ff9a5da960a103a6" dependencies = [ + "bitvec", + "funty", "memchr", "version_check", ] @@ -246,9 +271,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.0.0" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" [[package]] name = "paste" @@ -256,15 +281,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -291,61 +307,57 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.37" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1" +checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ "proc-macro2", ] [[package]] -name = "ryu" -version = "1.0.9" +name = "radium" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" + +[[package]] +name = "ryu" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" [[package]] name = "semver" -version = "0.11.0" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" dependencies = [ - "semver-parser", "serde", ] -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" -version = "1.0.137" +version = "1.0.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.137" +version = "1.0.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" dependencies = [ "proc-macro2", "quote", @@ -354,9 +366,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" dependencies = [ "itoa", "ryu", @@ -371,15 +383,21 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.92" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52" +checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "termcolor" version = "1.1.3" @@ -404,12 +422,6 @@ dependencies = [ "serde", ] -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" - [[package]] name = "unicase" version = "2.6.0" @@ -420,20 +432,23 @@ dependencies = [ ] [[package]] -name = "unicode-xid" -version = "0.2.3" +name = "unicode-ident" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" [[package]] name = "uniffi_bindgen" -version = "0.18.0" +version = "0.19.3" dependencies = [ "anyhow", "askama", + "camino", "cargo_metadata", "clap", + "fs-err", "heck", + "lazy_static", "paste", "serde", "toml", @@ -448,11 +463,12 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "weedle2" -version = "2.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8655cb807b9f5c665d199c735dae90e10230eae6ae5cf009d3506963214fe451" +checksum = "5d730d941cf471131c40a64cf2e8a595822009f51e64c05c5afdbc85af155857" dependencies = [ - "nom 5.1.2", + "fs-err", + "nom 6.2.1", ] [[package]] @@ -485,3 +501,9 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" diff --git a/third_party/rust/uniffi_bindgen/Cargo.toml b/third_party/rust/uniffi_bindgen/Cargo.toml index 09cbdd33b0ab..a519c40ff30d 100644 --- a/third_party/rust/uniffi_bindgen/Cargo.toml +++ b/third_party/rust/uniffi_bindgen/Cargo.toml @@ -10,9 +10,9 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" +edition = "2021" name = "uniffi_bindgen" -version = "0.18.0" +version = "0.19.3" authors = ["Firefox Sync Team "] description = "a multi-language bindings generator for rust (codegen and cli tooling)" homepage = "https://mozilla.github.io/uniffi-rs" @@ -23,6 +23,7 @@ keywords = [ ] license = "MPL-2.0" repository = "https://github.com/mozilla/uniffi-rs" +resolver = "2" [[bin]] name = "uniffi-bindgen" @@ -36,20 +37,29 @@ version = "0.11" features = ["config"] default-features = false +[dependencies.camino] +version = "1.0.8" + [dependencies.cargo_metadata] -version = "0.13" +version = "0.14" [dependencies.clap] -version = "3" +version = "~3.1" features = [ "cargo", "std", "derive", ] +[dependencies.fs-err] +version = "2.7.0" + [dependencies.heck] version = "0.4" +[dependencies.lazy_static] +version = "1.4" + [dependencies.paste] version = "1.0" @@ -60,4 +70,4 @@ version = "1" version = "0.5" [dependencies.weedle2] -version = "2.0.0" +version = "3.0.0" diff --git a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs index 34b3b09e6c7f..f062bd2404d7 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs @@ -6,7 +6,7 @@ use std::borrow::Borrow; use std::cell::RefCell; use std::collections::{BTreeSet, HashMap, HashSet}; -use anyhow::Result; +use anyhow::{Context, Result}; use askama::Template; use heck::{ToLowerCamelCase, ToShoutySnakeCase, ToUpperCamelCase}; use serde::{Deserialize, Serialize}; @@ -89,7 +89,7 @@ impl MergeWith for Config { pub fn generate_bindings(config: &Config, ci: &ComponentInterface) -> Result { KotlinWrapper::new(config.clone(), ci) .render() - .map_err(|_| anyhow::anyhow!("failed to render kotlin bindings")) + .context("failed to render kotlin bindings") } /// Renders Kotlin helper code for all types @@ -174,7 +174,6 @@ impl<'a> KotlinWrapper<'a> { pub fn initialization_fns(&self) -> Vec { self.ci .iter_types() - .into_iter() .filter_map(|t| t.initialization_fn(&KotlinCodeOracle)) .collect() } @@ -241,12 +240,12 @@ impl CodeOracle for KotlinCodeOracle { /// Get the idiomatic Kotlin rendering of a function name. fn fn_name(&self, nm: &str) -> String { - nm.to_string().to_lower_camel_case() + format!("`{}`", nm.to_string().to_lower_camel_case()) } /// Get the idiomatic Kotlin rendering of a variable name. fn var_name(&self, nm: &str) -> String { - nm.to_string().to_lower_camel_case() + format!("`{}`", nm.to_string().to_lower_camel_case()) } /// Get the idiomatic Kotlin rendering of an individual enum variant. @@ -260,14 +259,11 @@ impl CodeOracle for KotlinCodeOracle { /// "Error" for any type of error but in the Java world, "Error" means a non-recoverable error /// and is distinguished from an "Exception". fn error_name(&self, nm: &str) -> String { - let name = nm.to_string(); + // errors are a class in kotlin. + let name = self.class_name(nm); match name.strip_suffix("Error") { None => name, - Some(stripped) => { - let mut kt_exc_name = stripped.to_owned(); - kt_exc_name.push_str("Exception"); - kt_exc_name - } + Some(stripped) => format!("{}Exception", stripped), } } @@ -282,7 +278,7 @@ impl CodeOracle for KotlinCodeOracle { FFIType::Int64 | FFIType::UInt64 => "Long".to_string(), FFIType::Float32 => "Float".to_string(), FFIType::Float64 => "Double".to_string(), - FFIType::RustArcPtr => "Pointer".to_string(), + FFIType::RustArcPtr(_) => "Pointer".to_string(), FFIType::RustBuffer => "RustBuffer.ByValue".to_string(), FFIType::ForeignBytes => "ForeignBytes.ByValue".to_string(), FFIType::ForeignCallback => "ForeignCallback".to_string(), @@ -364,11 +360,8 @@ pub mod filters { Ok(oracle().enum_variant_name(nm)) } - /// Get the idiomatic Kotlin rendering of an exception name - /// - /// This replaces "Error" at the end of the name with "Exception". Rust code typically uses - /// "Error" for any type of error but in the Java world, "Error" means a non-recoverable error - /// and is distinguished from an "Exception". + /// Get the idiomatic Kotlin rendering of an exception name, replacing + /// `Error` with `Exception`. pub fn exception_name(nm: &str) -> Result { Ok(oracle().error_name(nm)) } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/mod.rs b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/mod.rs index 2b8d82e1cf1f..c80b4be93a81 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/mod.rs @@ -3,14 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use anyhow::{bail, Context, Result}; -use std::{ - env, - ffi::OsString, - fs::File, - io::Write, - path::{Path, PathBuf}, - process::Command, -}; +use camino::{Utf8Path, Utf8PathBuf}; +use fs_err::{self as fs, File}; +use std::{env, ffi::OsString, io::Write, process::Command}; pub mod gen_kotlin; pub use gen_kotlin::{generate_bindings, Config}; @@ -20,23 +15,19 @@ use super::super::interface::ComponentInterface; pub fn write_bindings( config: &Config, ci: &ComponentInterface, - out_dir: &Path, + out_dir: &Utf8Path, try_format_code: bool, ) -> Result<()> { - let mut kt_file = full_bindings_path(config, out_dir)?; - std::fs::create_dir_all(&kt_file)?; + let mut kt_file = full_bindings_path(config, out_dir); + fs::create_dir_all(&kt_file)?; kt_file.push(format!("{}.kt", ci.namespace())); - let mut f = File::create(&kt_file).context("Failed to create .kt file for bindings")?; + let mut f = File::create(&kt_file)?; write!(f, "{}", generate_bindings(config, ci)?)?; if try_format_code { - if let Err(e) = Command::new("ktlint") - .arg("-F") - .arg(kt_file.to_str().unwrap()) - .output() - { + if let Err(e) = Command::new("ktlint").arg("-F").arg(&kt_file).output() { println!( "Warning: Unable to auto-format {} using ktlint: {:?}", - kt_file.file_name().unwrap().to_str().unwrap(), + kt_file.file_name().unwrap(), e ) } @@ -44,18 +35,21 @@ pub fn write_bindings( Ok(()) } -fn full_bindings_path(config: &Config, out_dir: &Path) -> Result { - let package_path: PathBuf = config.package_name().split('.').collect(); - Ok(PathBuf::from(out_dir).join(package_path)) +fn full_bindings_path(config: &Config, out_dir: &Utf8Path) -> Utf8PathBuf { + let package_path: Utf8PathBuf = config.package_name().split('.').collect(); + Utf8PathBuf::from(out_dir).join(package_path) } /// Generate kotlin bindings for the given namespace, then use the kotlin /// command-line tools to compile them into a .jar file. -pub fn compile_bindings(config: &Config, ci: &ComponentInterface, out_dir: &Path) -> Result<()> { - let mut kt_file = full_bindings_path(config, out_dir)?; +pub fn compile_bindings( + config: &Config, + ci: &ComponentInterface, + out_dir: &Utf8Path, +) -> Result<()> { + let mut kt_file = full_bindings_path(config, out_dir); kt_file.push(format!("{}.kt", ci.namespace())); - let mut jar_file = PathBuf::from(out_dir); - jar_file.push(format!("{}.jar", ci.namespace())); + let jar_file = out_dir.join(format!("{}.jar", ci.namespace())); let status = Command::new("kotlinc") // Our generated bindings should not produce any warnings; fail tests if they do. .arg("-Werror") @@ -76,7 +70,7 @@ pub fn compile_bindings(config: &Config, ci: &ComponentInterface, out_dir: &Path /// Execute the specifed kotlin script, with classpath based on the generated // artifacts in the given output directory. -pub fn run_script(out_dir: &Path, script_file: &Path) -> Result<()> { +pub fn run_script(out_dir: &Utf8Path, script_file: &Utf8Path) -> Result<()> { let mut cmd = Command::new("kotlinc"); // Make sure it can load the .jar and its dependencies. cmd.arg("-classpath").arg(classpath_for_testing(out_dir)?); @@ -97,8 +91,8 @@ pub fn run_script(out_dir: &Path, script_file: &Path) -> Result<()> { } // Calculate the classpath string to use for testing -pub fn classpath_for_testing(out_dir: &Path) -> Result { - let mut classpath = env::var_os("CLASSPATH").unwrap_or_else(|| OsString::from("")); +pub fn classpath_for_testing(out_dir: &Utf8Path) -> Result { + let mut classpath = env::var_os("CLASSPATH").unwrap_or_default(); // This lets java find the compiled library for the rust component. classpath.push(":"); classpath.push(out_dir); @@ -107,7 +101,7 @@ pub fn classpath_for_testing(out_dir: &Path) -> Result { // Including all .jar files is needed for tests like ext-types that use multiple UDL files. // TODO: Instead of including all .jar files, we should only include jar files that we // previously built for this test. - for entry in PathBuf::from(out_dir) + for entry in out_dir .read_dir() .context("Failed to list target directory when running Kotlin script")? { diff --git a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/TopLevelFunctionTemplate.kt b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/TopLevelFunctionTemplate.kt index cc370c826086..d43038ae1123 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/TopLevelFunctionTemplate.kt +++ b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/TopLevelFunctionTemplate.kt @@ -10,7 +10,7 @@ fun {{ func.name()|fn_name }}({%- call kt::arg_list_decl(func) -%}): {{ return_t return {{ return_type|lift_fn }}({% call kt::to_ffi_call(func) %}) } -{% when None -%} +{% when None %} fun {{ func.name()|fn_name }}({% call kt::arg_list_decl(func) %}) = {% call kt::to_ffi_call(func) %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/Types.kt b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/Types.kt index 7c160efd5f29..6379971b76eb 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/Types.kt +++ b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/Types.kt @@ -7,7 +7,7 @@ {%- let contains_object_references = ci.item_contains_object_references(type_) %} {# - # Map `Type` instances to a `Box` for that type. + # Map `Type` instances to an include statement for that type. # # There is a companion match in `KotlinCodeOracle::create_code_type()` which performs a similar function for the # Rust code. diff --git a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/macros.kt b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/macros.kt index 469ddfdd89fa..1f4e2a8385a2 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/macros.kt +++ b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/macros.kt @@ -62,7 +62,7 @@ -#} {%- macro arg_list_ffi_decl(func) %} {%- for arg in func.arguments() %} - {{- arg.name() }}: {{ arg.type_().borrow()|ffi_type_name -}}, + {{- arg.name()|var_name }}: {{ arg.type_().borrow()|ffi_type_name -}}, {%- endfor %} _uniffi_out_err: RustCallStatus {%- endmacro -%} @@ -76,7 +76,7 @@ {%- endmacro -%} {%- macro ffi_function_definition(func) %} -fun {{ func.name() }}( +fun {{ func.name()|fn_name }}( {%- call arg_list_ffi_decl(func) %} ){%- match func.return_type() -%}{%- when Some with (type_) %}: {{ type_|ffi_type_name }}{% when None %}: Unit{% endmatch %} {% endmacro %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/wrapper.kt b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/wrapper.kt index 7827c5e8119a..9cb104292cb2 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/wrapper.kt +++ b/third_party/rust/uniffi_bindgen/src/bindings/kotlin/templates/wrapper.kt @@ -40,7 +40,7 @@ import {{ imported_class }} // Public interface members begin here. {{ type_helper_code }} -{%- for func in ci.iter_function_definitions() %} +{%- for func in ci.function_definitions() %} {%- include "TopLevelFunctionTemplate.kt" %} {%- endfor %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/mod.rs b/third_party/rust/uniffi_bindgen/src/bindings/mod.rs index fc644da6d13d..5aca6413403b 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/mod.rs @@ -8,9 +8,8 @@ //! along with some helpers for executing foreign language scripts or tests. use anyhow::{bail, Result}; +use camino::Utf8Path; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; -use std::path::Path; use crate::interface::ComponentInterface; use crate::MergeWith; @@ -99,17 +98,13 @@ impl MergeWith for Config { } /// Generate foreign language bindings from a compiled `uniffi` library. -pub fn write_bindings

( +pub fn write_bindings( config: &Config, ci: &ComponentInterface, - out_dir: P, + out_dir: &Utf8Path, language: TargetLanguage, try_format_code: bool, -) -> Result<()> -where - P: AsRef, -{ - let out_dir = out_dir.as_ref(); +) -> Result<()> { match language { TargetLanguage::Kotlin => { kotlin::write_bindings(&config.kotlin, ci, out_dir, try_format_code)? @@ -129,16 +124,12 @@ where /// /// Note: This function is only used for compiling the unit tests. See #1169 for plans to refactor /// it. -pub fn compile_bindings

( +pub fn compile_bindings( config: &Config, ci: &ComponentInterface, - out_dir: P, + out_dir: &Utf8Path, language: TargetLanguage, -) -> Result<()> -where - P: AsRef, -{ - let out_dir = out_dir.as_ref(); +) -> Result<()> { match language { TargetLanguage::Kotlin => kotlin::compile_bindings(&config.kotlin, ci, out_dir)?, TargetLanguage::Swift => swift::compile_bindings(&config.swift, ci, out_dir)?, @@ -152,13 +143,11 @@ where /// /// Note: This function is only used for compiling the unit tests. See #1169 for plans to refactor /// it. -pub fn run_script(out_dir: P1, script_file: P2, language: TargetLanguage) -> Result<()> -where - P1: AsRef, - P2: AsRef, -{ - let out_dir = out_dir.as_ref(); - let script_file = script_file.as_ref(); +pub fn run_script( + out_dir: &Utf8Path, + script_file: &Utf8Path, + language: TargetLanguage, +) -> Result<()> { match language { TargetLanguage::Kotlin => kotlin::run_script(out_dir, script_file)?, TargetLanguage::Swift => swift::run_script(out_dir, script_file)?, diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/callback_interface.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/callback_interface.rs index 0ae1d4368bbc..9359fbaeae1c 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/callback_interface.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/callback_interface.rs @@ -2,12 +2,8 @@ * 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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{CallbackInterface, ComponentInterface}; -use askama::Template; -use std::borrow::Borrow; +use crate::backend::{CodeOracle, CodeType, Literal}; -use super::filters; pub struct CallbackInterfaceCodeType { id: String, } @@ -35,49 +31,3 @@ impl CodeType for CallbackInterfaceCodeType { nm.to_string() } } - -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "CallbackInterfaceTemplate.py")] -pub struct PythonCallbackInterface { - inner: CallbackInterface, -} - -impl PythonCallbackInterface { - pub fn new(inner: CallbackInterface, _ci: &ComponentInterface) -> Self { - Self { inner } - } - - pub fn inner(&self) -> &CallbackInterface { - &self.inner - } -} - -impl CodeDeclaration for PythonCallbackInterface { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } -} - -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "CallbackInterfaceRuntime.py")] -pub struct PythonCallbackInterfaceRuntime { - is_needed: bool, -} - -impl PythonCallbackInterfaceRuntime { - pub fn new(ci: &ComponentInterface) -> Self { - Self { - is_needed: !ci.iter_callback_interface_definitions().is_empty(), - } - } -} - -impl CodeDeclaration for PythonCallbackInterfaceRuntime { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - if !self.is_needed { - None - } else { - Some(self.render().unwrap()) - } - } -} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/compounds.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/compounds.rs index 58638e55a276..80b1da040de4 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/compounds.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/compounds.rs @@ -2,155 +2,120 @@ * 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/. */ -use super::filters; use crate::backend::{CodeOracle, CodeType, Literal, TypeIdentifier}; -use askama::Template; -use paste::paste; -fn render_literal(oracle: &dyn CodeOracle, literal: &Literal, inner: &TypeIdentifier) -> String { - match literal { - Literal::Null => "None".into(), - Literal::EmptySequence => "[]".into(), - Literal::EmptyMap => "{}".into(), +pub struct OptionalCodeType { + inner: TypeIdentifier, +} - // For optionals - _ => oracle.find(inner).literal(oracle, literal), +impl OptionalCodeType { + pub fn new(inner: TypeIdentifier) -> Self { + Self { inner } } } -macro_rules! impl_code_type_for_compound { - ($T:ty, $canonical_name_pattern: literal, $template_file:literal, $coerce_code:expr) => { - paste! { - #[derive(Template)] - #[template(syntax = "py", escape = "none", path = $template_file)] - pub struct $T { - inner: TypeIdentifier, - outer: TypeIdentifier, - } +impl CodeType for OptionalCodeType { + fn type_label(&self, oracle: &dyn CodeOracle) -> String { + oracle.find(&self.inner).type_label(oracle) + } - impl $T { - pub fn new(inner: TypeIdentifier, outer: TypeIdentifier) -> Self { - Self { inner, outer } - } + fn canonical_name(&self, oracle: &dyn CodeOracle) -> String { + format!( + "Optional{}", + oracle.find(&self.inner).canonical_name(oracle), + ) + } - fn inner(&self) -> &TypeIdentifier { - &self.inner - } - - fn outer(&self) -> &TypeIdentifier { - &self.outer - } - } - - impl CodeType for $T { - fn type_label(&self, oracle: &dyn CodeOracle) -> String { - oracle.find(self.inner()).type_label(oracle) - } - - fn canonical_name(&self, oracle: &dyn CodeOracle) -> String { - format!($canonical_name_pattern, oracle.find(self.inner()).canonical_name(oracle)) - } - - fn literal(&self, oracle: &dyn CodeOracle, literal: &Literal) -> String { - render_literal(oracle, &literal, self.inner()) - } - - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - - fn coerce(&self, oracle: &dyn CodeOracle, nm: &str) -> String { - $coerce_code(self, oracle, nm) - } - } + fn literal(&self, oracle: &dyn CodeOracle, literal: &Literal) -> String { + match literal { + Literal::Null => "None".into(), + _ => oracle.find(&self.inner).literal(oracle, literal), } } - } -impl_code_type_for_compound!( - OptionalCodeType, - "Optional{}", - "OptionalTemplate.py", - optional_coerce -); -fn optional_coerce(this: &OptionalCodeType, oracle: &dyn CodeOracle, nm: &str) -> String { - format!( - "(None if {} is None else {})", - nm, - oracle.find(this.inner()).coerce(oracle, nm) - ) + fn coerce(&self, oracle: &dyn CodeOracle, nm: &str) -> String { + format!( + "(None if {} is None else {})", + nm, + oracle.find(&self.inner).coerce(oracle, nm) + ) + } } -impl_code_type_for_compound!( - SequenceCodeType, - "Sequence{}", - "SequenceTemplate.py", - sequence_coerce -); -fn sequence_coerce(this: &SequenceCodeType, oracle: &dyn CodeOracle, nm: &str) -> String { - format!( - "list({} for x in {})", - oracle.find(this.inner()).coerce(oracle, "x"), - nm - ) +pub struct SequenceCodeType { + inner: TypeIdentifier, +} + +impl SequenceCodeType { + pub fn new(inner: TypeIdentifier) -> Self { + Self { inner } + } +} + +impl CodeType for SequenceCodeType { + fn type_label(&self, _oracle: &dyn CodeOracle) -> String { + "list".to_string() + } + + fn canonical_name(&self, oracle: &dyn CodeOracle) -> String { + format!( + "Sequence{}", + oracle.find(&self.inner).canonical_name(oracle), + ) + } + + fn literal(&self, _oracle: &dyn CodeOracle, literal: &Literal) -> String { + match literal { + Literal::EmptySequence => "[]".into(), + _ => unimplemented!(), + } + } + + fn coerce(&self, oracle: &dyn CodeOracle, nm: &str) -> String { + format!( + "list({} for x in {})", + oracle.find(&self.inner).coerce(oracle, "x"), + nm + ) + } } -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "MapTemplate.py")] pub struct MapCodeType { key: TypeIdentifier, value: TypeIdentifier, - outer: TypeIdentifier, } impl MapCodeType { - pub fn new(key: TypeIdentifier, value: TypeIdentifier, outer: TypeIdentifier) -> Self { - Self { key, value, outer } - } - - fn key(&self) -> &TypeIdentifier { - &self.key - } - - fn value(&self) -> &TypeIdentifier { - &self.value - } - - fn outer(&self) -> &TypeIdentifier { - &self.outer + pub fn new(key: TypeIdentifier, value: TypeIdentifier) -> Self { + Self { key, value } } } impl CodeType for MapCodeType { - fn type_label(&self, oracle: &dyn CodeOracle) -> String { - format!( - "Map<{}, {}>", - self.key().type_label(oracle), - self.value().type_label(oracle), - ) + fn type_label(&self, _oracle: &dyn CodeOracle) -> String { + "dict".to_string() } fn canonical_name(&self, oracle: &dyn CodeOracle) -> String { format!( "Map{}{}", - self.key().type_label(oracle), - self.value().type_label(oracle), + oracle.find(&self.key).canonical_name(oracle), + oracle.find(&self.value).canonical_name(oracle), ) } - fn literal(&self, oracle: &dyn CodeOracle, literal: &Literal) -> String { - render_literal(oracle, literal, self.value()) - } - - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) + fn literal(&self, _oracle: &dyn CodeOracle, literal: &Literal) -> String { + match literal { + Literal::EmptyMap => "{}".into(), + _ => unimplemented!(), + } } fn coerce(&self, oracle: &dyn CodeOracle, nm: &str) -> String { format!( "dict(({}, {}) for (k, v) in {}.items())", - self.key().coerce(oracle, "k"), - self.value().coerce(oracle, "v"), + self.key.coerce(oracle, "k"), + self.value.coerce(oracle, "v"), nm ) } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/custom.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/custom.rs index 4b4bce033176..d53a94694772 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/custom.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/custom.rs @@ -2,9 +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/. */ -use super::{filters, CustomTypeConfig}; -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, TypeIdentifier}; -use askama::Template; +use crate::backend::{CodeOracle, CodeType}; pub struct CustomCodeType { name: String, @@ -28,42 +26,4 @@ impl CodeType for CustomCodeType { fn coerce(&self, _oracle: &dyn CodeOracle, nm: &str) -> String { nm.to_string() } - - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(format!( - "# Helper code for {} is found in CustomType.py", - self.name, - )) - } -} - -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "CustomType.py")] -pub struct PythonCustomType { - name: String, - builtin: TypeIdentifier, - config: Option, -} - -impl PythonCustomType { - pub fn new(name: String, builtin: TypeIdentifier, config: Option) -> Self { - Self { - name, - builtin, - config, - } - } -} - -impl CodeDeclaration for PythonCustomType { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - - fn imports(&self, _oracle: &dyn CodeOracle) -> Option> { - match &self.config { - None => None, - Some(custom_type_config) => custom_type_config.imports.clone(), - } - } } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/enum_.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/enum_.rs index 55d21b8abc29..9a8607677017 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/enum_.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/enum_.rs @@ -2,11 +2,8 @@ * 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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{ComponentInterface, Enum}; -use askama::Template; +use crate::backend::{CodeOracle, CodeType, Literal}; -use super::filters; pub struct EnumCodeType { id: String, } @@ -38,36 +35,7 @@ impl CodeType for EnumCodeType { } } - fn helper_code(&self, oracle: &dyn CodeOracle) -> Option { - Some(format!( - "# Helper code for {} enum is found in EnumTemplate.py", - self.type_label(oracle) - )) - } - fn coerce(&self, _oracle: &dyn CodeOracle, nm: &str) -> String { nm.to_string() } } - -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "EnumTemplate.py")] -pub struct PythonEnum { - inner: Enum, -} - -impl PythonEnum { - pub fn new(inner: Enum, _ci: &ComponentInterface) -> Self { - Self { inner } - } - - pub fn inner(&self) -> &Enum { - &self.inner - } -} - -impl CodeDeclaration for PythonEnum { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } -} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/error.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/error.rs index 7e1b3f4c4e89..f1567281f23f 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/error.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/error.rs @@ -2,12 +2,8 @@ * 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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{ComponentInterface, Error, Type}; -use askama::Template; -use std::borrow::Borrow; +use crate::backend::{CodeOracle, CodeType, Literal}; -use super::filters; pub struct ErrorCodeType { id: String, } @@ -31,36 +27,7 @@ impl CodeType for ErrorCodeType { unreachable!(); } - fn helper_code(&self, oracle: &dyn CodeOracle) -> Option { - Some(format!( - "# Helper code for {} error is found in ErrorTemplate.py", - self.type_label(oracle) - )) - } - fn coerce(&self, _oracle: &dyn CodeOracle, nm: &str) -> String { nm.to_string() } } - -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "ErrorTemplate.py")] -pub struct PythonError { - inner: Error, -} - -impl PythonError { - pub fn new(inner: Error, _ci: &ComponentInterface) -> Self { - Self { inner } - } - - pub fn inner(&self) -> &Error { - &self.inner - } -} - -impl CodeDeclaration for PythonError { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } -} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/external.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/external.rs index 877be5c9fb2c..50cafabbbc43 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/external.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/external.rs @@ -2,20 +2,15 @@ * 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/. */ -use super::filters; use crate::backend::{CodeOracle, CodeType}; -use askama::Template; -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "ExternalTemplate.py")] pub struct ExternalCodeType { name: String, - crate_name: String, } impl ExternalCodeType { - pub fn new(name: String, crate_name: String) -> Self { - Self { name, crate_name } + pub fn new(name: String) -> Self { + Self { name } } } @@ -28,10 +23,6 @@ impl CodeType for ExternalCodeType { format!("Type{}", self.name) } - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - fn coerce(&self, _oracle: &dyn CodeOracle, _nm: &str) -> String { panic!("should not be necessary to coerce External types"); } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/function.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/function.rs deleted file mode 100644 index 208f33f34be3..000000000000 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/function.rs +++ /dev/null @@ -1,31 +0,0 @@ -/* 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/. */ - -use crate::backend::{CodeDeclaration, CodeOracle}; -use crate::interface::{ComponentInterface, Function}; -use askama::Template; -use std::borrow::Borrow; - -use super::filters; - -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "TopLevelFunctionTemplate.py")] -pub struct PythonFunction { - inner: Function, -} - -impl PythonFunction { - pub fn new(inner: Function, _ci: &ComponentInterface) -> Self { - Self { inner } - } - pub fn inner(&self) -> &Function { - &self.inner - } -} - -impl CodeDeclaration for PythonFunction { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } -} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/miscellany.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/miscellany.rs index f71fcc1789a9..c885428bc3d7 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/miscellany.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/miscellany.rs @@ -2,17 +2,12 @@ * 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/. */ -#[allow(unused_imports)] -use super::filters; use crate::backend::{CodeOracle, CodeType, Literal}; -use askama::Template; use paste::paste; macro_rules! impl_code_type_for_miscellany { - ($T:ty, $canonical_name:literal, $template_file:literal) => { + ($T:ty, $canonical_name:literal) => { paste! { - #[derive(Template)] - #[template(syntax = "py", escape = "none", path = $template_file)] pub struct $T; impl CodeType for $T { @@ -28,10 +23,6 @@ macro_rules! impl_code_type_for_miscellany { unreachable!() } - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - fn coerce(&self, _oracle: &dyn CodeOracle, nm: &str) -> String { nm.to_string() } @@ -40,6 +31,6 @@ macro_rules! impl_code_type_for_miscellany { }; } -impl_code_type_for_miscellany!(TimestampCodeType, "Timestamp", "TimestampHelper.py"); +impl_code_type_for_miscellany!(TimestampCodeType, "Timestamp"); -impl_code_type_for_miscellany!(DurationCodeType, "Duration", "DurationHelper.py"); +impl_code_type_for_miscellany!(DurationCodeType, "Duration"); diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/mod.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/mod.rs index 8b7709b85d7d..e711e5b58b91 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/mod.rs @@ -2,14 +2,15 @@ * 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/. */ -use anyhow::Result; +use anyhow::{Context, Result}; use askama::Template; use heck::{ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase}; use serde::{Deserialize, Serialize}; use std::borrow::Borrow; -use std::collections::{HashMap, HashSet}; +use std::cell::RefCell; +use std::collections::{BTreeSet, HashMap, HashSet}; -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, TemplateExpression, TypeIdentifier}; +use crate::backend::{CodeOracle, CodeType, TemplateExpression, TypeIdentifier}; use crate::interface::*; use crate::MergeWith; @@ -19,12 +20,56 @@ mod custom; mod enum_; mod error; mod external; -mod function; mod miscellany; mod object; mod primitives; mod record; +lazy_static::lazy_static! { + // Taken from Python's `keyword.py` module. + static ref KEYWORDS: HashSet = { + let kwlist = vec![ + "False", + "None", + "True", + "__peg_parser__", + "and", + "as", + "assert", + "async", + "await", + "break", + "class", + "continue", + "def", + "del", + "elif", + "else", + "except", + "finally", + "for", + "from", + "global", + "if", + "import", + "in", + "is", + "lambda", + "nonlocal", + "not", + "or", + "pass", + "raise", + "return", + "try", + "while", + "with", + "yield", + ]; + HashSet::from_iter(kwlist.into_iter().map(|s| s.to_string())) + }; +} + // Config options to customize the generated python. #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct Config { @@ -72,9 +117,58 @@ impl MergeWith for Config { // Generate python bindings for the given ComponentInterface, as a string. pub fn generate_python_bindings(config: &Config, ci: &ComponentInterface) -> Result { - PythonWrapper::new(PythonCodeOracle, config.clone(), ci) + PythonWrapper::new(config.clone(), ci) .render() - .map_err(|_| anyhow::anyhow!("failed to render python bindings")) + .context("failed to render python bindings") +} + +/// Renders Python helper code for all types +/// +/// This template is a bit different than others in that it stores internal state from the render +/// process. Make sure to only call `render()` once. +#[derive(Template)] +#[template(syntax = "py", escape = "none", path = "Types.py")] +pub struct TypeRenderer<'a> { + python_config: &'a Config, + ci: &'a ComponentInterface, + // Track included modules for the `include_once()` macro + include_once_names: RefCell>, + // Track imports added with the `add_import()` macro + imports: RefCell>, +} + +impl<'a> TypeRenderer<'a> { + fn new(python_config: &'a Config, ci: &'a ComponentInterface) -> Self { + Self { + python_config, + ci, + include_once_names: RefCell::new(HashSet::new()), + imports: RefCell::new(BTreeSet::new()), + } + } + + // The following methods are used by the `Types.py` macros. + + // Helper for the including a template, but only once. + // + // The first time this is called with a name it will return true, indicating that we should + // include the template. Subsequent calls will return false. + fn include_once_check(&self, name: &str) -> bool { + self.include_once_names + .borrow_mut() + .insert(name.to_string()) + } + + // Helper to add an import statement + // + // Call this inside your template to cause an import statement to be added at the top of the + // file. Imports will be sorted and de-deuped. + // + // Returns an empty string so that it can be used inside an askama `{{ }}` block. + fn add_import(&self, name: &str) -> &str { + self.imports.borrow_mut().insert(name.to_owned()); + "" + } } #[derive(Template)] @@ -82,96 +176,32 @@ pub fn generate_python_bindings(config: &Config, ci: &ComponentInterface) -> Res pub struct PythonWrapper<'a> { ci: &'a ComponentInterface, config: Config, - oracle: PythonCodeOracle, + type_helper_code: String, + type_imports: BTreeSet, } impl<'a> PythonWrapper<'a> { - pub fn new(oracle: PythonCodeOracle, config: Config, ci: &'a ComponentInterface) -> Self { - Self { oracle, config, ci } - } - - pub fn members(&self) -> Vec> { - let ci = self.ci; - vec![ - Box::new(callback_interface::PythonCallbackInterfaceRuntime::new(ci)) - as Box, - ] - .into_iter() - .chain( - ci.iter_enum_definitions().into_iter().map(|inner| { - Box::new(enum_::PythonEnum::new(inner, ci)) as Box - }), - ) - .chain(ci.iter_function_definitions().into_iter().map(|inner| { - Box::new(function::PythonFunction::new(inner, ci)) as Box - })) - .chain(ci.iter_object_definitions().into_iter().map(|inner| { - Box::new(object::PythonObject::new(inner, ci)) as Box - })) - .chain(ci.iter_record_definitions().into_iter().map(|inner| { - Box::new(record::PythonRecord::new(inner, ci)) as Box - })) - .chain( - ci.iter_error_definitions().into_iter().map(|inner| { - Box::new(error::PythonError::new(inner, ci)) as Box - }), - ) - .chain( - ci.iter_callback_interface_definitions() - .into_iter() - .map(|inner| { - Box::new(callback_interface::PythonCallbackInterface::new(inner, ci)) - as Box - }), - ) - .chain(ci.iter_custom_types().into_iter().map(|(name, type_)| { - let config = self.config.custom_types.get(&name).cloned(); - Box::new(custom::PythonCustomType::new(name, type_, config)) as Box - })) - .collect() - } - - pub fn initialization_code(&self) -> Vec { - let oracle = &self.oracle; - self.members() - .into_iter() - .filter_map(|member| member.initialization_code(oracle)) - .collect() - } - - pub fn declaration_code(&self) -> Vec { - let oracle = &self.oracle; - self.members() - .into_iter() - .filter_map(|member| member.definition_code(oracle)) - .chain( - self.ci - .iter_types() - .into_iter() - .filter_map(|type_| oracle.find(&type_).helper_code(oracle)), - ) - .collect() + pub fn new(config: Config, ci: &'a ComponentInterface) -> Self { + let type_renderer = TypeRenderer::new(&config, ci); + let type_helper_code = type_renderer.render().unwrap(); + let type_imports = type_renderer.imports.into_inner(); + Self { + config, + ci, + type_helper_code, + type_imports, + } } pub fn imports(&self) -> Vec { - let oracle = &self.oracle; - let mut imports: Vec = self - .members() - .into_iter() - .filter_map(|member| member.imports(oracle)) - .flatten() - .chain( - self.ci - .iter_types() - .into_iter() - .filter_map(|type_| oracle.find(&type_).imports(oracle)) - .flatten(), - ) - .collect::>() - .into_iter() - .collect(); + self.type_imports.iter().cloned().collect() + } +} - imports.sort(); - imports +fn fixup_keyword(name: String) -> String { + if KEYWORDS.contains(&name) { + format!("_{}", name) + } else { + name } } @@ -179,11 +209,14 @@ impl<'a> PythonWrapper<'a> { pub struct PythonCodeOracle; impl PythonCodeOracle { + // Map `Type` instances to a `Box` for that type. + // + // There is a companion match in `templates/Types.py` which performs a similar function for the + // template code. + // + // - When adding additional types here, make sure to also add a match arm to the `Types.py` template. + // - To keep things managable, let's try to limit ourselves to these 2 mega-matches fn create_code_type(&self, type_: TypeIdentifier) -> Box { - // I really want access to the ComponentInterface here so I can look up the interface::{Enum, Record, Error, Object, etc} - // However, there's some violence and gore I need to do to (temporarily) make the oracle usable from filters. - - // Some refactor of the templates is needed to make progress here: I think most of the filter functions need to take an &dyn CodeOracle match type_ { Type::UInt8 => Box::new(primitives::UInt8CodeType), Type::Int8 => Box::new(primitives::Int8CodeType), @@ -209,25 +242,10 @@ impl PythonCodeOracle { Box::new(callback_interface::CallbackInterfaceCodeType::new(id)) } - Type::Optional(ref inner) => { - let outer = type_.clone(); - let inner = *inner.to_owned(); - Box::new(compounds::OptionalCodeType::new(inner, outer)) - } - Type::Sequence(ref inner) => { - let outer = type_.clone(); - let inner = *inner.to_owned(); - Box::new(compounds::SequenceCodeType::new(inner, outer)) - } - Type::Map(ref key, ref value) => { - let outer = type_.clone(); - let key = *key.to_owned(); - let value = *value.to_owned(); - Box::new(compounds::MapCodeType::new(key, value, outer)) - } - Type::External { name, crate_name } => { - Box::new(external::ExternalCodeType::new(name, crate_name)) - } + Type::Optional(inner) => Box::new(compounds::OptionalCodeType::new(*inner)), + Type::Sequence(inner) => Box::new(compounds::SequenceCodeType::new(*inner)), + Type::Map(key, value) => Box::new(compounds::MapCodeType::new(*key, *value)), + Type::External { name, .. } => Box::new(external::ExternalCodeType::new(name)), Type::Custom { name, .. } => Box::new(custom::CustomCodeType::new(name)), } } @@ -240,38 +258,31 @@ impl CodeOracle for PythonCodeOracle { /// Get the idiomatic Python rendering of a class name (for enums, records, errors, etc). fn class_name(&self, nm: &str) -> String { - nm.to_string().to_upper_camel_case() + fixup_keyword(nm.to_string().to_upper_camel_case()) } /// Get the idiomatic Python rendering of a function name. fn fn_name(&self, nm: &str) -> String { - nm.to_string().to_snake_case() + fixup_keyword(nm.to_string().to_snake_case()) } /// Get the idiomatic Python rendering of a variable name. fn var_name(&self, nm: &str) -> String { - nm.to_string().to_snake_case() + fixup_keyword(nm.to_string().to_snake_case()) } /// Get the idiomatic Python rendering of an individual enum variant. fn enum_variant_name(&self, nm: &str) -> String { - nm.to_string().to_shouty_snake_case() + fixup_keyword(nm.to_string().to_shouty_snake_case()) } /// Get the idiomatic Python rendering of an exception name - /// - /// This replaces "Error" at the end of the name with "Exception". Rust code typically uses - /// "Error" for any type of error but in the Java world, "Error" means a non-recoverable error - /// and is distinguished from an "Exception". + /// This replaces "Error" at the end of the name with "Exception". fn error_name(&self, nm: &str) -> String { - let name = nm.to_string(); + let name = fixup_keyword(self.class_name(nm)); match name.strip_suffix("Error") { None => name, - Some(stripped) => { - let mut py_exc_name = stripped.to_owned(); - py_exc_name.push_str("Exception"); - py_exc_name - } + Some(stripped) => format!("{}Exception", stripped), } } @@ -287,7 +298,7 @@ impl CodeOracle for PythonCodeOracle { FFIType::UInt64 => "ctypes.c_uint64".to_string(), FFIType::Float32 => "ctypes.c_float".to_string(), FFIType::Float64 => "ctypes.c_double".to_string(), - FFIType::RustArcPtr => "ctypes.c_void_p".to_string(), + FFIType::RustArcPtr(_) => "ctypes.c_void_p".to_string(), FFIType::RustBuffer => "RustBuffer".to_string(), FFIType::ForeignBytes => "ForeignBytes".to_string(), FFIType::ForeignCallback => "FOREIGN_CALLBACK_T".to_string(), @@ -367,10 +378,6 @@ pub mod filters { } /// Get the idiomatic Python rendering of an exception name - /// - /// This replaces "Error" at the end of the name with "Exception". Rust code typically uses - /// "Error" for any type of error but in the Java world, "Error" means a non-recoverable error - /// and is distinguished from an "Exception". pub fn exception_name(nm: &str) -> Result { Ok(oracle().error_name(nm)) } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/object.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/object.rs index de5d19fd2606..7744865ec014 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/object.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/object.rs @@ -2,13 +2,8 @@ * 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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{ComponentInterface, Object}; -use askama::Template; -use std::borrow::Borrow; +use crate::backend::{CodeOracle, CodeType, Literal}; -// Filters is used by ObjectTemplate.py, which looks for the filters module here. -use super::filters; pub struct ObjectCodeType { id: String, } @@ -32,35 +27,7 @@ impl CodeType for ObjectCodeType { unreachable!(); } - fn helper_code(&self, oracle: &dyn CodeOracle) -> Option { - Some(format!( - "# Helper code for {} class is found in ObjectTemplate.py", - self.type_label(oracle) - )) - } - fn coerce(&self, _oracle: &dyn CodeOracle, nm: &str) -> String { nm.to_string() } } - -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "ObjectTemplate.py")] -pub struct PythonObject { - inner: Object, -} - -impl PythonObject { - pub fn new(inner: Object, _ci: &ComponentInterface) -> Self { - Self { inner } - } - pub fn inner(&self) -> &Object { - &self.inner - } -} - -impl CodeDeclaration for PythonObject { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } -} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/primitives.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/primitives.rs index c6efc0f69bee..948047fdd030 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/primitives.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/primitives.rs @@ -2,11 +2,8 @@ * 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/. */ -#[allow(unused_imports)] -use super::filters; use crate::backend::{CodeOracle, CodeType, Literal}; use crate::interface::Radix; -use askama::Template; use paste::paste; fn render_literal(_oracle: &dyn CodeOracle, literal: &Literal) -> String { @@ -37,10 +34,8 @@ fn render_literal(_oracle: &dyn CodeOracle, literal: &Literal) -> String { } macro_rules! impl_code_type_for_primitive { - ($T:ty, $class_name:literal, $template_file:literal, $coerce_code:expr) => { + ($T:ty, $class_name:literal, $coerce_code:expr) => { paste! { - #[derive(Template)] - #[template(syntax = "py", escape = "none", path = $template_file)] pub struct $T; impl CodeType for $T { @@ -52,10 +47,6 @@ macro_rules! impl_code_type_for_primitive { render_literal(oracle, &literal) } - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - fn coerce(&self, _oracle: &dyn CodeOracle, nm: &str) -> String { format!($coerce_code, nm) } @@ -64,15 +55,15 @@ macro_rules! impl_code_type_for_primitive { }; } -impl_code_type_for_primitive!(BooleanCodeType, "Bool", "BooleanHelper.py", "bool({})"); -impl_code_type_for_primitive!(StringCodeType, "String", "StringHelper.py", "{}"); -impl_code_type_for_primitive!(Int8CodeType, "Int8", "Int8Helper.py", "int({})"); -impl_code_type_for_primitive!(Int16CodeType, "Int16", "Int16Helper.py", "int({})"); -impl_code_type_for_primitive!(Int32CodeType, "Int32", "Int32Helper.py", "int({})"); -impl_code_type_for_primitive!(Int64CodeType, "Int64", "Int64Helper.py", "int({})"); -impl_code_type_for_primitive!(UInt8CodeType, "UInt8", "UInt8Helper.py", "int({})"); -impl_code_type_for_primitive!(UInt16CodeType, "UInt16", "UInt16Helper.py", "int({})"); -impl_code_type_for_primitive!(UInt32CodeType, "UInt32", "UInt32Helper.py", "int({})"); -impl_code_type_for_primitive!(UInt64CodeType, "UInt64", "UInt64Helper.py", "int({})"); -impl_code_type_for_primitive!(Float32CodeType, "Float", "Float32Helper.py", "float({})"); -impl_code_type_for_primitive!(Float64CodeType, "Double", "Float64Helper.py", "float({})"); +impl_code_type_for_primitive!(BooleanCodeType, "Bool", "bool({})"); +impl_code_type_for_primitive!(StringCodeType, "String", "{}"); +impl_code_type_for_primitive!(Int8CodeType, "Int8", "int({})"); +impl_code_type_for_primitive!(Int16CodeType, "Int16", "int({})"); +impl_code_type_for_primitive!(Int32CodeType, "Int32", "int({})"); +impl_code_type_for_primitive!(Int64CodeType, "Int64", "int({})"); +impl_code_type_for_primitive!(UInt8CodeType, "UInt8", "int({})"); +impl_code_type_for_primitive!(UInt16CodeType, "UInt16", "int({})"); +impl_code_type_for_primitive!(UInt32CodeType, "UInt32", "int({})"); +impl_code_type_for_primitive!(UInt64CodeType, "UInt64", "int({})"); +impl_code_type_for_primitive!(Float32CodeType, "Float", "float({})"); +impl_code_type_for_primitive!(Float64CodeType, "Double", "float({})"); diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/record.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/record.rs index c998d3a8a4c0..1dba8e49feec 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/record.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/gen_python/record.rs @@ -2,11 +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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{ComponentInterface, Record}; -use askama::Template; - -use super::filters; +use crate::backend::{CodeOracle, CodeType, Literal}; pub struct RecordCodeType { id: String, @@ -31,36 +27,7 @@ impl CodeType for RecordCodeType { unreachable!(); } - fn helper_code(&self, oracle: &dyn CodeOracle) -> Option { - Some(format!( - "# Helper code for {} record is found in RecordTemplate.py", - self.type_label(oracle) - )) - } - fn coerce(&self, _oracle: &dyn CodeOracle, nm: &str) -> String { nm.to_string() } } - -#[derive(Template)] -#[template(syntax = "py", escape = "none", path = "RecordTemplate.py")] -pub struct PythonRecord { - inner: Record, -} - -impl PythonRecord { - pub fn new(inner: Record, _ci: &ComponentInterface) -> Self { - Self { inner } - } - - pub fn inner(&self) -> &Record { - &self.inner - } -} - -impl CodeDeclaration for PythonRecord { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } -} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/mod.rs b/third_party/rust/uniffi_bindgen/src/bindings/python/mod.rs index 5401640c1ed6..73245db86b2b 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/mod.rs @@ -2,18 +2,13 @@ * 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/. */ -use std::{ - env, - ffi::OsString, - fs::File, - io::Write, - path::{Path, PathBuf}, - process::Command, -}; +use std::{env, io::Write, process::Command}; use anyhow::{bail, Context, Result}; +use fs_err::File; pub mod gen_python; +use camino::Utf8Path; pub use gen_python::{generate_python_bindings, Config}; use super::super::interface::ComponentInterface; @@ -22,19 +17,18 @@ use super::super::interface::ComponentInterface; pub fn write_bindings( config: &Config, ci: &ComponentInterface, - out_dir: &Path, + out_dir: &Utf8Path, try_format_code: bool, ) -> Result<()> { - let mut py_file = PathBuf::from(out_dir); - py_file.push(format!("{}.py", ci.namespace())); - let mut f = File::create(&py_file).context("Failed to create .py file for bindings")?; + let py_file = out_dir.join(format!("{}.py", ci.namespace())); + let mut f = File::create(&py_file)?; write!(f, "{}", generate_python_bindings(config, ci)?)?; if try_format_code { - if let Err(e) = Command::new("yapf").arg(py_file.to_str().unwrap()).output() { + if let Err(e) = Command::new("yapf").arg(&py_file).output() { println!( "Warning: Unable to auto-format {} using yapf: {:?}", - py_file.file_name().unwrap().to_str().unwrap(), + py_file.file_name().unwrap(), e ) } @@ -45,12 +39,13 @@ pub fn write_bindings( /// Execute the specifed python script, with environment based on the generated /// artifacts in the given output directory. -pub fn run_script(out_dir: &Path, script_file: &Path) -> Result<()> { +pub fn run_script(out_dir: &Utf8Path, script_file: &Utf8Path) -> Result<()> { let mut cmd = Command::new("python3"); // This helps python find the generated .py wrapper for rust component. - let pythonpath = env::var_os("PYTHONPATH").unwrap_or_else(|| OsString::from("")); - let pythonpath = - env::join_paths(env::split_paths(&pythonpath).chain(vec![out_dir.to_path_buf()]))?; + let pythonpath = env::var_os("PYTHONPATH").unwrap_or_default(); + let pythonpath = env::join_paths( + env::split_paths(&pythonpath).chain(vec![out_dir.as_std_path().to_owned()]), + )?; cmd.env("PYTHONPATH", pythonpath); // We should now be able to execute the tests successfully. cmd.arg(script_file); diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/CallbackInterfaceTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/CallbackInterfaceTemplate.py index 548f7f7cb9e4..537d16bf2a80 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/CallbackInterfaceTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/CallbackInterfaceTemplate.py @@ -1,12 +1,11 @@ -{% import "macros.py" as py %} -{%- let cbi = self.inner() %} -{%- let canonical_name = cbi|canonical_name %} -{%- let ffi_converter = cbi|ffi_converter_name %} -{%- let foreign_callback = format!("foreignCallback{}", canonical_name) %} +{%- let cbi = ci.get_callback_interface_definition(id).unwrap() %} +{%- let foreign_callback = format!("foreignCallback{}", canonical_type_name) %} -# Declaration and FfiConverters for {{ cbi|type_name }} Callback Interface +{% if self.include_once_check("CallbackInterfaceRuntime.py") %}{% include "CallbackInterfaceRuntime.py" %}{% endif %} -class {{ cbi|type_name }}: +# Declaration and FfiConverters for {{ type_name }} Callback Interface + +class {{ type_name }}: {% for meth in cbi.methods() -%} def {{ meth.name()|fn_name }}({% call py::arg_list_decl(meth) %}): raise NotImplementedError @@ -45,12 +44,12 @@ def py_{{ foreign_callback }}(handle, method, args, buf_ptr): # https://github.com/mozilla/uniffi-rs/issues/351 {% endfor %} - cb = {{ ffi_converter }}.lift(handle) + cb = {{ ffi_converter_name }}.lift(handle) if not cb: raise InternalError("No callback in handlemap; this is a Uniffi bug") if method == IDX_CALLBACK_FREE: - {{ ffi_converter }}.drop(handle) + {{ ffi_converter_name }}.drop(handle) # No return value. # See docs of ForeignCallback in `uniffi/src/ffi/foreigncallbacks.rs` return 0 @@ -80,4 +79,4 @@ def py_{{ foreign_callback }}(handle, method, args, buf_ptr): # The FfiConverter which transforms the Callbacks in to Handles to pass to Rust. rust_call(lambda err: _UniFFILib.{{ cbi.ffi_init_callback().name() }}({{ foreign_callback }}, err)) -{{ ffi_converter }} = FfiConverterCallbackInterface({{ foreign_callback }}) +{{ ffi_converter_name }} = FfiConverterCallbackInterface({{ foreign_callback }}) diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/CustomType.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/CustomType.py index 92fa18e2f64d..9ce6a21ced55 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/CustomType.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/CustomType.py @@ -1,5 +1,5 @@ -{%- match config %} -{%- when None %} +{%- match python_config.custom_types.get(name.as_str()) %} +{% when None %} {#- No custom type config, just forward all methods to our builtin type #} class FfiConverterType{{ name }}: @staticmethod @@ -18,7 +18,16 @@ class FfiConverterType{{ name }}: def lower(value): return {{ builtin|ffi_converter_name }}.lower(value) -{%- when Some with (config) %} +{%- when Some(config) %} + +{%- match config.imports %} +{%- when Some(imports) %} +{%- for import_name in imports %} +{{ self.add_import(import_name) }} +{%- endfor %} +{%- else %} +{%- endmatch %} + {#- Custom type config supplied, use it to convert the builtin type #} class FfiConverterType{{ name }}: @staticmethod diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/EnumTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/EnumTemplate.py index 25ab5e654764..5c366d8855f3 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/EnumTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/EnumTemplate.py @@ -4,18 +4,18 @@ # when none of the variants have associated data, or a generic nested-class # construct when they do. #} -{%- let e = self.inner() %} +{%- let e = ci.get_enum_definition(name).unwrap() %} {% if e.is_flat() %} -class {{ e|type_name }}(enum.Enum): +class {{ type_name }}(enum.Enum): {% for variant in e.variants() -%} {{ variant.name()|enum_variant_py }} = {{ loop.index }} {% endfor %} {% else %} -class {{ e|type_name }}: +class {{ type_name }}: def __init__(self): - raise RuntimeError("{{ e|type_name }} cannot be instantiated directly") + raise RuntimeError("{{ type_name }} cannot be instantiated directly") # Each enum variant is a nested class of the enum itself. {% for variant in e.variants() -%} @@ -30,7 +30,7 @@ class {{ e|type_name }}: {% endif %} def __str__(self): - return "{{ e|type_name }}.{{ variant.name()|enum_variant_py }}({% for field in variant.fields() %}{{ field.name() }}={}{% if loop.last %}{% else %}, {% endif %}{% endfor %})".format({% for field in variant.fields() %}self.{{ field.name() }}{% if loop.last %}{% else %}, {% endif %}{% endfor %}) + return "{{ type_name }}.{{ variant.name()|enum_variant_py }}({% for field in variant.fields() %}{{ field.name()|var_name }}={}{% if loop.last %}{% else %}, {% endif %}{% endfor %})".format({% for field in variant.fields() %}self.{{ field.name()|var_name }}{% if loop.last %}{% else %}, {% endif %}{% endfor %}) def __eq__(self, other): if not other.is_{{ variant.name()|var_name }}(): @@ -46,19 +46,19 @@ class {{ e|type_name }}: # whether an instance is that variant. {% for variant in e.variants() -%} def is_{{ variant.name()|var_name }}(self): - return isinstance(self, {{ e|type_name }}.{{ variant.name()|enum_variant_py }}) + return isinstance(self, {{ type_name }}.{{ variant.name()|enum_variant_py }}) {% endfor %} # Now, a little trick - we make each nested variant class be a subclass of the main # enum class, so that method calls and instance checks etc will work intuitively. # We might be able to do this a little more neatly with a metaclass, but this'll do. {% for variant in e.variants() -%} -{{ e|type_name }}.{{ variant.name()|enum_variant_py }} = type("{{ e|type_name }}.{{ variant.name()|enum_variant_py }}", ({{ e|type_name }}.{{variant.name()|enum_variant_py}}, {{ e|type_name }},), {}) +{{ type_name }}.{{ variant.name()|enum_variant_py }} = type("{{ type_name }}.{{ variant.name()|enum_variant_py }}", ({{ type_name }}.{{variant.name()|enum_variant_py}}, {{ type_name }},), {}) {% endfor %} {% endif %} -class {{ e|ffi_converter_name }}(FfiConverterRustBuffer): +class {{ ffi_converter_name }}(FfiConverterRustBuffer): @staticmethod def read(buf): variant = buf.readI32() @@ -66,9 +66,9 @@ class {{ e|ffi_converter_name }}(FfiConverterRustBuffer): {%- for variant in e.variants() %} if variant == {{ loop.index }}: {%- if e.is_flat() %} - return {{ e|type_name }}.{{variant.name()|enum_variant_py}} + return {{ type_name }}.{{variant.name()|enum_variant_py}} {%- else %} - return {{ e|type_name }}.{{variant.name()|enum_variant_py}}( + return {{ type_name }}.{{variant.name()|enum_variant_py}}( {%- for field in variant.fields() %} {{ field|read_fn }}(buf), {%- endfor %} @@ -80,7 +80,7 @@ class {{ e|ffi_converter_name }}(FfiConverterRustBuffer): def write(value, buf): {%- for variant in e.variants() %} {%- if e.is_flat() %} - if value == {{ e|type_name }}.{{ variant.name()|enum_variant_py }}: + if value == {{ type_name }}.{{ variant.name()|enum_variant_py }}: buf.writeI32({{ loop.index }}) {%- else %} if value.is_{{ variant.name()|var_name }}(): diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ErrorTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ErrorTemplate.py index 10b67b9b8f58..fe6530eb6a57 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ErrorTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ErrorTemplate.py @@ -1,5 +1,5 @@ -{%- let e = self.inner() %} -class {{ e|type_name }}(Exception): +{%- let e = ci.get_error_definition(name).unwrap() %} +class {{ type_name }}(Exception): {%- if e.is_flat() %} # Each variant is a nested class of the error itself. @@ -27,24 +27,24 @@ class {{ e|type_name }}(Exception): {%- if variant.has_fields() %} field_parts = [ {%- for field in variant.fields() %} - '{{ field.name() }}={!r}'.format(self.{{ field.name() }}), + '{{ field.name()|var_name }}={!r}'.format(self.{{ field.name()|var_name }}), {%- endfor %} ] - return "{{ e|type_name }}.{{ variant.name()|class_name }}({})".format(', '.join(field_parts)) + return "{{ type_name }}.{{ variant.name()|class_name }}({})".format(', '.join(field_parts)) {%- else %} - return "{{ e|type_name }}.{{ variant.name()|class_name }}" + return "{{ type_name }}.{{ variant.name()|class_name }}" {%- endif %} {%- endfor %} {%- endif %} -class {{ e|ffi_converter_name }}(FfiConverterRustBuffer): +class {{ ffi_converter_name }}(FfiConverterRustBuffer): @staticmethod def read(buf): variant = buf.readI32() {%- for variant in e.variants() %} if variant == {{ loop.index }}: - return {{ e|type_name }}.{{ variant.name()|class_name }}( + return {{ type_name }}.{{ variant.name()|class_name }}( {%- if e.is_flat() %} {{ Type::String.borrow()|read_fn }}(buf), {%- else %} @@ -59,7 +59,7 @@ class {{ e|ffi_converter_name }}(FfiConverterRustBuffer): @staticmethod def write(value, buf): {%- for variant in e.variants() %} - if isinstance(value, {{ e|type_name }}.{{ variant.name()|class_name }}): + if isinstance(value, {{ type_name }}.{{ variant.name()|class_name }}): buf.writeI32({{ loop.index }}) {%- for field in variant.fields() %} {{ field|write_fn }}(value.{{ field.name()|var_name }}, buf) diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ExternalTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ExternalTemplate.py index 47544e84c6b7..b3acc5b2d1ab 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ExternalTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ExternalTemplate.py @@ -1 +1 @@ -from {{ self.crate_name|fn_name }} import FfiConverterType{{ name }} +from {{ crate_name|fn_name }} import FfiConverterType{{ name }} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/MapTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/MapTemplate.py index 63d19ce06566..7f42daa7a9cd 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/MapTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/MapTemplate.py @@ -1,10 +1,7 @@ -{%- let outer_type = self.outer() %} -{%- let key_type = self.key() %} -{%- let value_type = self.value() %} {%- let key_ffi_converter = key_type|ffi_converter_name %} {%- let value_ffi_converter = value_type|ffi_converter_name %} -class {{ outer_type|ffi_converter_name }}(FfiConverterRustBuffer): +class {{ ffi_converter_name }}(FfiConverterRustBuffer): @classmethod def write(cls, items, buf): buf.writeI32(len(items)) diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ObjectTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ObjectTemplate.py index 0ed0fb1fe888..cc4cc35b4e1f 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ObjectTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/ObjectTemplate.py @@ -1,11 +1,10 @@ -{% import "macros.py" as py %} -{%- let obj = self.inner() %} +{%- let obj = ci.get_object_definition(name).unwrap() %} -class {{ obj|type_name }}(object): +class {{ type_name }}(object): {%- match obj.primary_constructor() %} {%- when Some with (cons) %} def __init__(self, {% call py::arg_list_decl(cons) -%}): - {%- call py::coerce_args_extra_indent(cons) %} + {%- call py::setup_args_extra_indent(cons) %} self._pointer = {% call py::to_ffi_call(cons) %} {%- when None %} {%- endmatch %} @@ -28,7 +27,7 @@ class {{ obj|type_name }}(object): {% for cons in obj.alternate_constructors() -%} @classmethod def {{ cons.name()|fn_name }}(cls, {% call py::arg_list_decl(cons) %}): - {%- call py::coerce_args_extra_indent(cons) %} + {%- call py::setup_args_extra_indent(cons) %} # Call the (fallible) function before creating any half-baked object instances. pointer = {% call py::to_ffi_call(cons) %} return cls._make_instance_(pointer) @@ -39,20 +38,20 @@ class {{ obj|type_name }}(object): {%- when Some with (return_type) -%} def {{ meth.name()|fn_name }}(self, {% call py::arg_list_decl(meth) %}): - {%- call py::coerce_args_extra_indent(meth) %} + {%- call py::setup_args_extra_indent(meth) %} return {{ return_type|lift_fn }}( {% call py::to_ffi_call_with_prefix("self._pointer", meth) %} ) {%- when None -%} def {{ meth.name()|fn_name }}(self, {% call py::arg_list_decl(meth) %}): - {%- call py::coerce_args_extra_indent(meth) %} + {%- call py::setup_args_extra_indent(meth) %} {% call py::to_ffi_call_with_prefix("self._pointer", meth) %} {% endmatch %} {% endfor %} -class {{ obj|ffi_converter_name }}: +class {{ ffi_converter_name }}: @classmethod def read(cls, buf): ptr = buf.readU64() @@ -62,13 +61,13 @@ class {{ obj|ffi_converter_name }}: @classmethod def write(cls, value, buf): - if not isinstance(value, {{ obj|type_name }}): - raise TypeError("Expected {{ obj|type_name }} instance, {} found".format(value.__class__.__name__)) + if not isinstance(value, {{ type_name }}): + raise TypeError("Expected {{ type_name }} instance, {} found".format(value.__class__.__name__)) buf.writeU64(cls.lower(value)) @staticmethod def lift(value): - return {{ obj|type_name }}._make_instance_(value) + return {{ type_name }}._make_instance_(value) @staticmethod def lower(value): diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/OptionalTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/OptionalTemplate.py index f894253e9100..70f705362f45 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/OptionalTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/OptionalTemplate.py @@ -1,8 +1,6 @@ -{%- let inner_type = self.inner() %} -{%- let outer_type = self.outer() %} {%- let inner_ffi_converter = inner_type|ffi_converter_name %} -class {{ outer_type|ffi_converter_name }}(FfiConverterRustBuffer): +class {{ ffi_converter_name }}(FfiConverterRustBuffer): @classmethod def write(cls, value, buf): if value is None: diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/RecordTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/RecordTemplate.py index 8be9489a0796..2009d59e8ac1 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/RecordTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/RecordTemplate.py @@ -1,13 +1,26 @@ -{% import "macros.py" as py %} -{%- let rec = self.inner() %} -class {{ rec|type_name }}: - def __init__(self, {% call py::field_list_decl(rec) %}): +{%- let rec = ci.get_record_definition(name).unwrap() %} +class {{ type_name }}: + + def __init__(self, {% for field in rec.fields() %} + {{- field.name()|var_name }} + {%- if field.default_value().is_some() %} = DEFAULT{% endif %} + {%- if !loop.last %}, {% endif %} + {%- endfor %}): {%- for field in rec.fields() %} - self.{{ field.name()|var_name }} = {{ field.name()|var_name }} + {%- let field_name = field.name()|var_name %} + {%- match field.default_value() %} + {%- when None %} + self.{{ field_name }} = {{ field_name }} + {%- when Some with(literal) %} + if {{ field_name }} is DEFAULT: + self.{{ field_name }} = {{ literal|literal_py(field) }} + else: + self.{{ field_name }} = {{ field_name }} + {%- endmatch %} {%- endfor %} def __str__(self): - return "{{ rec|type_name }}({% for field in rec.fields() %}{{ field.name() }}={}{% if loop.last %}{% else %}, {% endif %}{% endfor %})".format({% for field in rec.fields() %}self.{{ field.name() }}{% if loop.last %}{% else %}, {% endif %}{% endfor %}) + return "{{ type_name }}({% for field in rec.fields() %}{{ field.name()|var_name }}={}{% if loop.last %}{% else %}, {% endif %}{% endfor %})".format({% for field in rec.fields() %}self.{{ field.name()|var_name }}{% if loop.last %}{% else %}, {% endif %}{% endfor %}) def __eq__(self, other): {%- for field in rec.fields() %} @@ -16,10 +29,10 @@ class {{ rec|type_name }}: {%- endfor %} return True -class {{ rec|ffi_converter_name }}(FfiConverterRustBuffer): +class {{ ffi_converter_name }}(FfiConverterRustBuffer): @staticmethod def read(buf): - return {{ rec|type_name }}( + return {{ type_name }}( {%- for field in rec.fields() %} {{ field.name()|var_name }}={{ field|read_fn }}(buf), {%- endfor %} @@ -28,5 +41,5 @@ class {{ rec|ffi_converter_name }}(FfiConverterRustBuffer): @staticmethod def write(value, buf): {%- for field in rec.fields() %} - {{ field|write_fn }}(value.{{ field.name() }}, buf) + {{ field|write_fn }}(value.{{ field.name()|var_name }}, buf) {%- endfor %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/SequenceTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/SequenceTemplate.py index 35bcf40fc18e..6de7bf2d4dc0 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/SequenceTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/SequenceTemplate.py @@ -1,8 +1,6 @@ -{%- let inner_type = self.inner() %} -{%- let outer_type = self.outer() %} {%- let inner_ffi_converter = inner_type|ffi_converter_name %} -class {{ outer_type|ffi_converter_name}}(FfiConverterRustBuffer): +class {{ ffi_converter_name}}(FfiConverterRustBuffer): @classmethod def write(cls, value, buf): items = len(value) diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/TopLevelFunctionTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/TopLevelFunctionTemplate.py index b32a8fde96b8..2d0e09f22d21 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/TopLevelFunctionTemplate.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/TopLevelFunctionTemplate.py @@ -1,15 +1,13 @@ -{% import "macros.py" as py %} -{%- let func = self.inner() %} {%- match func.return_type() -%} {%- when Some with (return_type) %} def {{ func.name()|fn_name }}({%- call py::arg_list_decl(func) -%}): - {%- call py::coerce_args(func) %} + {%- call py::setup_args(func) %} return {{ return_type|lift_fn }}({% call py::to_ffi_call(func) %}) -{% when None -%} +{% when None %} def {{ func.name()|fn_name }}({%- call py::arg_list_decl(func) -%}): - {%- call py::coerce_args(func) %} + {%- call py::setup_args(func) %} {% call py::to_ffi_call(func) %} {% endmatch %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/Types.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/Types.py new file mode 100644 index 000000000000..eb9502083e39 --- /dev/null +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/Types.py @@ -0,0 +1,93 @@ +{%- import "macros.py" as py %} + +{%- for type_ in ci.iter_types() %} +{%- let type_name = type_|type_name %} +{%- let ffi_converter_name = type_|ffi_converter_name %} +{%- let canonical_type_name = type_|canonical_name %} + +{# + # Map `Type` instances to an include statement for that type. + # + # There is a companion match in `PythonCodeOracle::create_code_type()` which performs a similar function for the + # Rust code. + # + # - When adding additional types here, make sure to also add a match arm to that function. + # - To keep things managable, let's try to limit ourselves to these 2 mega-matches + #} +{%- match type_ %} + +{%- when Type::Boolean %} +{%- include "BooleanHelper.py" %} + +{%- when Type::Int8 %} +{%- include "Int8Helper.py" %} + +{%- when Type::Int16 %} +{%- include "Int16Helper.py" %} + +{%- when Type::Int32 %} +{%- include "Int32Helper.py" %} + +{%- when Type::Int64 %} +{%- include "Int64Helper.py" %} + +{%- when Type::UInt8 %} +{%- include "UInt8Helper.py" %} + +{%- when Type::UInt16 %} +{%- include "UInt16Helper.py" %} + +{%- when Type::UInt32 %} +{%- include "UInt32Helper.py" %} + +{%- when Type::UInt64 %} +{%- include "UInt64Helper.py" %} + +{%- when Type::Float32 %} +{%- include "Float32Helper.py" %} + +{%- when Type::Float64 %} +{%- include "Float64Helper.py" %} + +{%- when Type::String %} +{%- include "StringHelper.py" %} + +{%- when Type::Enum(name) %} +{%- include "EnumTemplate.py" %} + +{%- when Type::Error(name) %} +{%- include "ErrorTemplate.py" %} + +{%- when Type::Record(name) %} +{%- include "RecordTemplate.py" %} + +{%- when Type::Object(name) %} +{%- include "ObjectTemplate.py" %} + +{%- when Type::Timestamp %} +{%- include "TimestampHelper.py" %} + +{%- when Type::Duration %} +{%- include "DurationHelper.py" %} + +{%- when Type::Optional(inner_type) %} +{%- include "OptionalTemplate.py" %} + +{%- when Type::Sequence(inner_type) %} +{%- include "SequenceTemplate.py" %} + +{%- when Type::Map(key_type, value_type) %} +{%- include "MapTemplate.py" %} + +{%- when Type::CallbackInterface(id) %} +{%- include "CallbackInterfaceTemplate.py" %} + +{%- when Type::Custom { name, builtin } %} +{%- include "CustomType.py" %} + +{%- when Type::External { name, crate_name } %} +{%- include "ExternalTemplate.py" %} + +{%- else %} +{%- endmatch %} +{%- endfor %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/macros.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/macros.py index be0c824e4ec9..e81ec1a6e9be 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/macros.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/macros.py @@ -32,7 +32,7 @@ rust_call( {%- macro _arg_list_ffi_call(func) %} {%- for arg in func.arguments() %} - {{ arg|lower_fn }}({{ arg.name() }}) + {{ arg|lower_fn }}({{ arg.name()|var_name }}) {%- if !loop.last %},{% endif %} {%- endfor %} {%- endmacro -%} @@ -46,28 +46,13 @@ rust_call( {%- for arg in func.arguments() -%} {{ arg.name()|var_name }} {%- match arg.default_value() %} - {%- when Some with(literal) %} = {{ literal|literal_py(arg.type_().borrow()) }} + {%- when Some with(literal) %} = DEFAULT {%- else %} {%- endmatch %} {%- if !loop.last %},{% endif -%} {%- endfor %} {%- endmacro %} -{#- -// Field lists as used in Python declarations of Records. -// Note the var_name. --#} -{%- macro field_list_decl(item) %} - {%- for field in item.fields() -%} - {{ field.name()|var_name }} - {%- match field.default_value() %} - {%- when Some with(literal) %} = {{ literal|literal_py(field) }} - {%- else %} - {%- endmatch -%} - {% if !loop.last %}, {% endif %} - {%- endfor %} -{%- endmacro %} - {#- // Arglist as used in the _UniFFILib function declations. // Note unfiltered name but ffi_type_name filters. @@ -79,14 +64,38 @@ rust_call( ctypes.POINTER(RustCallStatus), {% endmacro -%} -{%- macro coerce_args(func) %} +{# + # Setup function arguments by initializing default values and passing other + # values through coerce. + #} +{%- macro setup_args(func) %} {%- for arg in func.arguments() %} - {{ arg.name() }} = {{ arg.name()|coerce_py(arg.type_().borrow()) -}} + {%- match arg.default_value() %} + {%- when None %} + {{ arg.name()|var_name }} = {{ arg.name()|var_name|coerce_py(arg.type_().borrow()) -}} + {%- when Some with(literal) %} + if {{ arg.name()|var_name }} is DEFAULT: + {{ arg.name()|var_name }} = {{ literal|literal_py(arg.type_().borrow()) }} + else: + {{ arg.name()|var_name }} = {{ arg.name()|var_name|coerce_py(arg.type_().borrow()) -}} + {%- endmatch %} {% endfor -%} {%- endmacro -%} -{%- macro coerce_args_extra_indent(func) %} +{# + # Exactly the same thing as `setup_args()` but with an extra 4 spaces of + # indent so that it works with object methods. + #} +{%- macro setup_args_extra_indent(func) %} {%- for arg in func.arguments() %} - {{ arg.name() }} = {{ arg.name()|coerce_py(arg.type_().borrow()) }} - {%- endfor %} + {%- match arg.default_value() %} + {%- when None %} + {{ arg.name()|var_name }} = {{ arg.name()|var_name|coerce_py(arg.type_().borrow()) -}} + {%- when Some with(literal) %} + if {{ arg.name()|var_name }} is DEFAULT: + {{ arg.name()|var_name }} = {{ literal|literal_py(arg.type_().borrow()) }} + else: + {{ arg.name()|var_name }} = {{ arg.name()|var_name|coerce_py(arg.type_().borrow()) -}} + {%- endmatch %} + {% endfor -%} {%- endmacro -%} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/wrapper.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/wrapper.py index 39b2feb477d3..01695244db88 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/wrapper.py +++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/wrapper.py @@ -28,6 +28,9 @@ import datetime import {{ module_name }} {%- endfor %} +# Used for default argument values +DEFAULT = object() + {% include "RustBufferTemplate.py" %} {% include "Helpers.py" %} {% include "RustBufferHelper.py" %} @@ -37,28 +40,30 @@ import {{ module_name }} {% include "NamespaceLibraryTemplate.py" %} # Public interface members begin here. -{% for code in self.declaration_code() %} -{{ code }} +{{ type_helper_code }} + +{%- for func in ci.function_definitions() %} +{%- include "TopLevelFunctionTemplate.py" %} {%- endfor %} __all__ = [ "InternalError", - {%- for e in ci.iter_enum_definitions() %} + {%- for e in ci.enum_definitions() %} "{{ e|type_name }}", {%- endfor %} - {%- for record in ci.iter_record_definitions() %} + {%- for record in ci.record_definitions() %} "{{ record|type_name }}", {%- endfor %} - {%- for func in ci.iter_function_definitions() %} + {%- for func in ci.function_definitions() %} "{{ func.name()|fn_name }}", {%- endfor %} - {%- for obj in ci.iter_object_definitions() %} + {%- for obj in ci.object_definitions() %} "{{ obj|type_name }}", {%- endfor %} - {%- for e in ci.iter_error_definitions() %} + {%- for e in ci.error_definitions() %} "{{ e|type_name }}", {%- endfor %} - {%- for c in ci.iter_callback_interface_definitions() %} + {%- for c in ci.callback_interface_definitions() %} "{{ c.name()|class_name }}", {%- endfor %} ] diff --git a/third_party/rust/uniffi_bindgen/src/bindings/ruby/gen_ruby/mod.rs b/third_party/rust/uniffi_bindgen/src/bindings/ruby/gen_ruby/mod.rs index 6183fb23ba5f..77df9733676c 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/ruby/gen_ruby/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/ruby/gen_ruby/mod.rs @@ -92,7 +92,7 @@ mod filters { FFIType::UInt64 => ":uint64".to_string(), FFIType::Float32 => ":float".to_string(), FFIType::Float64 => ":double".to_string(), - FFIType::RustArcPtr => ":pointer".to_string(), + FFIType::RustArcPtr(_) => ":pointer".to_string(), FFIType::RustBuffer => "RustBuffer.by_value".to_string(), FFIType::ForeignBytes => "ForeignBytes".to_string(), FFIType::ForeignCallback => unimplemented!("Callback interfaces are not implemented"), diff --git a/third_party/rust/uniffi_bindgen/src/bindings/ruby/mod.rs b/third_party/rust/uniffi_bindgen/src/bindings/ruby/mod.rs index d3bc826b6a02..5e5b26771969 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/ruby/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/ruby/mod.rs @@ -2,18 +2,13 @@ * 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/. */ -use std::{ - env, - ffi::OsString, - fs::File, - io::Write, - path::{Path, PathBuf}, - process::Command, -}; +use std::{env, io::Write, process::Command}; use anyhow::{bail, Context, Result}; +use fs_err::File; pub mod gen_ruby; +use camino::Utf8Path; pub use gen_ruby::{Config, RubyWrapper}; use super::super::interface::ComponentInterface; @@ -23,23 +18,18 @@ use super::super::interface::ComponentInterface; pub fn write_bindings( config: &Config, ci: &ComponentInterface, - out_dir: &Path, + out_dir: &Utf8Path, try_format_code: bool, ) -> Result<()> { - let mut rb_file = PathBuf::from(out_dir); - rb_file.push(format!("{}.rb", ci.namespace())); - let mut f = File::create(&rb_file).context("Failed to create .rb file for bindings")?; + let rb_file = out_dir.join(format!("{}.rb", ci.namespace())); + let mut f = File::create(&rb_file)?; write!(f, "{}", generate_ruby_bindings(config, ci)?)?; if try_format_code { - if let Err(e) = Command::new("rubocop") - .arg("-A") - .arg(rb_file.to_str().unwrap()) - .output() - { + if let Err(e) = Command::new("rubocop").arg("-A").arg(&rb_file).output() { println!( "Warning: Unable to auto-format {} using rubocop: {:?}", - rb_file.file_name().unwrap().to_str().unwrap(), + rb_file.file_name().unwrap(), e ) } @@ -54,16 +44,17 @@ pub fn generate_ruby_bindings(config: &Config, ci: &ComponentInterface) -> Resul use askama::Template; RubyWrapper::new(config.clone(), ci) .render() - .map_err(|_| anyhow::anyhow!("failed to render ruby bindings")) + .context("failed to render ruby bindings") } /// Execute the specifed ruby script, with environment based on the generated /// artifacts in the given output directory. -pub fn run_script(out_dir: &Path, script_file: &Path) -> Result<()> { +pub fn run_script(out_dir: &Utf8Path, script_file: &Utf8Path) -> Result<()> { let mut cmd = Command::new("ruby"); // This helps ruby find the generated .rb wrapper for rust component. - let rubypath = env::var_os("RUBYLIB").unwrap_or_else(|| OsString::from("")); - let rubypath = env::join_paths(env::split_paths(&rubypath).chain(vec![out_dir.to_path_buf()]))?; + let rubypath = env::var_os("RUBYLIB").unwrap_or_default(); + let rubypath = + env::join_paths(env::split_paths(&rubypath).chain(vec![out_dir.as_std_path().to_owned()]))?; cmd.env("RUBYLIB", rubypath); // We should now be able to execute the tests successfully. diff --git a/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/ErrorTemplate.rb b/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/ErrorTemplate.rb index 5e815f30ad8d..72a7779b6509 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/ErrorTemplate.rb +++ b/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/ErrorTemplate.rb @@ -19,7 +19,7 @@ end CALL_SUCCESS = 0 CALL_ERROR = 1 CALL_PANIC = 2 -{%- for e in ci.iter_error_definitions() %} +{%- for e in ci.error_definitions() %} {% if e.is_flat() %} class {{ e.name()|class_name_rb }} {%- for variant in e.variants() %} @@ -47,7 +47,7 @@ end # Map error modules to the RustBuffer method name that reads them ERROR_MODULE_TO_READER_METHOD = { -{%- for e in ci.iter_error_definitions() %} +{%- for e in ci.error_definitions() %} {%- let typ=ci.get_type(e.name()).unwrap() %} {%- let canonical_type_name = typ.canonical_name().borrow()|class_name_rb %} {{ e.name()|class_name_rb }} => :read{{ canonical_type_name }}, diff --git a/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/TopLevelFunctionTemplate.rb b/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/TopLevelFunctionTemplate.rb index 04fa5db5e091..13214cf31b53 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/TopLevelFunctionTemplate.rb +++ b/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/TopLevelFunctionTemplate.rb @@ -7,7 +7,7 @@ def self.{{ func.name()|fn_name_rb }}({%- call rb::arg_list_decl(func) -%}) return {{ "result"|lift_rb(return_type) }} end -{% when None -%} +{% when None %} def self.{{ func.name()|fn_name_rb }}({%- call rb::arg_list_decl(func) -%}) {%- call rb::coerce_args(func) %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/wrapper.rb b/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/wrapper.rb index 31c0eeaf0e0c..72cb60f73fac 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/wrapper.rb +++ b/third_party/rust/uniffi_bindgen/src/bindings/ruby/templates/wrapper.rb @@ -27,19 +27,19 @@ module {{ ci.namespace()|class_name_rb }} # Public interface members begin here. - {% for e in ci.iter_enum_definitions() %} + {% for e in ci.enum_definitions() %} {% include "EnumTemplate.rb" %} {%- endfor -%} - {%- for rec in ci.iter_record_definitions() %} + {%- for rec in ci.record_definitions() %} {% include "RecordTemplate.rb" %} {% endfor %} - {% for func in ci.iter_function_definitions() %} + {% for func in ci.function_definitions() %} {% include "TopLevelFunctionTemplate.rb" %} {% endfor %} - {% for obj in ci.iter_object_definitions() %} + {% for obj in ci.object_definitions() %} {% include "ObjectTemplate.rb" %} {% endfor %} end diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/callback_interface.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/callback_interface.rs index 4c1010971d83..828a8823ee29 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/callback_interface.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/callback_interface.rs @@ -2,12 +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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{CallbackInterface, ComponentInterface}; -use askama::Template; - -use super::filters; -use super::Config; +use crate::backend::{CodeOracle, CodeType}; pub struct CallbackInterfaceCodeType { id: String, @@ -27,74 +22,4 @@ impl CodeType for CallbackInterfaceCodeType { fn canonical_name(&self, oracle: &dyn CodeOracle) -> String { format!("CallbackInterface{}", self.type_label(oracle)) } - - fn literal(&self, _oracle: &dyn CodeOracle, _literal: &Literal) -> String { - unreachable!(); - } - - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - None - } -} - -#[derive(Template)] -#[template( - syntax = "swift", - escape = "none", - path = "CallbackInterfaceTemplate.swift" -)] -pub struct SwiftCallbackInterface { - inner: CallbackInterface, - config: Config, -} - -impl SwiftCallbackInterface { - pub fn new(inner: CallbackInterface, _ci: &ComponentInterface, config: Config) -> Self { - Self { inner, config } - } - pub fn inner(&self) -> &CallbackInterface { - &self.inner - } -} - -impl CodeDeclaration for SwiftCallbackInterface { - fn initialization_code(&self, _oracle: &dyn CodeOracle) -> Option { - None - } - - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - - fn imports(&self, _oracle: &dyn CodeOracle) -> Option> { - None - } -} - -#[derive(Template)] -#[template( - syntax = "swift", - escape = "none", - path = "CallbackInterfaceRuntime.swift" -)] -pub struct SwiftCallbackInterfaceRuntime { - is_needed: bool, -} - -impl SwiftCallbackInterfaceRuntime { - pub fn new(ci: &ComponentInterface) -> Self { - Self { - is_needed: !ci.iter_callback_interface_definitions().is_empty(), - } - } -} - -impl CodeDeclaration for SwiftCallbackInterfaceRuntime { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - if !self.is_needed { - None - } else { - Some(self.render().unwrap()) - } - } } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/compounds.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/compounds.rs index 351279e65cd3..bc292ca554ea 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/compounds.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/compounds.rs @@ -3,103 +3,72 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use crate::backend::{CodeOracle, CodeType, Literal, TypeIdentifier}; -use askama::Template; -use paste::paste; -// Used in template files. -use super::filters; +pub struct OptionalCodeType { + inner: TypeIdentifier, +} -fn render_literal(oracle: &dyn CodeOracle, literal: &Literal, inner: &TypeIdentifier) -> String { - match literal { - Literal::Null => "nil".into(), - Literal::EmptySequence => "[]".into(), - Literal::EmptyMap => "[:]".into(), - - // For optionals - _ => oracle.find(inner).literal(oracle, literal), +impl OptionalCodeType { + pub fn new(inner: TypeIdentifier) -> Self { + Self { inner } } } -macro_rules! impl_code_type_for_compound { - ($T:ty, $type_label_pattern:literal, $canonical_name_pattern:literal, $template_file:literal) => { - paste! { - #[derive(Template)] - #[template(syntax = "swift", escape = "none", path = $template_file)] - pub struct $T { - inner: TypeIdentifier, - outer: TypeIdentifier, - } +impl CodeType for OptionalCodeType { + fn type_label(&self, oracle: &dyn CodeOracle) -> String { + format!("{}?", oracle.find(&self.inner).type_label(oracle)) + } - impl $T { - pub fn new(inner: TypeIdentifier, outer: TypeIdentifier) -> Self { - Self { inner, outer } - } - fn inner(&self) -> &TypeIdentifier { - &self.inner - } - fn outer(&self) -> &TypeIdentifier { - &self.outer - } - } + fn canonical_name(&self, oracle: &dyn CodeOracle) -> String { + format!("Option{}", oracle.find(&self.inner).canonical_name(oracle)) + } - impl CodeType for $T { - fn type_label(&self, oracle: &dyn CodeOracle) -> String { - format!($type_label_pattern, oracle.find(self.inner()).type_label(oracle)) - } - - fn canonical_name(&self, oracle: &dyn CodeOracle) -> String { - format!($canonical_name_pattern, oracle.find(self.inner()).canonical_name(oracle)) - } - - fn literal(&self, oracle: &dyn CodeOracle, literal: &Literal) -> String { - render_literal(oracle, literal, self.inner()) - } - - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - } + fn literal(&self, oracle: &dyn CodeOracle, literal: &Literal) -> String { + match literal { + Literal::Null => "nil".into(), + _ => oracle.find(&self.inner).literal(oracle, literal), } } - } +} -impl_code_type_for_compound!( - OptionalCodeType, - "{}?", - "Option{}", - "OptionalTemplate.swift" -); +pub struct SequenceCodeType { + inner: TypeIdentifier, +} -impl_code_type_for_compound!( - SequenceCodeType, - "[{}]", - "Sequence{}", - "SequenceTemplate.swift" -); +impl SequenceCodeType { + pub fn new(inner: TypeIdentifier) -> Self { + Self { inner } + } +} + +impl CodeType for SequenceCodeType { + fn type_label(&self, oracle: &dyn CodeOracle) -> String { + format!("[{}]", oracle.find(&self.inner).type_label(oracle)) + } + + fn canonical_name(&self, oracle: &dyn CodeOracle) -> String { + format!( + "Sequence{}", + oracle.find(&self.inner).canonical_name(oracle) + ) + } + + fn literal(&self, _oracle: &dyn CodeOracle, literal: &Literal) -> String { + match literal { + Literal::EmptySequence => "[]".into(), + _ => unreachable!(), + } + } +} -#[derive(Template)] -#[template(syntax = "swift", escape = "none", path = "MapTemplate.swift")] pub struct MapCodeType { key: TypeIdentifier, value: TypeIdentifier, - outer: TypeIdentifier, } impl MapCodeType { - pub fn new(key: TypeIdentifier, value: TypeIdentifier, outer: TypeIdentifier) -> Self { - Self { key, value, outer } - } - - fn key(&self) -> &TypeIdentifier { - &self.key - } - - fn value(&self) -> &TypeIdentifier { - &self.value - } - - fn outer(&self) -> &TypeIdentifier { - &self.outer + pub fn new(key: TypeIdentifier, value: TypeIdentifier) -> Self { + Self { key, value } } } @@ -107,24 +76,23 @@ impl CodeType for MapCodeType { fn type_label(&self, oracle: &dyn CodeOracle) -> String { format!( "[{}: {}]", - oracle.find(self.key()).type_label(oracle), - oracle.find(self.value()).type_label(oracle) + oracle.find(&self.key).type_label(oracle), + oracle.find(&self.value).type_label(oracle) ) } fn canonical_name(&self, oracle: &dyn CodeOracle) -> String { format!( "Dictionary{}{}", - oracle.find(self.key()).type_label(oracle), - oracle.find(self.value()).type_label(oracle) + oracle.find(&self.key).type_label(oracle), + oracle.find(&self.value).type_label(oracle) ) } - fn literal(&self, oracle: &dyn CodeOracle, literal: &Literal) -> String { - render_literal(oracle, literal, self.value()) - } - - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) + fn literal(&self, _oracle: &dyn CodeOracle, literal: &Literal) -> String { + match literal { + Literal::EmptyMap => "[:]".into(), + _ => unreachable!(), + } } } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/custom.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/custom.rs index 27deb6dd3956..bf1806e5e200 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/custom.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/custom.rs @@ -2,11 +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/. */ -use super::{filters, CustomTypeConfig}; -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{FFIType, Type}; -use askama::Template; -use std::borrow::Borrow; +use crate::backend::{CodeOracle, CodeType}; pub struct CustomCodeType { name: String, @@ -26,51 +22,4 @@ impl CodeType for CustomCodeType { fn canonical_name(&self, _oracle: &dyn CodeOracle) -> String { format!("Type{}", self.name) } - - fn literal(&self, _oracle: &dyn CodeOracle, _literal: &Literal) -> String { - // No such thing as a literal custom type - unreachable!("Can't have a literal of a custom type"); - } - - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(format!( - "// Helper code for {} is found in CustomType.py", - self.name, - )) - } -} - -#[derive(Template)] -#[template(syntax = "swift", escape = "none", path = "CustomType.swift")] -pub struct SwiftCustomType { - name: String, - builtin: Type, - config: Option, -} - -impl SwiftCustomType { - pub fn new(name: String, builtin: Type, config: Option) -> Self { - SwiftCustomType { - name, - builtin, - config, - } - } - - fn builtin_ffi_type(&self) -> FFIType { - FFIType::from(&self.builtin) - } -} - -impl CodeDeclaration for SwiftCustomType { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - - fn imports(&self, _oracle: &dyn CodeOracle) -> Option> { - match &self.config { - None => None, - Some(custom_type_config) => custom_type_config.imports.clone(), - } - } } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/enum_.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/enum_.rs index c6168b580205..04d8422f6abb 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/enum_.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/enum_.rs @@ -2,11 +2,8 @@ * 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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{ComponentInterface, Enum}; -use askama::Template; +use crate::backend::{CodeOracle, CodeType, Literal}; -use super::filters; pub struct EnumCodeType { id: String, } @@ -33,39 +30,4 @@ impl CodeType for EnumCodeType { unreachable!(); } } - - fn helper_code(&self, oracle: &dyn CodeOracle) -> Option { - Some(format!( - "// Helper code for {} enum is found in EnumTemplate.swift", - self.type_label(oracle) - )) - } -} - -#[derive(Template)] -#[template(syntax = "swift", escape = "none", path = "EnumTemplate.swift")] -pub struct SwiftEnum { - inner: Enum, - contains_object_references: bool, -} - -impl SwiftEnum { - pub fn new(inner: Enum, ci: &ComponentInterface) -> Self { - Self { - contains_object_references: ci.item_contains_object_references(&inner), - inner, - } - } - pub fn inner(&self) -> &Enum { - &self.inner - } - pub fn contains_object_references(&self) -> bool { - self.contains_object_references - } -} - -impl CodeDeclaration for SwiftEnum { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/error.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/error.rs index 5405c24810fa..4219f24c3933 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/error.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/error.rs @@ -2,12 +2,8 @@ * 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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{ComponentInterface, Error, Type}; -use askama::Template; -use std::borrow::Borrow; +use crate::backend::{CodeOracle, CodeType}; -use super::filters; pub struct ErrorCodeType { id: String, } @@ -26,43 +22,4 @@ impl CodeType for ErrorCodeType { fn canonical_name(&self, _oracle: &dyn CodeOracle) -> String { format!("Type{}", self.id) } - - fn literal(&self, _oracle: &dyn CodeOracle, _literal: &Literal) -> String { - unreachable!(); - } - - fn helper_code(&self, oracle: &dyn CodeOracle) -> Option { - Some(format!( - "// Helper code for {} error is found in ErrorTemplate.swift", - self.type_label(oracle) - )) - } -} - -#[derive(Template)] -#[template(syntax = "swift", escape = "none", path = "ErrorTemplate.swift")] -pub struct SwiftError { - inner: Error, - contains_object_references: bool, -} - -impl SwiftError { - pub fn new(inner: Error, ci: &ComponentInterface) -> Self { - Self { - contains_object_references: ci.item_contains_object_references(&inner), - inner, - } - } - pub fn inner(&self) -> &Error { - &self.inner - } - pub fn contains_object_references(&self) -> bool { - self.contains_object_references - } -} - -impl CodeDeclaration for SwiftError { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/function.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/function.rs deleted file mode 100644 index fe5eca0e339c..000000000000 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/function.rs +++ /dev/null @@ -1,37 +0,0 @@ -/* 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/. */ - -use crate::backend::{CodeDeclaration, CodeOracle}; -use crate::interface::{ComponentInterface, Function}; -use askama::Template; - -use super::filters; -use super::Config; - -#[derive(Template)] -#[template( - syntax = "swift", - escape = "none", - path = "TopLevelFunctionTemplate.swift" -)] -pub struct SwiftFunction { - inner: Function, - config: Config, -} - -impl SwiftFunction { - pub fn new(inner: Function, _ci: &ComponentInterface, config: Config) -> Self { - Self { inner, config } - } - - pub fn inner(&self) -> &Function { - &self.inner - } -} - -impl CodeDeclaration for SwiftFunction { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } -} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/miscellany.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/miscellany.rs index 64fcea9202bc..4f577349343a 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/miscellany.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/miscellany.rs @@ -2,64 +2,28 @@ * 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/. */ -use crate::backend::{CodeOracle, CodeType, Literal}; -use askama::Template; -use paste::paste; +use crate::backend::{CodeOracle, CodeType}; -#[allow(unused_imports)] -use super::filters; +pub struct TimestampCodeType; -macro_rules! impl_code_type_for_miscellany { - ($T:ty, $class_name:literal, $canonical_name:literal, $imports:expr, $template_file:literal) => { - paste! { - #[derive(Template)] - #[template(syntax = "swift", escape = "none", path = $template_file)] - pub struct $T; +impl CodeType for TimestampCodeType { + fn type_label(&self, _oracle: &dyn CodeOracle) -> String { + "Date".into() + } - impl CodeType for $T { - fn type_label(&self, _oracle: &dyn CodeOracle) -> String { - $class_name.into() - } - - fn canonical_name(&self, _oracle: &dyn CodeOracle) -> String { - $canonical_name.into() - } - - fn literal(&self, _oracle: &dyn CodeOracle, _literal: &Literal) -> String { - unreachable!() - } - - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - - fn imports(&self, _oracle: &dyn CodeOracle) -> Option> { - let imports: Vec<&str> = $imports; - if (!imports.is_empty()) { - Some( - imports.into_iter().map(|s| s.into()).collect() - ) - } else { - None - } - } - } - } - }; + fn canonical_name(&self, _oracle: &dyn CodeOracle) -> String { + "Timestamp".into() + } } -impl_code_type_for_miscellany!( - TimestampCodeType, - "Date", - "Timestamp", - vec![], - "TimestampHelper.swift" -); +pub struct DurationCodeType; -impl_code_type_for_miscellany!( - DurationCodeType, - "TimeInterval", - "Duration", - vec![], - "DurationHelper.swift" -); +impl CodeType for DurationCodeType { + fn type_label(&self, _oracle: &dyn CodeOracle) -> String { + "TimeInterval".into() + } + + fn canonical_name(&self, _oracle: &dyn CodeOracle) -> String { + "Duration".into() + } +} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs index 99ff2136a519..5ffb1b229321 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs @@ -3,15 +3,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::borrow::Borrow; -use std::collections::{HashMap, HashSet}; +use std::cell::RefCell; +use std::collections::{BTreeSet, HashMap, HashSet}; -use anyhow::{anyhow, Result}; +use anyhow::{Context, Result}; use askama::Template; use heck::{ToLowerCamelCase, ToUpperCamelCase}; use serde::{Deserialize, Serialize}; use super::Bindings; -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, TemplateExpression, TypeIdentifier}; +use crate::backend::{CodeOracle, CodeType, TemplateExpression, TypeIdentifier}; use crate::interface::*; use crate::MergeWith; @@ -20,7 +21,6 @@ mod compounds; mod custom; mod enum_; mod error; -mod function; mod miscellany; mod object; mod primitives; @@ -140,15 +140,15 @@ impl MergeWith for Config { pub fn generate_bindings(config: &Config, ci: &ComponentInterface) -> Result { let header = BridgingHeader::new(config, ci) .render() - .map_err(|_| anyhow!("failed to render Swift bridging header"))?; - let library = SwiftWrapper::new(SwiftCodeOracle, config.clone(), ci) + .context("failed to render Swift bridging header")?; + let library = SwiftWrapper::new(config.clone(), ci) .render() - .map_err(|_| anyhow!("failed to render Swift library"))?; + .context("failed to render Swift library")?; let modulemap = if config.generate_module_map() { Some( ModuleMap::new(config, ci) .render() - .map_err(|_| anyhow!("failed to render Swift modulemap"))?, + .context("failed to render Swift modulemap")?, ) } else { None @@ -160,6 +160,55 @@ pub fn generate_bindings(config: &Config, ci: &ComponentInterface) -> Result { + config: &'a Config, + ci: &'a ComponentInterface, + // Track included modules for the `include_once()` macro + include_once_names: RefCell>, + // Track imports added with the `add_import()` macro + imports: RefCell>, +} + +impl<'a> TypeRenderer<'a> { + fn new(config: &'a Config, ci: &'a ComponentInterface) -> Self { + Self { + config, + ci, + include_once_names: RefCell::new(HashSet::new()), + imports: RefCell::new(BTreeSet::new()), + } + } + + // The following methods are used by the `Types.kt` macros. + + // Helper for the including a template, but only once. + // + // The first time this is called with a name it will return true, indicating that we should + // include the template. Subsequent calls will return false. + fn include_once_check(&self, name: &str) -> bool { + self.include_once_names + .borrow_mut() + .insert(name.to_string()) + } + + // Helper to add an import statement + // + // Call this inside your template to cause an import statement to be added at the top of the + // file. Imports will be sorted and de-deuped. + // + // Returns an empty string so that it can be used inside an askama `{{ }}` block. + fn add_import(&self, name: &str) -> &str { + self.imports.borrow_mut().insert(name.to_owned()); + "" + } +} + /// Template for generating the `.h` file that defines the low-level C FFI. /// /// This file defines only the low-level structs and functions that are exposed @@ -205,103 +254,32 @@ impl<'config, 'ci> ModuleMap<'config, 'ci> { pub struct SwiftWrapper<'a> { config: Config, ci: &'a ComponentInterface, - oracle: SwiftCodeOracle, + type_helper_code: String, + type_imports: BTreeSet, } impl<'a> SwiftWrapper<'a> { - pub fn new(oracle: SwiftCodeOracle, config: Config, ci: &'a ComponentInterface) -> Self { - Self { oracle, config, ci } - } - - pub fn members(&self) -> Vec> { - let ci = self.ci; - vec![ - Box::new(callback_interface::SwiftCallbackInterfaceRuntime::new(ci)) - as Box, - ] - .into_iter() - .chain( - ci.iter_enum_definitions().into_iter().map(|inner| { - Box::new(enum_::SwiftEnum::new(inner, ci)) as Box - }), - ) - .chain(ci.iter_function_definitions().into_iter().map(|inner| { - Box::new(function::SwiftFunction::new(inner, ci, self.config.clone())) - as Box - })) - .chain(ci.iter_object_definitions().into_iter().map(|inner| { - Box::new(object::SwiftObject::new(inner, ci, self.config.clone())) - as Box - })) - .chain( - ci.iter_record_definitions().into_iter().map(|inner| { - Box::new(record::SwiftRecord::new(inner, ci)) as Box - }), - ) - .chain( - ci.iter_error_definitions().into_iter().map(|inner| { - Box::new(error::SwiftError::new(inner, ci)) as Box - }), - ) - .chain( - ci.iter_callback_interface_definitions() - .into_iter() - .map(|inner| { - Box::new(callback_interface::SwiftCallbackInterface::new( - inner, - ci, - self.config.clone(), - )) as Box - }), - ) - .chain(ci.iter_custom_types().into_iter().map(|(name, type_)| { - let config = self.config.custom_types.get(&name).cloned(); - Box::new(custom::SwiftCustomType::new(name, type_, config)) as Box - })) - .collect() - } - - pub fn initialization_code(&self) -> Vec { - let oracle = &self.oracle; - self.members() - .into_iter() - .filter_map(|member| member.initialization_code(oracle)) - .collect() - } - - pub fn declaration_code(&self) -> Vec { - let oracle = &self.oracle; - self.members() - .into_iter() - .filter_map(|member| member.definition_code(oracle)) - .chain( - self.ci - .iter_types() - .into_iter() - .filter_map(|type_| oracle.find(&type_).helper_code(oracle)), - ) - .collect() + pub fn new(config: Config, ci: &'a ComponentInterface) -> Self { + let type_renderer = TypeRenderer::new(&config, ci); + let type_helper_code = type_renderer.render().unwrap(); + let type_imports = type_renderer.imports.into_inner(); + Self { + config, + ci, + type_helper_code, + type_imports, + } } pub fn imports(&self) -> Vec { - let oracle = &self.oracle; - let mut imports: Vec = self - .members() - .into_iter() - .filter_map(|member| member.imports(oracle)) - .flatten() - .chain( - self.ci - .iter_types() - .into_iter() - .filter_map(|type_| oracle.find(&type_).imports(oracle)) - .flatten(), - ) - .collect::>() - .into_iter() - .collect(); + self.type_imports.iter().cloned().collect() + } - imports.sort(); - imports + pub fn initialization_fns(&self) -> Vec { + self.ci + .iter_types() + .into_iter() + .filter_map(|t| t.initialization_fn(&SwiftCodeOracle)) + .collect() } } @@ -309,11 +287,14 @@ impl<'a> SwiftWrapper<'a> { pub struct SwiftCodeOracle; impl SwiftCodeOracle { + // Map `Type` instances to a `Box` for that type. + // + // There is a companion match in `templates/Types.swift` which performs a similar function for the + // template code. + // + // - When adding additional types here, make sure to also add a match arm to the `Types.swift` template. + // - To keep things managable, let's try to limit ourselves to these 2 mega-matches fn create_code_type(&self, type_: TypeIdentifier) -> Box { - // I really want access to the ComponentInterface here so I can look up the interface::{Enum, Record, Error, Object, etc} - // However, there's some violence and gore I need to do to (temporarily) make the oracle usable from filters. - - // Some refactor of the templates is needed to make progress here: I think most of the filter functions need to take an &dyn CodeOracle match type_ { Type::UInt8 => Box::new(primitives::UInt8CodeType), Type::Int8 => Box::new(primitives::Int8CodeType), @@ -339,22 +320,9 @@ impl SwiftCodeOracle { Box::new(callback_interface::CallbackInterfaceCodeType::new(id)) } - Type::Optional(ref inner) => { - let outer = type_.clone(); - let inner = *inner.to_owned(); - Box::new(compounds::OptionalCodeType::new(inner, outer)) - } - Type::Sequence(ref inner) => { - let outer = type_.clone(); - let inner = *inner.to_owned(); - Box::new(compounds::SequenceCodeType::new(inner, outer)) - } - Type::Map(ref key, ref value) => { - let outer = type_.clone(); - let key = *key.to_owned(); - let value = *value.to_owned(); - Box::new(compounds::MapCodeType::new(key, value, outer)) - } + Type::Optional(inner) => Box::new(compounds::OptionalCodeType::new(*inner)), + Type::Sequence(inner) => Box::new(compounds::SequenceCodeType::new(*inner)), + Type::Map(key, value) => Box::new(compounds::MapCodeType::new(*key, *value)), Type::External { .. } => panic!("no support for external types yet"), Type::Custom { name, .. } => Box::new(custom::CustomCodeType::new(name)), } @@ -403,7 +371,7 @@ impl CodeOracle for SwiftCodeOracle { FFIType::UInt64 => "uint64_t".into(), FFIType::Float32 => "float".into(), FFIType::Float64 => "double".into(), - FFIType::RustArcPtr => "void*_Nonnull".into(), + FFIType::RustArcPtr(_) => "void*_Nonnull".into(), FFIType::RustBuffer => "RustBuffer".into(), FFIType::ForeignBytes => "ForeignBytes".into(), FFIType::ForeignCallback => "ForeignCallback _Nonnull".to_string(), @@ -475,7 +443,7 @@ pub mod filters { FFIType::UInt64 => "UInt64".into(), FFIType::Float32 => "float".into(), FFIType::Float64 => "double".into(), - FFIType::RustArcPtr => "void*_Nonnull".into(), + FFIType::RustArcPtr(_) => "void*_Nonnull".into(), FFIType::RustBuffer => "RustBuffer".into(), FFIType::ForeignBytes => "ForeignBytes".into(), FFIType::ForeignCallback => "ForeignCallback _Nonnull".to_string(), diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/object.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/object.rs index d829390fcad9..d227f8e7cd6e 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/object.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/object.rs @@ -2,12 +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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{ComponentInterface, Object}; -use askama::Template; - -use super::filters; -use super::Config; +use crate::backend::{CodeOracle, CodeType}; pub struct ObjectCodeType { id: String, @@ -27,42 +22,4 @@ impl CodeType for ObjectCodeType { fn canonical_name(&self, _oracle: &dyn CodeOracle) -> String { format!("Type{}", self.id) } - - fn literal(&self, _oracle: &dyn CodeOracle, _literal: &Literal) -> String { - unreachable!(); - } - - fn helper_code(&self, oracle: &dyn CodeOracle) -> Option { - Some(format!( - "// Helper code for {} class is found in ObjectTemplate.swift", - self.type_label(oracle) - )) - } -} - -#[derive(Template)] -#[template(syntax = "swift", escape = "none", path = "ObjectTemplate.swift")] -pub struct SwiftObject { - config: Config, - inner: Object, -} - -impl SwiftObject { - pub fn new(inner: Object, _ci: &ComponentInterface, config: Config) -> Self { - Self { inner, config } - } - - pub fn inner(&self) -> &Object { - &self.inner - } -} - -impl CodeDeclaration for SwiftObject { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } - - fn imports(&self, _oracle: &dyn CodeOracle) -> Option> { - None - } } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/primitives.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/primitives.rs index a6eae46446c5..4a9051fcef15 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/primitives.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/primitives.rs @@ -4,12 +4,8 @@ use crate::backend::{CodeOracle, CodeType, Literal}; use crate::interface::{types::Type, Radix}; -use askama::Template; use paste::paste; -#[allow(unused_imports)] -use super::filters; - fn render_literal(oracle: &dyn CodeOracle, literal: &Literal) -> String { fn typed_number(oracle: &dyn CodeOracle, type_: &Type, num_str: String) -> String { match type_ { @@ -60,10 +56,8 @@ fn render_literal(oracle: &dyn CodeOracle, literal: &Literal) -> String { } macro_rules! impl_code_type_for_primitive { - ($T:ty, $class_name:literal, $template_file:literal) => { + ($T:ty, $class_name:literal) => { paste! { - #[derive(Template)] - #[template(syntax = "swift", escape = "none", path = $template_file)] pub struct $T; impl CodeType for $T { @@ -74,24 +68,20 @@ macro_rules! impl_code_type_for_primitive { fn literal(&self, oracle: &dyn CodeOracle, literal: &Literal) -> String { render_literal(oracle, &literal) } - - fn helper_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } } } }; } -impl_code_type_for_primitive!(BooleanCodeType, "Bool", "BooleanHelper.swift"); -impl_code_type_for_primitive!(StringCodeType, "String", "StringHelper.swift"); -impl_code_type_for_primitive!(Int8CodeType, "Int8", "Int8Helper.swift"); -impl_code_type_for_primitive!(Int16CodeType, "Int16", "Int16Helper.swift"); -impl_code_type_for_primitive!(Int32CodeType, "Int32", "Int32Helper.swift"); -impl_code_type_for_primitive!(Int64CodeType, "Int64", "Int64Helper.swift"); -impl_code_type_for_primitive!(UInt8CodeType, "UInt8", "UInt8Helper.swift"); -impl_code_type_for_primitive!(UInt16CodeType, "UInt16", "UInt16Helper.swift"); -impl_code_type_for_primitive!(UInt32CodeType, "UInt32", "UInt32Helper.swift"); -impl_code_type_for_primitive!(UInt64CodeType, "UInt64", "UInt64Helper.swift"); -impl_code_type_for_primitive!(Float32CodeType, "Float", "Float32Helper.swift"); -impl_code_type_for_primitive!(Float64CodeType, "Double", "Float64Helper.swift"); +impl_code_type_for_primitive!(BooleanCodeType, "Bool"); +impl_code_type_for_primitive!(StringCodeType, "String"); +impl_code_type_for_primitive!(Int8CodeType, "Int8"); +impl_code_type_for_primitive!(Int16CodeType, "Int16"); +impl_code_type_for_primitive!(Int32CodeType, "Int32"); +impl_code_type_for_primitive!(Int64CodeType, "Int64"); +impl_code_type_for_primitive!(UInt8CodeType, "UInt8"); +impl_code_type_for_primitive!(UInt16CodeType, "UInt16"); +impl_code_type_for_primitive!(UInt32CodeType, "UInt32"); +impl_code_type_for_primitive!(UInt64CodeType, "UInt64"); +impl_code_type_for_primitive!(Float32CodeType, "Float"); +impl_code_type_for_primitive!(Float64CodeType, "Double"); diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/record.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/record.rs index e8e77ebf6ba7..0943bcaada0b 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/record.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/gen_swift/record.rs @@ -2,11 +2,8 @@ * 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/. */ -use crate::backend::{CodeDeclaration, CodeOracle, CodeType, Literal}; -use crate::interface::{ComponentInterface, Record}; -use askama::Template; +use crate::backend::{CodeOracle, CodeType}; -use super::filters; pub struct RecordCodeType { id: String, } @@ -25,43 +22,4 @@ impl CodeType for RecordCodeType { fn canonical_name(&self, _oracle: &dyn CodeOracle) -> String { format!("Type{}", self.id) } - - fn literal(&self, _oracle: &dyn CodeOracle, _literal: &Literal) -> String { - unreachable!(); - } - - fn helper_code(&self, oracle: &dyn CodeOracle) -> Option { - Some(format!( - "// Helper code for {} record is found in RecordTemplate.swift", - self.type_label(oracle) - )) - } -} - -#[derive(Template)] -#[template(syntax = "swift", escape = "none", path = "RecordTemplate.swift")] -pub struct SwiftRecord { - inner: Record, - contains_object_references: bool, -} - -impl SwiftRecord { - pub fn new(inner: Record, ci: &ComponentInterface) -> Self { - Self { - contains_object_references: ci.item_contains_object_references(&inner), - inner, - } - } - pub fn inner(&self) -> &Record { - &self.inner - } - pub fn contains_object_references(&self) -> bool { - self.contains_object_references - } -} - -impl CodeDeclaration for SwiftRecord { - fn definition_code(&self, _oracle: &dyn CodeOracle) -> Option { - Some(self.render().unwrap()) - } } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/mod.rs b/third_party/rust/uniffi_bindgen/src/bindings/swift/mod.rs index 7df13afc80b4..740759acbfe4 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/mod.rs @@ -29,14 +29,11 @@ //! * How to read from and write into a byte buffer. //! +use std::{ffi::OsString, io::Write, process::Command}; + use anyhow::{bail, Context, Result}; -use std::{ - ffi::OsString, - fs::File, - io::Write, - path::{Path, PathBuf}, - process::Command, -}; +use camino::Utf8Path; +use fs_err::File; pub mod gen_swift; pub use gen_swift::{generate_bindings, Config}; @@ -62,43 +59,35 @@ pub struct Bindings { pub fn write_bindings( config: &Config, ci: &ComponentInterface, - out_dir: &Path, + out_dir: &Utf8Path, try_format_code: bool, ) -> Result<()> { - let out_path = PathBuf::from(out_dir); - let Bindings { header, library, modulemap, } = generate_bindings(config, ci)?; - let mut source_file = out_path.clone(); - source_file.push(format!("{}.swift", config.module_name())); - let mut l = File::create(&source_file).context("Failed to create .swift file for bindings")?; + let source_file = out_dir.join(format!("{}.swift", config.module_name())); + let mut l = File::create(&source_file)?; write!(l, "{}", library)?; - let mut header_file = out_path.clone(); - header_file.push(config.header_filename()); - let mut h = File::create(&header_file).context("Failed to create .h file for bindings")?; + let mut h = File::create(out_dir.join(config.header_filename()))?; write!(h, "{}", header)?; if let Some(modulemap) = modulemap { - let mut modulemap_file = out_path; - modulemap_file.push(config.modulemap_filename()); - let mut m = File::create(&modulemap_file) - .context("Failed to create .modulemap file for bindings")?; + let mut m = File::create(out_dir.join(config.modulemap_filename()))?; write!(m, "{}", modulemap)?; } if try_format_code { if let Err(e) = Command::new("swiftformat") - .arg(source_file.to_str().unwrap()) + .arg(source_file.as_str()) .output() { println!( "Warning: Unable to auto-format {} using swiftformat: {:?}", - source_file.file_name().unwrap().to_str().unwrap(), + source_file.file_name().unwrap(), e ) } @@ -115,23 +104,21 @@ pub fn write_bindings( /// test scripts need to be able to import the generated bindings, we have to compile them /// ahead of time before running the tests. /// -pub fn compile_bindings(config: &Config, ci: &ComponentInterface, out_dir: &Path) -> Result<()> { - let out_path = PathBuf::from(out_dir); - +pub fn compile_bindings( + config: &Config, + ci: &ComponentInterface, + out_dir: &Utf8Path, +) -> Result<()> { if !config.generate_module_map() { bail!("Cannot compile Swift bindings when `generate_module_map` is `false`") } - let mut module_map_file = out_path.clone(); - module_map_file.push(config.modulemap_filename()); + let module_map_file = out_dir.join(config.modulemap_filename()); let mut module_map_file_option = OsString::from("-fmodule-map-file="); module_map_file_option.push(module_map_file.as_os_str()); - let mut source_file = out_path.clone(); - source_file.push(format!("{}.swift", config.module_name())); - - let mut dylib_file = out_path.clone(); - dylib_file.push(format!("lib{}.dylib", config.module_name())); + let source_file = out_dir.join(format!("{}.swift", config.module_name())); + let dylib_file = out_dir.join(format!("lib{}.dylib", config.module_name())); // `-emit-library -o ` generates a `.dylib`, so that we can use the // Swift module from the REPL. Otherwise, we'll get "Couldn't lookup @@ -143,13 +130,13 @@ pub fn compile_bindings(config: &Config, ci: &ComponentInterface, out_dir: &Path .arg(ci.namespace()) .arg("-emit-library") .arg("-o") - .arg(&dylib_file) + .arg(dylib_file) .arg("-emit-module") .arg("-emit-module-path") - .arg(&out_path) + .arg(out_dir) .arg("-parse-as-library") .arg("-L") - .arg(&out_path) + .arg(out_dir) .arg(format!("-l{}", config.cdylib_name())) .arg("-Xcc") .arg(module_map_file_option) @@ -170,7 +157,7 @@ pub fn compile_bindings(config: &Config, ci: &ComponentInterface, out_dir: &Path /// Swift modules in the given output directory. The modules must have been pre-compiled /// using the [`compile_bindings`] function. /// -pub fn run_script(out_dir: &Path, script_file: &Path) -> Result<()> { +pub fn run_script(out_dir: &Utf8Path, script_file: &Utf8Path) -> Result<()> { let mut cmd = Command::new("swift"); // Find any module maps and/or dylibs in the target directory, and tell swift to use them. @@ -179,7 +166,7 @@ pub fn run_script(out_dir: &Path, script_file: &Path) -> Result<()> { // this test function doesn't allow us to pass that name in to the call. cmd.arg("-I").arg(out_dir); - for entry in PathBuf::from(out_dir) + for entry in out_dir .read_dir() .context("Failed to list target directory when running script")? { diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/CallbackInterfaceTemplate.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/CallbackInterfaceTemplate.swift index abfbbe601218..8776cb5737e3 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/CallbackInterfaceTemplate.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/CallbackInterfaceTemplate.swift @@ -1,9 +1,6 @@ -{% import "macros.swift" as swift %} -{%- let cbi = self.inner() %} -{%- let type_name = cbi|type_name %} -{%- let canonical_type_name = cbi|canonical_name %} -{%- let ffi_converter = cbi|ffi_converter_name %} +{%- let cbi = ci.get_callback_interface_definition(name).unwrap() %} {%- let foreign_callback = format!("foreignCallback{}", canonical_type_name) %} +{%- if self.include_once_check("CallbackInterfaceRuntime.swift") %}{%- include "CallbackInterfaceRuntime.swift" %}{%- endif %} // Declaration and FfiConverters for {{ type_name }} Callback Interface @@ -59,10 +56,10 @@ fileprivate let {{ foreign_callback }} : ForeignCallback = } {% endfor %} - let cb = try! {{ ffi_converter }}.lift(handle) + let cb = try! {{ ffi_converter_name }}.lift(handle) switch method { case IDX_CALLBACK_FREE: - {{ ffi_converter }}.drop(handle: handle) + {{ ffi_converter_name }}.drop(handle: handle) // No return value. // See docs of ForeignCallback in `uniffi/src/ffi/foreigncallbacks.rs` return 0 @@ -86,7 +83,7 @@ fileprivate let {{ foreign_callback }} : ForeignCallback = } // FFIConverter protocol for callback interfaces -fileprivate struct {{ ffi_converter }} { +fileprivate struct {{ ffi_converter_name }} { // Initialize our callback method with the scaffolding code private static var callbackInitialized = false private static func initCallback() { @@ -108,7 +105,7 @@ fileprivate struct {{ ffi_converter }} { private static var handleMap = ConcurrentHandleMap<{{ type_name }}>() } -extension {{ ffi_converter }} : FfiConverter { +extension {{ ffi_converter_name }} : FfiConverter { typealias SwiftType = {{ type_name }} // We can use Handle as the FFIType because it's a typealias to UInt64 typealias FfiType = Handle diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/CustomType.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/CustomType.swift index 26af82888610..741d8d631c78 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/CustomType.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/CustomType.swift @@ -1,4 +1,5 @@ -{%- match config %} +{%- let ffi_type_name=builtin.ffi_type().borrow()|ffi_type_name %} +{%- match config.custom_types.get(name.as_str()) %} {%- when None %} {#- No config, just forward all methods to our builtin type #} /** @@ -21,6 +22,14 @@ public typealias {{ name }} = {{ concrete_type_name }} {%- else %} {%- endmatch %} +{%- match config.imports %} +{%- when Some(imports) %} +{%- for import_name in imports %} +{{ self.add_import(import_name) }} +{%- endfor %} +{%- else %} +{%- endmatch %} + fileprivate struct FfiConverterType{{ name }} { {#- Custom type config supplied, use it to convert the builtin type #} @@ -34,12 +43,12 @@ fileprivate struct FfiConverterType{{ name }} { return {{ builtin|write_fn }}(builtinValue, into: buf) } - static func lift(_ value: {{ self.builtin_ffi_type().borrow()|type_ffi_lowered }}) throws -> {{ name }} { + static func lift(_ value: {{ ffi_type_name }}) throws -> {{ name }} { let builtinValue = try {{ builtin|lift_fn }}(value) return {{ config.into_custom.render("builtinValue") }} } - static func lower(_ value: {{ name }}) -> {{ self.builtin_ffi_type().borrow()|type_ffi_lowered }} { + static func lower(_ value: {{ name }}) -> {{ ffi_type_name }} { let builtinValue = {{ config.from_custom.render("value") }} return {{ builtin|lower_fn }}(builtinValue) } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/EnumTemplate.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/EnumTemplate.swift index a512ba06e608..2feca61b1f7e 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/EnumTemplate.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/EnumTemplate.swift @@ -1,18 +1,16 @@ - // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. -{% import "macros.swift" as swift %} -{%- let e = self.inner() %} -public enum {{ e|type_name }} { +{%- let e = ci.get_enum_definition(name).unwrap() %} +public enum {{ type_name }} { {% for variant in e.variants() %} case {{ variant.name()|enum_variant_swift }}{% if variant.fields().len() > 0 %}({% call swift::field_list_decl(variant) %}){% endif -%} {% endfor %} } -fileprivate struct {{ e|ffi_converter_name }}: FfiConverterRustBuffer { - typealias SwiftType = {{ e|type_name }} +fileprivate struct {{ ffi_converter_name }}: FfiConverterRustBuffer { + typealias SwiftType = {{ type_name }} - static func read(from buf: Reader) throws -> {{ e|type_name }} { + static func read(from buf: Reader) throws -> {{ type_name }} { let variant: Int32 = try buf.readInt() switch variant { {% for variant in e.variants() %} @@ -27,7 +25,7 @@ fileprivate struct {{ e|ffi_converter_name }}: FfiConverterRustBuffer { } } - static func write(_ value: {{ e|type_name }}, into buf: Writer) { + static func write(_ value: {{ type_name }}, into buf: Writer) { switch value { {% for variant in e.variants() %} {% if variant.has_fields() %} @@ -45,6 +43,6 @@ fileprivate struct {{ e|ffi_converter_name }}: FfiConverterRustBuffer { } } -{% if ! self.contains_object_references() %} -extension {{ e|type_name }}: Equatable, Hashable {} +{% if !contains_object_references %} +extension {{ type_name }}: Equatable, Hashable {} {% endif %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/ErrorTemplate.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/ErrorTemplate.swift index fafec3e5e0b0..2a1c29868651 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/ErrorTemplate.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/ErrorTemplate.swift @@ -1,6 +1,5 @@ -{% import "macros.swift" as swift %} -{%- let e = self.inner() %} -public enum {{ e|type_name }} { +{%- let e = ci.get_error_definition(name).unwrap() %} +public enum {{ type_name }} { {% if e.is_flat() %} {% for variant in e.variants() %} @@ -16,10 +15,10 @@ public enum {{ e|type_name }} { {%- endif %} } -fileprivate struct {{ e|ffi_converter_name }}: FfiConverterRustBuffer { - typealias SwiftType = {{ e|type_name }} +fileprivate struct {{ ffi_converter_name }}: FfiConverterRustBuffer { + typealias SwiftType = {{ type_name }} - static func read(from buf: Reader) throws -> {{ e|type_name }} { + static func read(from buf: Reader) throws -> {{ type_name }} { let variant: Int32 = try buf.readInt() switch variant { @@ -47,7 +46,7 @@ fileprivate struct {{ e|ffi_converter_name }}: FfiConverterRustBuffer { } } - static func write(_ value: {{ e|type_name }}, into buf: Writer) { + static func write(_ value: {{ type_name }}, into buf: Writer) { switch value { {% if e.is_flat() %} @@ -78,7 +77,7 @@ fileprivate struct {{ e|ffi_converter_name }}: FfiConverterRustBuffer { } } -{% if !self.contains_object_references() %} -extension {{ e|type_name }}: Equatable, Hashable {} +{% if !contains_object_references %} +extension {{ type_name }}: Equatable, Hashable {} {% endif %} -extension {{ e|type_name }}: Error { } +extension {{ type_name }}: Error { } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/MapTemplate.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/MapTemplate.swift index f63209f1624e..20a99a11a926 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/MapTemplate.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/MapTemplate.swift @@ -1,11 +1,5 @@ -{%- import "macros.swift" as swift -%} -{%- let outer_type = self.outer() %} -{%- let dict_type = outer_type|type_name %} -{%- let key_type = self.key() %} -{%- let value_type = self.value() %} - -fileprivate struct {{ outer_type|ffi_converter_name }}: FfiConverterRustBuffer { - fileprivate static func write(_ value: {{ dict_type }}, into buf: Writer) { +fileprivate struct {{ ffi_converter_name }}: FfiConverterRustBuffer { + fileprivate static func write(_ value: {{ type_name }}, into buf: Writer) { let len = Int32(value.count) buf.writeInt(len) for (key, value) in value { @@ -14,9 +8,9 @@ fileprivate struct {{ outer_type|ffi_converter_name }}: FfiConverterRustBuffer { } } - fileprivate static func read(from buf: Reader) throws -> {{ dict_type }} { + fileprivate static func read(from buf: Reader) throws -> {{ type_name }} { let len: Int32 = try buf.readInt() - var dict = {{ dict_type }}() + var dict = {{ type_name }}() dict.reserveCapacity(Int(len)) for _ in 0.. {{ obj|type_name }} { - return {{ obj|type_name }}(unsafeFromRawPointer: {% call swift::to_ffi_call(cons) %}) + public static func {{ cons.name()|fn_name }}({% call swift::arg_list_decl(cons) %}) {% call swift::throws(cons) %} -> {{ type_name }} { + return {{ type_name }}(unsafeFromRawPointer: {% call swift::to_ffi_call(cons) %}) } {% endfor %} @@ -58,11 +57,11 @@ public class {{ obj|type_name }}: {{ obj.name() }}Protocol { } -fileprivate struct {{ obj|ffi_converter_name }}: FfiConverter { +fileprivate struct {{ ffi_converter_name }}: FfiConverter { typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = {{ obj|type_name }} + typealias SwiftType = {{ type_name }} - static func read(from buf: Reader) throws -> {{ obj|type_name }} { + static func read(from buf: Reader) throws -> {{ type_name }} { let v: UInt64 = try buf.readInt() // The Rust code won't compile if a pointer won't fit in a UInt64. // We have to go via `UInt` because that's the thing that's the size of a pointer. @@ -73,17 +72,17 @@ fileprivate struct {{ obj|ffi_converter_name }}: FfiConverter { return try lift(ptr!) } - static func write(_ value: {{ obj|type_name }}, into buf: Writer) { + static func write(_ value: {{ type_name }}, into buf: Writer) { // This fiddling is because `Int` is the thing that's the same size as a pointer. // The Rust code won't compile if a pointer won't fit in a `UInt64`. buf.writeInt(UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) } - static func lift(_ pointer: UnsafeMutableRawPointer) throws -> {{ obj|type_name }} { - return {{ obj|type_name}}(unsafeFromRawPointer: pointer) + static func lift(_ pointer: UnsafeMutableRawPointer) throws -> {{ type_name }} { + return {{ type_name}}(unsafeFromRawPointer: pointer) } - static func lower(_ value: {{ obj|type_name }}) -> UnsafeMutableRawPointer { + static func lower(_ value: {{ type_name }}) -> UnsafeMutableRawPointer { return value.pointer } } diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/OptionalTemplate.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/OptionalTemplate.swift index 25bec628da33..b4cd751d9d15 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/OptionalTemplate.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/OptionalTemplate.swift @@ -1,7 +1,5 @@ -{%- let inner_type = self.inner() %} -{%- let outer_type = self.outer() %} -fileprivate struct {{ outer_type|ffi_converter_name }}: FfiConverterRustBuffer { - typealias SwiftType = {{ outer_type|type_name }} +fileprivate struct {{ ffi_converter_name }}: FfiConverterRustBuffer { + typealias SwiftType = {{ type_name }} static func write(_ value: SwiftType, into buf: Writer) { guard let value = value else { diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/RecordTemplate.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/RecordTemplate.swift index d4f36318d22f..d7ed69d272c3 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/RecordTemplate.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/RecordTemplate.swift @@ -1,6 +1,5 @@ -{% import "macros.swift" as swift %} -{%- let rec = self.inner() %} -public struct {{ rec|type_name }} { +{%- let rec = ci.get_record_definition(name).unwrap() %} +public struct {{ type_name }} { {%- for field in rec.fields() %} public var {{ field.name()|var_name }}: {{ field|type_name }} {%- endfor %} @@ -14,9 +13,9 @@ public struct {{ rec|type_name }} { } } -{% if ! self.contains_object_references() %} -extension {{ rec|type_name }}: Equatable, Hashable { - public static func ==(lhs: {{ rec|type_name }}, rhs: {{ rec|type_name }}) -> Bool { +{% if !contains_object_references %} +extension {{ type_name }}: Equatable, Hashable { + public static func ==(lhs: {{ type_name }}, rhs: {{ type_name }}) -> Bool { {%- for field in rec.fields() %} if lhs.{{ field.name()|var_name }} != rhs.{{ field.name()|var_name }} { return false @@ -33,9 +32,9 @@ extension {{ rec|type_name }}: Equatable, Hashable { } {% endif %} -fileprivate struct {{ rec|ffi_converter_name }}: FfiConverterRustBuffer { - fileprivate static func read(from buf: Reader) throws -> {{ rec|type_name }} { - return try {{ rec|type_name }}( +fileprivate struct {{ ffi_converter_name }}: FfiConverterRustBuffer { + fileprivate static func read(from buf: Reader) throws -> {{ type_name }} { + return try {{ type_name }}( {%- for field in rec.fields() %} {{ field.name()|var_name }}: {{ field|read_fn }}(from: buf) {%- if !loop.last %}, {% endif %} @@ -43,7 +42,7 @@ fileprivate struct {{ rec|ffi_converter_name }}: FfiConverterRustBuffer { ) } - fileprivate static func write(_ value: {{ rec|type_name }}, into buf: Writer) { + fileprivate static func write(_ value: {{ type_name }}, into buf: Writer) { {%- for field in rec.fields() %} {{ field|write_fn }}(value.{{ field.name()|var_name }}, into: buf) {%- endfor %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/SequenceTemplate.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/SequenceTemplate.swift index 598a4c92a4d0..4cd104f5dd47 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/SequenceTemplate.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/SequenceTemplate.swift @@ -1,10 +1,7 @@ -{%- import "macros.swift" as swift -%} -{%- let inner_type = self.inner() %} -{%- let outer_type = self.outer() %} -fileprivate struct {{ outer_type|ffi_converter_name }}: FfiConverterRustBuffer { - typealias SwiftType = {{ outer_type|type_name }} +fileprivate struct {{ ffi_converter_name }}: FfiConverterRustBuffer { + typealias SwiftType = {{ type_name }} - static func write(_ value: {{ outer_type|type_name }}, into buf: Writer) { + static func write(_ value: {{ type_name }}, into buf: Writer) { let len = Int32(value.count) buf.writeInt(len) for item in value { @@ -12,9 +9,9 @@ fileprivate struct {{ outer_type|ffi_converter_name }}: FfiConverterRustBuffer { } } - static func read(from buf: Reader) throws -> {{ outer_type|type_name }} { + static func read(from buf: Reader) throws -> {{ type_name }} { let len: Int32 = try buf.readInt() - var seq = {{ outer_type|type_name }}() + var seq = {{ type_name }}() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { seq.append(try {{ inner_type|read_fn }}(from: buf)) diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/TopLevelFunctionTemplate.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/TopLevelFunctionTemplate.swift index 7385c6f8b503..5ce762d2a095 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/TopLevelFunctionTemplate.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/TopLevelFunctionTemplate.swift @@ -1,5 +1,3 @@ -{% import "macros.swift" as swift %} -{%- let func = self.inner() %} {%- match func.return_type() -%} {%- when Some with (return_type) %} @@ -9,7 +7,7 @@ public func {{ func.name()|fn_name }}({%- call swift::arg_list_decl(func) -%}) { ) } -{% when None -%} +{% when None %} public func {{ func.name()|fn_name }}({% call swift::arg_list_decl(func) %}) {% call swift::throws(func) %} { {% call swift::to_ffi_call(func) %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/Types.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/Types.swift new file mode 100644 index 000000000000..0940413b2c8c --- /dev/null +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/Types.swift @@ -0,0 +1,91 @@ +{%- import "macros.swift" as swift %} +{%- for type_ in ci.iter_types() %} +{%- let type_name = type_|type_name %} +{%- let ffi_converter_name = type_|ffi_converter_name %} +{%- let canonical_type_name = type_|canonical_name %} +{%- let contains_object_references = ci.item_contains_object_references(type_) %} + +{# + # Map `Type` instances to an include statement for that type. + # + # There is a companion match in `KotlinCodeOracle::create_code_type()` which performs a similar function for the + # Rust code. + # + # - When adding additional types here, make sure to also add a match arm to that function. + # - To keep things managable, let's try to limit ourselves to these 2 mega-matches + #} +{%- match type_ %} + +{%- when Type::Boolean %} +{%- include "BooleanHelper.swift" %} + +{%- when Type::String %} +{%- include "StringHelper.swift" %} + +{%- when Type::Int8 %} +{%- include "Int8Helper.swift" %} + +{%- when Type::Int16 %} +{%- include "Int16Helper.swift" %} + +{%- when Type::Int32 %} +{%- include "Int32Helper.swift" %} + +{%- when Type::Int64 %} +{%- include "Int64Helper.swift" %} + +{%- when Type::UInt8 %} +{%- include "UInt8Helper.swift" %} + +{%- when Type::UInt16 %} +{%- include "UInt16Helper.swift" %} + +{%- when Type::UInt32 %} +{%- include "UInt32Helper.swift" %} + +{%- when Type::UInt64 %} +{%- include "UInt64Helper.swift" %} + +{%- when Type::Float32 %} +{%- include "Float32Helper.swift" %} + +{%- when Type::Float64 %} +{%- include "Float64Helper.swift" %} + +{%- when Type::Timestamp %} +{%- include "TimestampHelper.swift" %} + +{%- when Type::Duration %} +{%- include "DurationHelper.swift" %} + +{%- when Type::CallbackInterface(name) %} +{%- include "CallbackInterfaceTemplate.swift" %} + +{%- when Type::Custom { name, builtin } %} +{%- include "CustomType.swift" %} + +{%- when Type::Enum(name) %} +{%- include "EnumTemplate.swift" %} + +{%- when Type::Error(name) %} +{%- include "ErrorTemplate.swift" %} + +{%- when Type::Object(name) %} +{%- include "ObjectTemplate.swift" %} + +{%- when Type::Record(name) %} +{%- include "RecordTemplate.swift" %} + +{%- when Type::Optional(inner_type) %} +{%- include "OptionalTemplate.swift" %} + +{%- when Type::Sequence(inner_type) %} +{%- include "SequenceTemplate.swift" %} + +{%- when Type::Map(key_type, value_type) %} +{%- include "MapTemplate.swift" %} + + +{%- else %} +{%- endmatch %} +{%- endfor %} diff --git a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/wrapper.swift b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/wrapper.swift index 8b734093a31c..ac0557912ee2 100644 --- a/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/wrapper.swift +++ b/third_party/rust/uniffi_bindgen/src/bindings/swift/templates/wrapper.swift @@ -1,5 +1,6 @@ // This file was autogenerated by some hot garbage in the `uniffi` crate. // Trust me, you don't want to mess with it! +{%- import "macros.swift" as swift %} import Foundation {%- for imported_class in self.imports() %} import {{ imported_class }} @@ -16,10 +17,11 @@ import {{ config.ffi_module_name() }} {% include "Helpers.swift" %} // Public interface members begin here. -{% for code in self.declaration_code() %} -{{ code }} +{{ type_helper_code }} + +{%- for func in ci.function_definitions() %} +{%- include "TopLevelFunctionTemplate.swift" %} {%- endfor %} -{% import "macros.swift" as swift %} /** * Top level initializers and tear down methods. @@ -31,13 +33,8 @@ public enum {{ config.module_name().borrow()|class_name }}Lifecycle { * Initialize the FFI and Rust library. This should be only called once per application. */ func initialize() { - {% let initialization_code = self.initialization_code() -%} - {% if !initialization_code.is_empty() %} - {% for code in self.initialization_code() -%} - {{ code }} - {% endfor -%} - {% else %} - // No initialization code needed - {% endif %} + {%- for initialization_fn in self.initialization_fns() %} + {{ initialization_fn }}() + {%- endfor %} } } diff --git a/third_party/rust/uniffi_bindgen/src/interface/attributes.rs b/third_party/rust/uniffi_bindgen/src/interface/attributes.rs index e1f2d7aa4590..49b885520c2e 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/attributes.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/attributes.rs @@ -14,8 +14,6 @@ //! all handled by a single abstraction. This might need to be refactored in future //! if we grow significantly more complicated attribute handling. -use std::convert::{TryFrom, TryInto}; - use anyhow::{bail, Result}; /// Represents an attribute parsed from UDL, like `[ByRef]` or `[Throws]`. @@ -112,7 +110,7 @@ where .map(Attribute::try_from) .collect::, _>>()?; - for attr in attrs.iter() { + for attr in &attrs { validator(attr)?; } diff --git a/third_party/rust/uniffi_bindgen/src/interface/callbacks.rs b/third_party/rust/uniffi_bindgen/src/interface/callbacks.rs index b0a64eff5760..62f8e4df4e97 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/callbacks.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/callbacks.rs @@ -39,7 +39,7 @@ use anyhow::{bail, Result}; use super::ffi::{FFIArgument, FFIFunction, FFIType}; use super::object::Method; -use super::types::{IterTypes, Type, TypeIterator}; +use super::types::{Type, TypeIterator}; use super::{APIConverter, ComponentInterface}; #[derive(Debug, Clone)] @@ -74,10 +74,6 @@ impl CallbackInterface { &self.ffi_init_callback } - pub fn iter_ffi_function_definitions(&self) -> Vec { - vec![self.ffi_init_callback.clone()] - } - pub(super) fn derive_ffi_funcs(&mut self, ci_prefix: &str) { self.ffi_init_callback.name = format!("ffi_{}_{}_init_callback", ci_prefix, self.name); self.ffi_init_callback.arguments = vec![FFIArgument { @@ -86,11 +82,9 @@ impl CallbackInterface { }]; self.ffi_init_callback.return_type = None; } -} -impl IterTypes for CallbackInterface { - fn iter_types(&self) -> TypeIterator<'_> { - Box::new(self.methods.iter().flat_map(IterTypes::iter_types)) + pub fn iter_types(&self) -> TypeIterator<'_> { + Box::new(self.methods.iter().flat_map(Method::iter_types)) } } @@ -120,7 +114,7 @@ impl APIConverter for weedle::CallbackInterfaceDefinition<'_> match member { weedle::interface::InterfaceMember::Operation(t) => { let mut method: Method = t.convert(ci)?; - method.object_name.push_str(object.name.as_str()); + method.object_name = object.name.clone(); object.methods.push(method); } _ => bail!( @@ -145,7 +139,7 @@ mod test { callback interface Testing {}; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_callback_interface_definitions().len(), 1); + assert_eq!(ci.callback_interface_definitions().len(), 1); assert_eq!( ci.get_callback_interface_definition("Testing") .unwrap() @@ -168,7 +162,7 @@ mod test { }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_callback_interface_definitions().len(), 2); + assert_eq!(ci.callback_interface_definitions().len(), 2); let callbacks_one = ci.get_callback_interface_definition("One").unwrap(); assert_eq!(callbacks_one.methods().len(), 1); diff --git a/third_party/rust/uniffi_bindgen/src/interface/enum_.rs b/third_party/rust/uniffi_bindgen/src/interface/enum_.rs index 6b119088c9e5..b01b228fb45a 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/enum_.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/enum_.rs @@ -79,7 +79,7 @@ use anyhow::{bail, Result}; use super::record::Field; -use super::types::{IterTypes, Type, TypeIterator}; +use super::types::{Type, TypeIterator}; use super::{APIConverter, ComponentInterface}; /// Represents an enum with named variants, each of which may have named @@ -113,11 +113,9 @@ impl Enum { pub fn is_flat(&self) -> bool { self.flat } -} -impl IterTypes for Enum { - fn iter_types(&self) -> TypeIterator<'_> { - Box::new(self.variants.iter().flat_map(IterTypes::iter_types)) + pub fn iter_types(&self) -> TypeIterator<'_> { + Box::new(self.variants.iter().flat_map(Variant::iter_types)) } } @@ -193,11 +191,9 @@ impl Variant { pub fn has_fields(&self) -> bool { !self.fields.is_empty() } -} -impl IterTypes for Variant { - fn iter_types(&self) -> TypeIterator<'_> { - Box::new(self.fields.iter().flat_map(IterTypes::iter_types)) + pub fn iter_types(&self) -> TypeIterator<'_> { + Box::new(self.fields.iter().flat_map(Field::iter_types)) } } @@ -284,7 +280,7 @@ mod test { enum Testing { "one", "two", "one" }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_enum_definitions().len(), 1); + assert_eq!(ci.enum_definitions().len(), 1); assert_eq!( ci.get_enum_definition("Testing").unwrap().variants().len(), 3 @@ -317,8 +313,8 @@ mod test { }; "##; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_enum_definitions().len(), 3); - assert_eq!(ci.iter_function_definitions().len(), 4); + assert_eq!(ci.enum_definitions().len(), 3); + assert_eq!(ci.function_definitions().len(), 4); // The "flat" enum with no associated data. let e = ci.get_enum_definition("TestEnum").unwrap(); diff --git a/third_party/rust/uniffi_bindgen/src/interface/error.rs b/third_party/rust/uniffi_bindgen/src/interface/error.rs index f4176a5585f2..7e9b571a165f 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/error.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/error.rs @@ -85,7 +85,7 @@ use anyhow::Result; use super::enum_::{Enum, Variant}; -use super::types::{IterTypes, Type, TypeIterator}; +use super::types::{Type, TypeIterator}; use super::{APIConverter, ComponentInterface}; /// Represents an Error that might be thrown by functions/methods in the component interface. @@ -129,10 +129,8 @@ impl Error { pub fn is_flat(&self) -> bool { self.enum_.is_flat() } -} -impl IterTypes for Error { - fn iter_types(&self) -> TypeIterator<'_> { + pub fn iter_types(&self) -> TypeIterator<'_> { self.wrapped_enum().iter_types() } } @@ -161,7 +159,7 @@ mod test { enum Testing { "one", "two", "three" }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_error_definitions().len(), 1); + assert_eq!(ci.error_definitions().len(), 1); let error = ci.get_error_definition("Testing").unwrap(); assert_eq!( error @@ -184,7 +182,7 @@ mod test { enum Testing { "one", "two", "one" }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_error_definitions().len(), 1); + assert_eq!(ci.error_definitions().len(), 1); assert_eq!( ci.get_error_definition("Testing").unwrap().variants().len(), 3 @@ -203,7 +201,7 @@ mod test { }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_error_definitions().len(), 1); + assert_eq!(ci.error_definitions().len(), 1); let error: &Error = ci.get_error_definition("Testing").unwrap(); assert_eq!( error diff --git a/third_party/rust/uniffi_bindgen/src/interface/ffi.rs b/third_party/rust/uniffi_bindgen/src/interface/ffi.rs index 5bf398ab1a8a..0ae98c9eab1a 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/ffi.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/ffi.rs @@ -34,7 +34,8 @@ pub enum FFIType { /// A `*const c_void` pointer to a rust-owned `Arc`. /// If you've got one of these, you must call the appropriate rust function to free it. /// The templates will generate a unique `free` function for each T. - RustArcPtr, + /// The inner string references the name of the `T` type. + RustArcPtr(String), /// A byte buffer allocated by rust, and owned by whoever currently holds it. /// If you've got one of these, you must either call the appropriate rust function to free it /// or pass it to someone that will. diff --git a/third_party/rust/uniffi_bindgen/src/interface/function.rs b/third_party/rust/uniffi_bindgen/src/interface/function.rs index 34b710724cec..7c34f4fcee24 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/function.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/function.rs @@ -39,7 +39,7 @@ use anyhow::{bail, Result}; use super::attributes::{ArgumentAttributes, FunctionAttributes}; use super::ffi::{FFIArgument, FFIFunction}; use super::literal::{convert_default_value, Literal}; -use super::types::{IterTypes, Type, TypeIterator}; +use super::types::{Type, TypeIterator}; use super::{APIConverter, ComponentInterface}; /// Represents a standalone function. @@ -89,26 +89,13 @@ impl Function { } pub fn derive_ffi_func(&mut self, ci_prefix: &str) -> Result<()> { - self.ffi_func.name.push_str(ci_prefix); - self.ffi_func.name.push('_'); - self.ffi_func.name.push_str(&self.name); + self.ffi_func.name = format!("{}_{}", ci_prefix, self.name); self.ffi_func.arguments = self.arguments.iter().map(|arg| arg.into()).collect(); self.ffi_func.return_type = self.return_type.as_ref().map(|rt| rt.into()); Ok(()) } } -impl IterTypes for Function { - fn iter_types(&self) -> TypeIterator<'_> { - Box::new( - self.arguments - .iter() - .flat_map(IterTypes::iter_types) - .chain(self.return_type.iter_types()), - ) - } -} - impl Hash for Function { fn hash(&self, state: &mut H) { // We don't include the FFIFunc in the hash calculation, because: @@ -165,19 +152,20 @@ impl Argument { pub fn name(&self) -> &str { &self.name } + pub fn type_(&self) -> Type { self.type_.clone() } + pub fn by_ref(&self) -> bool { self.by_ref } + pub fn default_value(&self) -> Option { self.default.clone() } -} -impl IterTypes for Argument { - fn iter_types(&self) -> TypeIterator<'_> { + pub fn iter_types(&self) -> TypeIterator<'_> { self.type_.iter_types() } } diff --git a/third_party/rust/uniffi_bindgen/src/interface/mod.rs b/third_party/rust/uniffi_bindgen/src/interface/mod.rs index 9c6e8113ba90..3f2dbfb599ce 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/mod.rs @@ -48,6 +48,7 @@ use std::{ collections::{hash_map::DefaultHasher, HashSet}, convert::TryFrom, hash::{Hash, Hasher}, + iter, str::FromStr, }; @@ -55,7 +56,7 @@ use anyhow::{bail, Result}; pub mod types; pub use types::Type; -use types::{IterTypes, TypeIterator, TypeUniverse}; +use types::{TypeIterator, TypeUniverse}; mod attributes; mod callbacks; @@ -100,7 +101,7 @@ pub struct ComponentInterface { errors: Vec, } -impl<'ci> ComponentInterface { +impl ComponentInterface { /// Parse a `ComponentInterface` from a string containing a WebIDL definition. pub fn from_webidl(idl: &str) -> Result { let mut ci = Self { @@ -140,9 +141,9 @@ impl<'ci> ComponentInterface { self.namespace.as_str() } - /// List the definitions for every Enum type in the interface. - pub fn iter_enum_definitions(&self) -> Vec { - self.enums.to_vec() + /// Get the definitions for every Enum type in the interface. + pub fn enum_definitions(&self) -> &[Enum] { + &self.enums } /// Get an Enum definition by name, or None if no such Enum is defined. @@ -151,9 +152,9 @@ impl<'ci> ComponentInterface { self.enums.iter().find(|e| e.name == name) } - /// List the definitions for every Record type in the interface. - pub fn iter_record_definitions(&self) -> Vec { - self.records.to_vec() + /// Get the definitions for every Record type in the interface. + pub fn record_definitions(&self) -> &[Record] { + &self.records } /// Get a Record definition by name, or None if no such Record is defined. @@ -162,9 +163,9 @@ impl<'ci> ComponentInterface { self.records.iter().find(|r| r.name == name) } - /// List the definitions for every Function in the interface. - pub fn iter_function_definitions(&self) -> Vec { - self.functions.to_vec() + /// Get the definitions for every Function in the interface. + pub fn function_definitions(&self) -> &[Function] { + &self.functions } /// Get a Function definition by name, or None if no such Function is defined. @@ -173,9 +174,9 @@ impl<'ci> ComponentInterface { self.functions.iter().find(|f| f.name == name) } - /// List the definitions for every Object type in the interface. - pub fn iter_object_definitions(&self) -> Vec { - self.objects.to_vec() + /// Get the definitions for every Object type in the interface. + pub fn object_definitions(&self) -> &[Object] { + &self.objects } /// Get an Object definition by name, or None if no such Object is defined. @@ -184,9 +185,9 @@ impl<'ci> ComponentInterface { self.objects.iter().find(|o| o.name == name) } - /// List the definitions for every Callback Interface type in the interface. - pub fn iter_callback_interface_definitions(&self) -> Vec { - self.callback_interfaces.to_vec() + /// Get the definitions for every Callback Interface type in the interface. + pub fn callback_interface_definitions(&self) -> &[CallbackInterface] { + &self.callback_interfaces } /// Get a Callback interface definition by name, or None if no such interface is defined. @@ -195,9 +196,9 @@ impl<'ci> ComponentInterface { self.callback_interfaces.iter().find(|o| o.name == name) } - /// List the definitions for every Error type in the interface. - pub fn iter_error_definitions(&self) -> Vec { - self.errors.to_vec() + /// Get the definitions for every Error type in the interface. + pub fn error_definitions(&self) -> &[Error] { + &self.errors } /// Get an Error definition by name, or None if no such Error is defined. @@ -207,30 +208,24 @@ impl<'ci> ComponentInterface { } /// Get details about all `Type::External` types - pub fn iter_external_types(&self) -> Vec<(String, String)> { - self.types - .iter_known_types() - .filter_map(|t| match t { - Type::External { name, crate_name } => Some((name, crate_name)), - _ => None, - }) - .collect() + pub fn iter_external_types(&self) -> impl Iterator { + self.types.iter_known_types().filter_map(|t| match t { + Type::External { name, crate_name } => Some((name, crate_name)), + _ => None, + }) } /// Get details about all `Type::Custom` types - pub fn iter_custom_types(&self) -> Vec<(String, Type)> { - self.types - .iter_known_types() - .filter_map(|t| match t { - Type::Custom { name, builtin } => Some((name, *builtin)), - _ => None, - }) - .collect() + pub fn iter_custom_types(&self) -> impl Iterator { + self.types.iter_known_types().filter_map(|t| match t { + Type::Custom { name, builtin } => Some((name, &**builtin)), + _ => None, + }) } /// Iterate over all known types in the interface. - pub fn iter_types(&self) -> Vec { - self.types.iter_known_types().collect() + pub fn iter_types(&self) -> impl Iterator { + self.types.iter_known_types() } /// Get a specific type @@ -240,13 +235,10 @@ impl<'ci> ComponentInterface { /// Iterate over all types contained in the given item. /// - /// This method uses `IterTypes::iter_types` to iterate over the types contained within the - /// given item, but additionally recurses into the definition of user-defined types like records - /// and enums to yield the types that *they* contain. - fn iter_types_in_item<'a, T: IterTypes>( - &'a self, - item: &'a T, - ) -> impl Iterator + 'a { + /// This method uses `iter_types` to iterate over the types contained within the given type, + /// but additionally recurses into the definition of user-defined types like records and enums + /// to yield the types that *they* contain. + fn iter_types_in_item<'a>(&'a self, item: &'a Type) -> impl Iterator + 'a { RecursiveTypeIterator::new(self, item) } @@ -254,13 +246,13 @@ impl<'ci> ComponentInterface { /// /// This is important to know in language bindings that cannot integrate object types /// tightly with the host GC, and hence need to perform manual destruction of objects. - pub fn item_contains_object_references(&self, item: &T) -> bool { + pub fn item_contains_object_references(&self, item: &Type) -> bool { self.iter_types_in_item(item) .any(|t| matches!(t, Type::Object(_))) } /// Check whether the given item contains any (possibly nested) unsigned types - pub fn item_contains_unsigned_types(&self, item: &T) -> bool { + pub fn item_contains_unsigned_types(&self, item: &Type) -> bool { self.iter_types_in_item(item) .any(|t| matches!(t, Type::UInt8 | Type::UInt16 | Type::UInt32 | Type::UInt64)) } @@ -402,10 +394,10 @@ impl<'ci> ComponentInterface { /// /// The set of FFI functions is derived automatically from the set of higher-level types /// along with the builtin FFI helper functions. - pub fn iter_ffi_function_definitions(&self) -> Vec { - let mut functions = self.iter_user_ffi_function_definitions(); - functions.append(&mut self.iter_rust_buffer_ffi_function_definitions()); - functions + pub fn iter_ffi_function_definitions(&self) -> impl Iterator + '_ { + self.iter_user_ffi_function_definitions() + .cloned() + .chain(self.iter_rust_buffer_ffi_function_definitions()) } /// List all FFI functions definitions for user-defined interfaces @@ -414,9 +406,8 @@ impl<'ci> ComponentInterface { /// - Top-level functions /// - Object methods /// - Callback interfaces - pub fn iter_user_ffi_function_definitions(&self) -> Vec { - vec![] - .into_iter() + pub fn iter_user_ffi_function_definitions(&self) -> impl Iterator + '_ { + iter::empty() .chain( self.objects .iter() @@ -425,20 +416,20 @@ impl<'ci> ComponentInterface { .chain( self.callback_interfaces .iter() - .flat_map(|cb| cb.iter_ffi_function_definitions()), + .map(|cb| cb.ffi_init_callback()), ) - .chain(self.functions.iter().map(|f| f.ffi_func.clone())) - .collect() + .chain(self.functions.iter().map(|f| &f.ffi_func)) } /// List all FFI functions definitions for RustBuffer functionality - pub fn iter_rust_buffer_ffi_function_definitions(&self) -> Vec { - vec![ + pub fn iter_rust_buffer_ffi_function_definitions(&self) -> impl Iterator { + [ self.ffi_rustbuffer_alloc(), self.ffi_rustbuffer_from_bytes(), self.ffi_rustbuffer_free(), self.ffi_rustbuffer_reserve(), ] + .into_iter() } // @@ -483,7 +474,7 @@ impl<'ci> ComponentInterface { if !self.namespace.is_empty() { bail!("duplicate namespace definition"); } - self.namespace.push_str(&defn.name); + self.namespace = defn.name; Ok(()) } @@ -541,8 +532,8 @@ impl<'ci> ComponentInterface { bail!("missing namespace definition"); } // To keep codegen tractable, enum variant names must not shadow type names. - for e in self.enums.iter() { - for variant in e.variants.iter() { + for e in &self.enums { + for variant in &e.variants { if self.types.get_type_definition(variant.name()).is_some() { bail!( "Enum variant names must not shadow type names: \"{}\"", @@ -598,22 +589,16 @@ impl Hash for ComponentInterface { } } -impl IterTypes for ComponentInterface { - fn iter_types(&self) -> TypeIterator<'_> { - self.types.iter_types() - } -} - -/// Stateful iterator for yielding all types contained in a given item. +/// Stateful iterator for yielding all types contained in a given type. /// /// This struct is the implementation of [`ComponentInterface::iter_types_in_item`] and should be /// considered an opaque implementation detail. It's a separate struct because I couldn't /// figure out a way to implement it using iterators and closures that would make the lifetimes /// work out correctly. /// -/// The idea here is that we want to yield all the types from `IterTypes::iter_types` on a -/// given item, and additionally we want to recurse into the definition of any user-provided -/// types like records, enums, etc so we can also yield the types contained therein. +/// The idea here is that we want to yield all the types from `iter_types` on a given type, and +/// additionally we want to recurse into the definition of any user-provided types like records, +/// enums, etc so we can also yield the types contained therein. /// /// To guard against infinite recursion, we maintain a list of previously-seen user-defined /// types, ensuring that we recurse into the definition of those types only once. To simplify @@ -633,7 +618,7 @@ struct RecursiveTypeIterator<'a> { impl<'a> RecursiveTypeIterator<'a> { /// Allocate a new `RecursiveTypeIterator` over the given item. - fn new(ci: &'a ComponentInterface, item: &'a T) -> RecursiveTypeIterator<'a> { + fn new(ci: &'a ComponentInterface, item: &'a Type) -> RecursiveTypeIterator<'a> { RecursiveTypeIterator { ci, // We begin by iterating over the types from the item itself. @@ -672,14 +657,14 @@ impl<'a> RecursiveTypeIterator<'a> { // to a non-existent type, we just leave the existing iterator in place and allow the recursive // call to `next()` to try again with the next pending type. let next_iter = match next_type { - Type::Record(nm) => self.ci.get_record_definition(nm).map(IterTypes::iter_types), - Type::Enum(nm) => self.ci.get_enum_definition(nm).map(IterTypes::iter_types), - Type::Error(nm) => self.ci.get_error_definition(nm).map(IterTypes::iter_types), - Type::Object(nm) => self.ci.get_object_definition(nm).map(IterTypes::iter_types), + Type::Record(nm) => self.ci.get_record_definition(nm).map(Record::iter_types), + Type::Enum(nm) => self.ci.get_enum_definition(nm).map(Enum::iter_types), + Type::Error(nm) => self.ci.get_error_definition(nm).map(Error::iter_types), + Type::Object(nm) => self.ci.get_object_definition(nm).map(Object::iter_types), Type::CallbackInterface(nm) => self .ci .get_callback_interface_definition(nm) - .map(IterTypes::iter_types), + .map(CallbackInterface::iter_types), _ => None, }; if let Some(next_iter) = next_iter { @@ -720,7 +705,7 @@ trait APIBuilder { /// by processing each in turn. impl APIBuilder for Vec { fn process(&self, ci: &mut ComponentInterface) -> Result<()> { - for item in self.iter() { + for item in self { item.process(ci)?; } Ok(()) diff --git a/third_party/rust/uniffi_bindgen/src/interface/namespace.rs b/third_party/rust/uniffi_bindgen/src/interface/namespace.rs index 111914913bb9..4a57d0ff41a6 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/namespace.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/namespace.rs @@ -54,7 +54,7 @@ //! # namespace example {}; //! # "##)?; //! assert_eq!(ci.namespace(), "example"); -//! assert_eq!(ci.iter_function_definitions().len(), 0); +//! assert_eq!(ci.function_definitions().len(), 0); //! # Ok::<(), anyhow::Error>(()) //! ``` //! @@ -111,7 +111,7 @@ mod test { "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); assert_eq!(ci.namespace(), "foobar"); - assert_eq!(ci.iter_function_definitions().len(), 2); + assert_eq!(ci.function_definitions().len(), 2); assert!(ci.get_function_definition("hello").is_some()); assert!(ci.get_function_definition("world").is_some()); assert!(ci.get_function_definition("potato").is_none()); diff --git a/third_party/rust/uniffi_bindgen/src/interface/object.rs b/third_party/rust/uniffi_bindgen/src/interface/object.rs index 3fb17c969fcb..aed9a6ce7d65 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/object.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/object.rs @@ -57,16 +57,16 @@ //! # Ok::<(), anyhow::Error>(()) //! ``` -use std::collections::HashSet; use std::convert::TryFrom; use std::hash::{Hash, Hasher}; +use std::{collections::HashSet, iter}; use anyhow::{bail, Result}; use super::attributes::{ConstructorAttributes, InterfaceAttributes, MethodAttributes}; use super::ffi::{FFIArgument, FFIFunction, FFIType}; use super::function::Argument; -use super::types::{IterTypes, Type, TypeIterator}; +use super::types::{Type, TypeIterator}; use super::{APIConverter, ComponentInterface}; /// An "object" is an opaque type that can be instantiated and passed around by reference, @@ -148,19 +148,17 @@ impl Object { self.uses_deprecated_threadsafe_attribute } - pub fn iter_ffi_function_definitions(&self) -> Vec { - vec![self.ffi_object_free().clone()] - .into_iter() - .chain(self.constructors.iter().map(|f| f.ffi_func.clone())) - .chain(self.methods.iter().map(|f| f.ffi_func.clone())) - .collect() + pub fn iter_ffi_function_definitions(&self) -> impl Iterator { + iter::once(&self.ffi_func_free) + .chain(self.constructors.iter().map(|f| &f.ffi_func)) + .chain(self.methods.iter().map(|f| &f.ffi_func)) } pub fn derive_ffi_funcs(&mut self, ci_prefix: &str) -> Result<()> { self.ffi_func_free.name = format!("ffi_{}_{}_object_free", ci_prefix, self.name); self.ffi_func_free.arguments = vec![FFIArgument { name: "ptr".to_string(), - type_: FFIType::RustArcPtr, + type_: FFIType::RustArcPtr(self.name().to_string()), }]; self.ffi_func_free.return_type = None; for cons in self.constructors.iter_mut() { @@ -171,15 +169,13 @@ impl Object { } Ok(()) } -} -impl IterTypes for Object { - fn iter_types(&self) -> TypeIterator<'_> { + pub fn iter_types(&self) -> TypeIterator<'_> { Box::new( self.methods .iter() - .map(IterTypes::iter_types) - .chain(self.constructors.iter().map(IterTypes::iter_types)) + .map(Method::iter_types) + .chain(self.constructors.iter().map(Constructor::iter_types)) .flatten(), ) } @@ -226,7 +222,7 @@ impl APIConverter for weedle::InterfaceDefinition<'_> { if !member_names.insert(method.name.clone()) { bail!("Duplicate interface member name: \"{}\"", method.name()) } - method.object_name.push_str(object.name.as_str()); + method.object_name = object.name.clone(); object.methods.push(method); } _ => bail!("no support for interface member type {:?} yet", member), @@ -279,20 +275,14 @@ impl Constructor { self.name == "new" } - fn derive_ffi_func(&mut self, ci_prefix: &str, obj_prefix: &str) { - self.ffi_func.name.push_str(ci_prefix); - self.ffi_func.name.push('_'); - self.ffi_func.name.push_str(obj_prefix); - self.ffi_func.name.push('_'); - self.ffi_func.name.push_str(&self.name); + fn derive_ffi_func(&mut self, ci_prefix: &str, obj_name: &str) { + self.ffi_func.name = format!("{}_{}_{}", ci_prefix, obj_name, self.name); self.ffi_func.arguments = self.arguments.iter().map(Into::into).collect(); - self.ffi_func.return_type = Some(FFIType::RustArcPtr); + self.ffi_func.return_type = Some(FFIType::RustArcPtr(obj_name.to_string())); } -} -impl IterTypes for Constructor { - fn iter_types(&self) -> TypeIterator<'_> { - Box::new(self.arguments.iter().flat_map(IterTypes::iter_types)) + pub fn iter_types(&self) -> TypeIterator<'_> { + Box::new(self.arguments.iter().flat_map(Argument::iter_types)) } } @@ -399,24 +389,18 @@ impl Method { } pub fn derive_ffi_func(&mut self, ci_prefix: &str, obj_prefix: &str) -> Result<()> { - self.ffi_func.name.push_str(ci_prefix); - self.ffi_func.name.push('_'); - self.ffi_func.name.push_str(obj_prefix); - self.ffi_func.name.push('_'); - self.ffi_func.name.push_str(&self.name); + self.ffi_func.name = format!("{}_{}_{}", ci_prefix, obj_prefix, self.name); self.ffi_func.arguments = self.full_arguments().iter().map(Into::into).collect(); self.ffi_func.return_type = self.return_type.as_ref().map(Into::into); Ok(()) } -} -impl IterTypes for Method { - fn iter_types(&self) -> TypeIterator<'_> { + pub fn iter_types(&self) -> TypeIterator<'_> { Box::new( self.arguments .iter() - .flat_map(IterTypes::iter_types) - .chain(self.return_type.iter_types()), + .flat_map(Argument::iter_types) + .chain(self.return_type.iter().flat_map(Type::iter_types)), ) } } @@ -481,28 +465,18 @@ mod test { }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_object_definitions().len(), 1); + assert_eq!(ci.object_definitions().len(), 1); ci.get_object_definition("Testing").unwrap(); - assert_eq!(ci.iter_types().len(), 6); - assert!(ci.iter_types().iter().any(|t| t.canonical_name() == "u16")); - assert!(ci.iter_types().iter().any(|t| t.canonical_name() == "u32")); + assert_eq!(ci.iter_types().count(), 6); + assert!(ci.iter_types().any(|t| t.canonical_name() == "u16")); + assert!(ci.iter_types().any(|t| t.canonical_name() == "u32")); + assert!(ci.iter_types().any(|t| t.canonical_name() == "Sequenceu32")); + assert!(ci.iter_types().any(|t| t.canonical_name() == "string")); assert!(ci .iter_types() - .iter() - .any(|t| t.canonical_name() == "Sequenceu32")); - assert!(ci - .iter_types() - .iter() - .any(|t| t.canonical_name() == "string")); - assert!(ci - .iter_types() - .iter() .any(|t| t.canonical_name() == "Optionalstring")); - assert!(ci - .iter_types() - .iter() - .any(|t| t.canonical_name() == "TypeTesting")); + assert!(ci.iter_types().any(|t| t.canonical_name() == "TypeTesting")); } #[test] @@ -516,7 +490,7 @@ mod test { }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_object_definitions().len(), 1); + assert_eq!(ci.object_definitions().len(), 1); let obj = ci.get_object_definition("Testing").unwrap(); assert!(obj.primary_constructor().is_some()); @@ -546,7 +520,7 @@ mod test { }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_object_definitions().len(), 1); + assert_eq!(ci.object_definitions().len(), 1); let obj = ci.get_object_definition("Testing").unwrap(); assert!(obj.primary_constructor().is_some()); diff --git a/third_party/rust/uniffi_bindgen/src/interface/record.rs b/third_party/rust/uniffi_bindgen/src/interface/record.rs index f555cd3cbf7c..719d93c3e33f 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/record.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/record.rs @@ -47,7 +47,7 @@ use anyhow::{bail, Result}; use super::literal::{convert_default_value, Literal}; -use super::types::{IterTypes, Type, TypeIterator}; +use super::types::{Type, TypeIterator}; use super::{APIConverter, ComponentInterface}; /// Represents a "data class" style object, for passing around complex values. @@ -75,11 +75,9 @@ impl Record { pub fn fields(&self) -> Vec<&Field> { self.fields.iter().collect() } -} -impl IterTypes for Record { - fn iter_types(&self) -> TypeIterator<'_> { - Box::new(self.fields.iter().flat_map(IterTypes::iter_types)) + pub fn iter_types(&self) -> TypeIterator<'_> { + Box::new(self.fields.iter().flat_map(Field::iter_types)) } } @@ -111,16 +109,16 @@ impl Field { pub fn name(&self) -> &str { &self.name } + pub fn type_(&self) -> Type { self.type_.clone() } + pub fn default_value(&self) -> Option { self.default.clone() } -} -impl IterTypes for Field { - fn iter_types(&self) -> TypeIterator<'_> { + pub fn iter_types(&self) -> TypeIterator<'_> { self.type_.iter_types() } } @@ -167,7 +165,7 @@ mod test { }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_record_definitions().len(), 3); + assert_eq!(ci.record_definitions().len(), 3); let record = ci.get_record_definition("Empty").unwrap(); assert_eq!(record.name(), "Empty"); @@ -214,25 +212,18 @@ mod test { }; "#; let ci = ComponentInterface::from_webidl(UDL).unwrap(); - assert_eq!(ci.iter_record_definitions().len(), 1); + assert_eq!(ci.record_definitions().len(), 1); let record = ci.get_record_definition("Testing").unwrap(); assert_eq!(record.fields().len(), 2); assert_eq!(record.fields()[0].name(), "maybe_name"); assert_eq!(record.fields()[1].name(), "value"); - assert_eq!(ci.iter_types().len(), 4); - assert!(ci.iter_types().iter().any(|t| t.canonical_name() == "u32")); + assert_eq!(ci.iter_types().count(), 4); + assert!(ci.iter_types().any(|t| t.canonical_name() == "u32")); + assert!(ci.iter_types().any(|t| t.canonical_name() == "string")); assert!(ci .iter_types() - .iter() - .any(|t| t.canonical_name() == "string")); - assert!(ci - .iter_types() - .iter() .any(|t| t.canonical_name() == "Optionalstring")); - assert!(ci - .iter_types() - .iter() - .any(|t| t.canonical_name() == "TypeTesting")); + assert!(ci.iter_types().any(|t| t.canonical_name() == "TypeTesting")); } } diff --git a/third_party/rust/uniffi_bindgen/src/interface/types/finder.rs b/third_party/rust/uniffi_bindgen/src/interface/types/finder.rs index 50b34b5f2925..c21f938d2f18 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/types/finder.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/types/finder.rs @@ -35,7 +35,7 @@ pub(in super::super) trait TypeFinder { impl TypeFinder for &[T] { fn add_type_definitions_to(&self, types: &mut TypeUniverse) -> Result<()> { - for item in self.iter() { + for item in *self { item.add_type_definitions_to(types)?; } Ok(()) diff --git a/third_party/rust/uniffi_bindgen/src/interface/types/mod.rs b/third_party/rust/uniffi_bindgen/src/interface/types/mod.rs index 8f591fcfcc62..f541d8e080ee 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/types/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/types/mod.rs @@ -21,7 +21,7 @@ //! about how these API-level types map into the lower-level types of the FFI layer as represented //! by the [`ffi::FFIType`](super::ffi::FFIType) enum, but that's a detail that is invisible to end users. -use std::{collections::hash_map::Entry, collections::BTreeSet, collections::HashMap}; +use std::{collections::hash_map::Entry, collections::BTreeSet, collections::HashMap, iter}; use anyhow::{bail, Result}; use heck::ToUpperCamelCase; @@ -124,6 +124,15 @@ impl Type { pub fn ffi_type(&self) -> FFIType { self.into() } + + pub fn iter_types(&self) -> TypeIterator<'_> { + let nested_types = match self { + Type::Optional(t) | Type::Sequence(t) => t.iter_types(), + Type::Map(k, v) => Box::new(k.iter_types().chain(v.iter_types())), + _ => Box::new(iter::empty()), + }; + Box::new(std::iter::once(self).chain(nested_types)) + } } /// When passing data across the FFI, each `Type` value will be lowered into a corresponding @@ -151,7 +160,7 @@ impl From<&Type> for FFIType { // We might add a separate type for borrowed strings in future. Type::String => FFIType::RustBuffer, // Objects are pointers to an Arc<> - Type::Object(_) => FFIType::RustArcPtr, + Type::Object(name) => FFIType::RustArcPtr(name.to_owned()), // Callback interfaces are passed as opaque integer handles. Type::CallbackInterface(_) => FFIType::UInt64, // Other types are serialized into a bytebuffer and deserialized on the other side. @@ -169,6 +178,13 @@ impl From<&Type> for FFIType { } } +// Needed for rust scaffolding askama template +impl From<&&Type> for FFIType { + fn from(ty: &&Type) -> Self { + (*ty).into() + } +} + /// The set of all possible types used in a particular component interface. /// /// Every component API uses a finite number of types, including primitive types, API-defined @@ -242,73 +258,17 @@ impl TypeUniverse { } /// Iterator over all the known types in this universe. - pub fn iter_known_types(&self) -> impl Iterator + '_ { - self.all_known_types.iter().cloned() + pub fn iter_known_types(&self) -> impl Iterator { + self.all_known_types.iter() } } /// An abstract type for an iterator over &Type references. /// /// Ideally we would not need to name this type explicitly, and could just -/// use an `impl Iterator` on any method that yields types. -/// Unfortunately existential types are not currently supported in trait method -/// signatures, so for now we hide the concrete type behind a box. +/// use an `impl Iterator` on any method that yields types. pub type TypeIterator<'a> = Box + 'a>; -/// A trait for objects that may contain references to types. -/// -/// Various objects in our interface will contain (possibly nested) references to types - -/// for example a `Record` struct will contain one or more `Field` structs which will each -/// have an associated type. This trait provides a uniform interface for inspecting the -/// types references by an object. - -pub trait IterTypes { - /// Iterate over all types contained within on object. - /// - /// This method iterates over the types contained with in object, making - /// no particular guarantees about ordering or handling of duplicates. - /// - /// The return type is a Box in order to hide the concrete implementation - /// details of the iterator. Ideally we would return `impl Iterator` here - /// but that's not currently supported for trait methods. - fn iter_types(&self) -> TypeIterator<'_>; -} - -impl IterTypes for &T { - fn iter_types(&self) -> TypeIterator<'_> { - (*self).iter_types() - } -} - -impl IterTypes for Box { - fn iter_types(&self) -> TypeIterator<'_> { - self.as_ref().iter_types() - } -} - -impl IterTypes for Option { - fn iter_types(&self) -> TypeIterator<'_> { - Box::new(self.iter().flat_map(IterTypes::iter_types)) - } -} - -impl IterTypes for Type { - fn iter_types(&self) -> TypeIterator<'_> { - let nested_types = match self { - Type::Optional(t) | Type::Sequence(t) => Some(t.iter_types()), - Type::Map(k, v) => Some(Box::new(k.iter_types().chain(v.iter_types())) as _), - _ => None, - }; - Box::new(std::iter::once(self).chain(nested_types.into_iter().flatten())) - } -} - -impl IterTypes for TypeUniverse { - fn iter_types(&self) -> TypeIterator<'_> { - Box::new(self.all_known_types.iter()) - } -} - #[cfg(test)] mod test_type { use super::*; diff --git a/third_party/rust/uniffi_bindgen/src/interface/types/resolver.rs b/third_party/rust/uniffi_bindgen/src/interface/types/resolver.rs index c4f4b756f84e..fc8476ab1c49 100644 --- a/third_party/rust/uniffi_bindgen/src/interface/types/resolver.rs +++ b/third_party/rust/uniffi_bindgen/src/interface/types/resolver.rs @@ -333,12 +333,12 @@ mod test { types.add_type_definition("TestBoolean", Type::Boolean)?; assert_eq!(types.iter_known_types().count(), 6); let mut iter = types.iter_known_types(); - assert_eq!(Some(Type::UInt8), iter.next()); - assert_eq!(Some(Type::Int8), iter.next()); - assert_eq!(Some(Type::Int64), iter.next()); - assert_eq!(Some(Type::Boolean), iter.next()); - assert_eq!(Some(Type::Record("TestRecord".into())), iter.next()); - assert_eq!(Some(Type::Record("TestRecord2".into())), iter.next()); + assert_eq!(Some(&Type::UInt8), iter.next()); + assert_eq!(Some(&Type::Int8), iter.next()); + assert_eq!(Some(&Type::Int64), iter.next()); + assert_eq!(Some(&Type::Boolean), iter.next()); + assert_eq!(Some(&Type::Record("TestRecord".into())), iter.next()); + assert_eq!(Some(&Type::Record("TestRecord2".into())), iter.next()); Ok(()) } } diff --git a/third_party/rust/uniffi_bindgen/src/lib.rs b/third_party/rust/uniffi_bindgen/src/lib.rs index 0d1f80c50884..20cec1d81698 100644 --- a/third_party/rust/uniffi_bindgen/src/lib.rs +++ b/third_party/rust/uniffi_bindgen/src/lib.rs @@ -94,20 +94,13 @@ const BINDGEN_VERSION: &str = env!("CARGO_PKG_VERSION"); -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{bail, Context, Result}; +use camino::{Utf8Path, Utf8PathBuf}; use clap::{Parser, Subcommand}; +use fs_err::{self as fs, File}; use serde::{Deserialize, Serialize}; -use std::convert::TryInto; use std::io::prelude::*; -use std::{ - collections::HashMap, - env, - ffi::OsString, - fs::File, - path::{Path, PathBuf}, - process::Command, - str::FromStr, -}; +use std::{collections::HashMap, env, process::Command, str::FromStr}; pub mod backend; pub mod bindings; @@ -135,12 +128,12 @@ pub trait BindingGeneratorConfig: for<'de> Deserialize<'de> { fn load_bindings_config( ci: &ComponentInterface, - udl_file: &Path, - config_file_override: Option<&Path>, + crate_root: &Utf8Path, + config_file_override: Option<&Utf8Path>, ) -> Result { // Load the config from the TOML value, falling back to an empty map if it doesn't exist let mut config_map: toml::value::Table = - match load_bindings_config_toml::(udl_file, config_file_override)? { + match load_bindings_config_toml::(crate_root, config_file_override)? { Some(value) => value .try_into() .context("Bindings config must be a TOML table")?, @@ -148,7 +141,7 @@ fn load_bindings_config( }; // Update it with the defaults from the component interface - for (key, value) in BC::get_config_defaults(ci).into_iter() { + for (key, value) in BC::get_config_defaults(ci) { config_map.entry(key).or_insert(value); } @@ -192,22 +185,22 @@ impl<'de> Deserialize<'de> for EmptyBindingGeneratorConfig { // If there is an error parsing the file then Err will be returned. If the file is missing or the // entry for the bindings is missing, then Ok(None) will be returned. fn load_bindings_config_toml( - udl_file: &Path, - config_file_override: Option<&Path>, + crate_root: &Utf8Path, + config_file_override: Option<&Utf8Path>, ) -> Result> { let config_path = match config_file_override { Some(cfg) => cfg.to_owned(), - None => guess_crate_root(udl_file)?.join("uniffi.toml"), + None => crate_root.join("uniffi.toml"), }; if !config_path.exists() { return Ok(None); } - let contents = slurp_file(&config_path) - .with_context(|| format!("Failed to read config file from {:?}", config_path))?; + let contents = fs::read_to_string(&config_path) + .with_context(|| format!("Failed to read config file from {}", config_path))?; let full_config = toml::Value::from_str(&contents) - .with_context(|| format!("Failed to parse config file {:?}", config_path))?; + .with_context(|| format!("Failed to parse config file {}", config_path))?; Ok(full_config .get("bindings") @@ -233,7 +226,7 @@ pub trait BindingGenerator: Sized { &self, ci: ComponentInterface, config: Self::Config, - out_dir: &Path, + out_dir: &Utf8Path, ) -> anyhow::Result<()>; } @@ -253,47 +246,39 @@ pub trait BindingGenerator: Sized { /// - `out_dir_override`: The path to write the bindings to. If [`None`], it will be the path to the parent directory of the `udl_file` pub fn generate_external_bindings( binding_generator: impl BindingGenerator, - udl_file: impl AsRef, - config_file_override: Option>, - out_dir_override: Option>, + udl_file: impl AsRef, + config_file_override: Option>, + out_dir_override: Option>, ) -> Result<()> { let out_dir_override = out_dir_override.as_ref().map(|p| p.as_ref()); let config_file_override = config_file_override.as_ref().map(|p| p.as_ref()); + + let crate_root = guess_crate_root(udl_file.as_ref())?; let out_dir = get_out_dir(udl_file.as_ref(), out_dir_override)?; let component = parse_udl(udl_file.as_ref()).context("Error parsing UDL")?; - let bindings_config = - load_bindings_config(&component, udl_file.as_ref(), config_file_override)?; - binding_generator.write_bindings(component, bindings_config, out_dir.as_path()) + let bindings_config = load_bindings_config(&component, crate_root, config_file_override)?; + binding_generator.write_bindings(component, bindings_config, &out_dir) } // Generate the infrastructural Rust code for implementing the UDL interface, // such as the `extern "C"` function definitions and record data types. -pub fn generate_component_scaffolding>( - udl_file: P, - config_file_override: Option

, - out_dir_override: Option

, +pub fn generate_component_scaffolding( + udl_file: &Utf8Path, + config_file_override: Option<&Utf8Path>, + out_dir_override: Option<&Utf8Path>, format_code: bool, ) -> Result<()> { - let config_file_override = config_file_override.as_ref().map(|p| p.as_ref()); - let out_dir_override = out_dir_override.as_ref().map(|p| p.as_ref()); - let udl_file = udl_file.as_ref(); let component = parse_udl(udl_file)?; let _config = get_config( &component, guess_crate_root(udl_file)?, config_file_override, ); - let mut filename = Path::new(&udl_file) - .file_stem() - .ok_or_else(|| anyhow!("not a file"))? - .to_os_string(); - filename.push(".uniffi.rs"); - let mut out_dir = get_out_dir(udl_file, out_dir_override)?; - out_dir.push(filename); - let mut f = - File::create(&out_dir).map_err(|e| anyhow!("Failed to create output file: {:?}", e))?; - write!(f, "{}", RustScaffolding::new(&component)) - .map_err(|e| anyhow!("Failed to write output file: {:?}", e))?; + let file_stem = udl_file.file_stem().context("not a file")?; + let filename = format!("{}.uniffi.rs", file_stem); + let out_dir = get_out_dir(udl_file, out_dir_override)?.join(filename); + let mut f = File::create(&out_dir)?; + write!(f, "{}", RustScaffolding::new(&component)).context("Failed to write output file")?; if format_code { Command::new("rustfmt").arg(&out_dir).status()?; } @@ -302,17 +287,13 @@ pub fn generate_component_scaffolding>( // Generate the bindings in the target languages that call the scaffolding // Rust code. -pub fn generate_bindings>( - udl_file: P, - config_file_override: Option

, +pub fn generate_bindings( + udl_file: &Utf8Path, + config_file_override: Option<&Utf8Path>, target_languages: Vec<&str>, - out_dir_override: Option

, + out_dir_override: Option<&Utf8Path>, try_format_code: bool, ) -> Result<()> { - let out_dir_override = out_dir_override.as_ref().map(|p| p.as_ref()); - let config_file_override = config_file_override.as_ref().map(|p| p.as_ref()); - let udl_file = udl_file.as_ref(); - let component = parse_udl(udl_file)?; let config = get_config( &component, @@ -334,11 +315,11 @@ pub fn generate_bindings>( // Run tests against the foreign language bindings (generated and compiled at the same time). // Note that the cdylib we're testing against must be built already. -pub fn run_tests>( - cdylib_dir: P, - udl_files: &[&str], - test_scripts: Vec<&str>, - config_file_override: Option

, +pub fn run_tests( + cdylib_dir: impl AsRef, + udl_files: &[impl AsRef], + test_scripts: &[impl AsRef], + config_file_override: Option<&Utf8Path>, ) -> Result<()> { // XXX - this is just for tests, so one config_file_override for all .udl files doesn't really // make sense, so we don't let tests do this. @@ -347,15 +328,15 @@ pub fn run_tests>( assert!(udl_files.len() == 1 || config_file_override.is_none()); let cdylib_dir = cdylib_dir.as_ref(); - let config_file_override = config_file_override.as_ref().map(|p| p.as_ref()); // Group the test scripts by language first. - let mut language_tests: HashMap> = HashMap::new(); + let mut language_tests: HashMap> = HashMap::new(); for test_script in test_scripts { - let lang: TargetLanguage = PathBuf::from(test_script) + let test_script = test_script.as_ref(); + let lang: TargetLanguage = test_script .extension() - .ok_or_else(|| anyhow!("File has no extension!"))? + .context("File has no extension!")? .try_into()?; language_tests .entry(lang) @@ -365,11 +346,12 @@ pub fn run_tests>( for (lang, test_scripts) in language_tests { for udl_file in udl_files { - let crate_root = guess_crate_root(Path::new(udl_file))?; - let component = parse_udl(Path::new(udl_file))?; + let udl_file = udl_file.as_ref(); + let crate_root = guess_crate_root(udl_file)?; + let component = parse_udl(udl_file)?; let config = get_config(&component, crate_root, config_file_override)?; - bindings::write_bindings(&config.bindings, &component, &cdylib_dir, lang, true)?; - bindings::compile_bindings(&config.bindings, &component, &cdylib_dir, lang)?; + bindings::write_bindings(&config.bindings, &component, cdylib_dir, lang, true)?; + bindings::compile_bindings(&config.bindings, &component, cdylib_dir, lang)?; } for test_script in test_scripts { bindings::run_script(cdylib_dir, &test_script, lang)?; @@ -383,12 +365,12 @@ pub fn run_tests>( /// For now, we assume that the UDL file is in `./src/something.udl` relative /// to the crate root. We might consider something more sophisticated in /// future. -fn guess_crate_root(udl_file: &Path) -> Result<&Path> { +fn guess_crate_root(udl_file: &Utf8Path) -> Result<&Utf8Path> { let path_guess = udl_file .parent() - .ok_or_else(|| anyhow!("UDL file has no parent folder!"))? + .context("UDL file has no parent folder!")? .parent() - .ok_or_else(|| anyhow!("UDL file has no grand-parent folder!"))?; + .context("UDL file has no grand-parent folder!")?; if !path_guess.join("Cargo.toml").is_file() { bail!("UDL file does not appear to be inside a crate") } @@ -397,55 +379,47 @@ fn guess_crate_root(udl_file: &Path) -> Result<&Path> { fn get_config( component: &ComponentInterface, - crate_root: &Path, - config_file_override: Option<&Path>, + crate_root: &Utf8Path, + config_file_override: Option<&Utf8Path>, ) -> Result { let default_config: Config = component.into(); - let config_file: Option = match config_file_override { - Some(cfg) => Some(PathBuf::from(cfg)), - None => crate_root.join("uniffi.toml").canonicalize().ok(), + let config_file = match config_file_override { + Some(cfg) => Some(cfg.to_owned()), + None => crate_root.join("uniffi.toml").canonicalize_utf8().ok(), }; match config_file { Some(path) => { - let contents = slurp_file(&path) - .with_context(|| format!("Failed to read config file from {:?}", &path))?; + let contents = fs::read_to_string(&path) + .with_context(|| format!("Failed to read config file from {}", &path))?; let loaded_config: Config = toml::de::from_str(&contents) - .with_context(|| format!("Failed to generate config from file {:?}", &path))?; + .with_context(|| format!("Failed to generate config from file {}", &path))?; Ok(loaded_config.merge_with(&default_config)) } None => Ok(default_config), } } -fn get_out_dir(udl_file: &Path, out_dir_override: Option<&Path>) -> Result { +fn get_out_dir(udl_file: &Utf8Path, out_dir_override: Option<&Utf8Path>) -> Result { Ok(match out_dir_override { Some(s) => { // Create the directory if it doesn't exist yet. - std::fs::create_dir_all(&s)?; - s.canonicalize() - .map_err(|e| anyhow!("Unable to find out-dir: {:?}", e))? + fs::create_dir_all(&s)?; + s.canonicalize_utf8().context("Unable to find out-dir")? } None => udl_file .parent() - .ok_or_else(|| anyhow!("File has no parent directory"))? + .context("File has no parent directory")? .to_owned(), }) } -fn parse_udl(udl_file: &Path) -> Result { - let udl = - slurp_file(udl_file).map_err(|_| anyhow!("Failed to read UDL from {:?}", &udl_file))?; +fn parse_udl(udl_file: &Utf8Path) -> Result { + let udl = fs::read_to_string(udl_file) + .with_context(|| format!("Failed to read UDL from {}", &udl_file))?; udl.parse::() - .map_err(|e| anyhow!("Failed to parse UDL: {}", e)) -} - -fn slurp_file(file_name: &Path) -> Result { - let mut contents = String::new(); - let mut f = File::open(file_name)?; - f.read_to_string(&mut contents)?; - Ok(contents) + .context("Failed to parse UDL") } #[derive(Debug, Clone, Default, Serialize, Deserialize)] @@ -495,11 +469,12 @@ impl MergeWith for HashMap { } } -// structs to help our cmdline parsing. +// structs to help our cmdline parsing. Note that docstrings below form part +// of the "help" output. +/// Scaffolding and bindings generator for Rust #[derive(Parser)] #[clap(name = "uniffi-bindgen")] #[clap(version = clap::crate_version!())] -#[clap(about = "Scaffolding and bindings generator for Rust")] #[clap(propagate_version = true)] struct Cli { #[clap(subcommand)] @@ -508,78 +483,60 @@ struct Cli { #[derive(Subcommand)] enum Commands { - #[clap(name = "generate", about = "Generate foreign language bindings")] + /// Generate foreign language bindings Generate { + /// Foreign language(s) for which to build bindings. #[clap(long, short, possible_values = &["kotlin", "python", "swift", "ruby"])] - #[clap(help = "Foreign language(s) for which to build bindings.")] language: Vec, - #[clap( - long, - short, - help = "Directory in which to write generated files. Default is same folder as .udl file." - )] - out_dir: Option, + /// Directory in which to write generated files. Default is same folder as .udl file. + #[clap(long, short)] + out_dir: Option, - #[clap(long, short, help = "Do not try to format the generated bindings.")] + /// Do not try to format the generated bindings. + #[clap(long, short)] no_format: bool, - #[clap( - long, - short, - help = "Path to the optional uniffi config file. If not provided, uniffi-bindgen will try to guess it from the UDL's file location." - )] - config: Option, + /// Path to the optional uniffi config file. If not provided, uniffi-bindgen will try to guess it from the UDL's file location. + #[clap(long, short)] + config: Option, - #[clap(help = "Path to the UDL file.")] - udl_file: OsString, + /// Path to the UDL file. + udl_file: Utf8PathBuf, }, - #[clap(name = "scaffolding", about = "Generate Rust scaffolding code")] + /// Generate Rust scaffolding code Scaffolding { - #[clap( - long, - short, - help = "Directory in which to write generated files. Default is same folder as .udl file." - )] - out_dir: Option, + /// Directory in which to write generated files. Default is same folder as .udl file. + #[clap(long, short)] + out_dir: Option, - #[clap( - long, - short, - help = "Path to the optional uniffi config file. If not provided, uniffi-bindgen will try to guess it from the UDL's file location." - )] - config: Option, + /// Path to the optional uniffi config file. If not provided, uniffi-bindgen will try to guess it from the UDL's file location. + #[clap(long, short)] + config: Option, - #[clap(long, short, help = "Do not try to format the generated bindings.")] + /// Do not try to format the generated bindings. + #[clap(long, short)] no_format: bool, - #[clap(help = "Path to the UDL file.")] - udl_file: OsString, + /// Path to the UDL file. + udl_file: Utf8PathBuf, }, - #[clap( - name = "test", - about = "Run test scripts against foreign language bindings." - )] + /// Run test scripts against foreign language bindings. Test { - #[clap( - help = "Path to the directory containing the cdylib the scripts will be testing against." - )] - cdylib_dir: OsString, + /// Path to the directory containing the cdylib the scripts will be testing against. + cdylib_dir: Utf8PathBuf, - #[clap(help = "Path to the UDL file.")] - udl_file: OsString, + /// Path to the UDL file. + udl_file: Utf8PathBuf, - #[clap(help = "Foreign language(s) test scripts to run.")] - test_scripts: Vec, + /// Foreign language(s) test scripts to run. + test_scripts: Vec, - #[clap( - long, - short, - help = "Path to the optional uniffi config file. If not provided, uniffi-bindgen will try to guess it from the UDL's file location." - )] - config: Option, + /// Path to the optional uniffi config file. If not provided, uniffi-bindgen will try to guess it from the UDL's file location. + #[clap(long, short)] + config: Option, }, } @@ -594,9 +551,9 @@ pub fn run_main() -> Result<()> { udl_file, } => crate::generate_bindings( udl_file, - config.as_ref(), + config.as_deref(), language.iter().map(String::as_str).collect(), - out_dir.as_ref(), + out_dir.as_deref(), !no_format, ), Commands::Scaffolding { @@ -606,8 +563,8 @@ pub fn run_main() -> Result<()> { udl_file, } => crate::generate_component_scaffolding( udl_file, - config.as_ref(), - out_dir.as_ref(), + config.as_deref(), + out_dir.as_deref(), !no_format, ), Commands::Test { @@ -615,16 +572,22 @@ pub fn run_main() -> Result<()> { udl_file, test_scripts, config, - } => crate::run_tests( - cdylib_dir, - &[&udl_file.to_string_lossy()], // XXX - kinda defeats the purpose of OsString? - test_scripts.iter().map(String::as_str).collect(), - config.as_ref(), - ), + } => crate::run_tests(cdylib_dir, &[udl_file], test_scripts, config.as_deref()), }?; Ok(()) } +// FIXME(HACK): +// Include the askama config file into the build. +// That way cargo tracks the file and other tools relying on file tracking see it as well. +// See https://bugzilla.mozilla.org/show_bug.cgi?id=1774585 +// In the future askama should handle that itself by using the `track_path::path` API, +// see https://github.com/rust-lang/rust/pull/84029 +#[allow(dead_code)] +mod __unused { + const _: &[u8] = include_bytes!("../askama.toml"); +} + #[cfg(test)] mod test { use super::*; @@ -632,7 +595,7 @@ mod test { #[test] fn test_guessing_of_crate_root_directory_from_udl_file() { // When running this test, this will be the ./uniffi_bindgen directory. - let this_crate_root = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); + let this_crate_root = Utf8PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); let example_crate_root = this_crate_root .parent() diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/mod.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/mod.rs index d5e23d781e0d..969931b9a6a3 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/mod.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/mod.rs @@ -42,17 +42,17 @@ mod filters { Type::String => "String".into(), Type::Timestamp => "std::time::SystemTime".into(), Type::Duration => "std::time::Duration".into(), - Type::Enum(name) | Type::Record(name) | Type::Error(name) => name.clone(), - Type::Object(name) => format!("std::sync::Arc<{}>", name), - Type::CallbackInterface(name) => format!("Box", name), + Type::Enum(name) | Type::Record(name) | Type::Error(name) => format!("r#{}", name), + Type::Object(name) => format!("std::sync::Arc", name), + Type::CallbackInterface(name) => format!("Box", name), Type::Optional(t) => format!("std::option::Option<{}>", type_rs(t)?), Type::Sequence(t) => format!("std::vec::Vec<{}>", type_rs(t)?), Type::Map(k, v) => format!( - "std::collections::HashMap<{}, {}>", + "std::collections::HashMap", type_rs(k)?, type_rs(v)? ), - Type::Custom { name, .. } => name.clone(), + Type::Custom { name, .. } => format!("r#{}", name), Type::External { .. } => panic!("External types coming to a uniffi near you soon!"), }) } @@ -69,7 +69,7 @@ mod filters { FFIType::UInt64 => "u64".into(), FFIType::Float32 => "f32".into(), FFIType::Float64 => "f64".into(), - FFIType::RustArcPtr => "*const std::os::raw::c_void".into(), + FFIType::RustArcPtr(_) => "*const std::os::raw::c_void".into(), FFIType::RustBuffer => "uniffi::RustBuffer".into(), FFIType::ForeignBytes => "uniffi::ForeignBytes".into(), FFIType::ForeignCallback => "uniffi::ForeignCallback".into(), @@ -87,7 +87,7 @@ mod filters { Type::Timestamp => "std::time::SystemTime".into(), Type::Duration => "std::time::Duration".into(), // Object is handled by Arc - Type::Object(name) => format!("std::sync::Arc<{}>", name), + Type::Object(name) => format!("std::sync::Arc", name), // Other user-defined types are handled by a unit-struct that we generate. The // FfiConverter implementation for this can be found in one of the scaffolding template code. // @@ -100,10 +100,12 @@ mod filters { } // Wrapper types are implemented by generics that wrap the FfiConverter implementation of the // inner type. - Type::Optional(inner) => format!("std::option::Option<{}>", ffi_converter_name(inner)?), - Type::Sequence(inner) => format!("std::vec::Vec<{}>", ffi_converter_name(inner)?), + Type::Optional(inner) => { + format!("std::option::Option", ffi_converter_name(inner)?) + } + Type::Sequence(inner) => format!("std::vec::Vec", ffi_converter_name(inner)?), Type::Map(k, v) => format!( - "std::collections::HashMap<{}, {}>", + "std::collections::HashMap", ffi_converter_name(k)?, ffi_converter_name(v)? ), diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/CallbackInterfaceTemplate.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/CallbackInterfaceTemplate.rs index dd9db829153d..5f1f4f2aa628 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/CallbackInterfaceTemplate.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/CallbackInterfaceTemplate.rs @@ -41,11 +41,11 @@ impl Drop for {{ trait_impl }} { uniffi::deps::static_assertions::assert_impl_all!({{ trait_impl }}: Send); -impl {{ trait_name }} for {{ trait_impl }} { +impl r#{{ trait_name }} for {{ trait_impl }} { {%- for meth in cbi.methods() %} {#- Method declaration #} - fn {{ meth.name() -}} + fn r#{{ meth.name() -}} ({% call rs::arg_list_decl_with_prefix("&self", meth) %}) {%- match meth.return_type() %} {%- when Some with (return_type) %} -> {{ return_type.borrow()|type_rs }} @@ -61,7 +61,7 @@ impl {{ trait_name }} for {{ trait_impl }} { let mut args_buf = Vec::new(); {% endif -%} {%- for arg in meth.arguments() %} - {{ arg.type_().borrow()|ffi_converter }}::write({{ arg.name() }}, &mut args_buf); + {{ arg.type_().borrow()|ffi_converter }}::write(r#{{ arg.name() }}, &mut args_buf); {%- endfor -%} let args_rbuf = uniffi::RustBuffer::from_vec(args_buf); @@ -99,7 +99,7 @@ impl {{ trait_name }} for {{ trait_impl }} { unsafe impl uniffi::FfiConverter for {{ trait_impl }} { // This RustType allows for rust code that inputs this type as a Box param - type RustType = Box; + type RustType = Box; type FfiType = u64; // Lower and write are tricky to implement because we have a dyn trait as our type. There's diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/EnumTemplate.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/EnumTemplate.rs index c0a459d54f3f..0d83a99b900d 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/EnumTemplate.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/EnumTemplate.rs @@ -12,30 +12,30 @@ pub struct {{ e.type_().borrow()|ffi_converter_name }}; #[doc(hidden)] impl uniffi::RustBufferFfiConverter for {{ e.type_().borrow()|ffi_converter_name }} { - type RustType = {{ e.name() }}; + type RustType = r#{{ e.name() }}; fn write(obj: Self::RustType, buf: &mut std::vec::Vec) { use uniffi::deps::bytes::BufMut; match obj { {%- for variant in e.variants() %} - {{ e.name() }}::{{ variant.name() }} { {% for field in variant.fields() %}{{ field.name() }}, {%- endfor %} } => { + r#{{ e.name() }}::r#{{ variant.name() }} { {% for field in variant.fields() %}r#{{ field.name() }}, {%- endfor %} } => { buf.put_i32({{ loop.index }}); {% for field in variant.fields() -%} - {{ field.type_().borrow()|ffi_converter }}::write({{ field.name() }}, buf); + {{ field.type_().borrow()|ffi_converter }}::write(r#{{ field.name() }}, buf); {%- endfor %} }, {%- endfor %} }; } - fn try_read(buf: &mut &[u8]) -> uniffi::deps::anyhow::Result<{{ e.name() }}> { + fn try_read(buf: &mut &[u8]) -> uniffi::deps::anyhow::Result { use uniffi::deps::bytes::Buf; uniffi::check_remaining(buf, 4)?; Ok(match buf.get_i32() { {%- for variant in e.variants() %} - {{ loop.index }} => {{ e.name() }}::{{ variant.name() }}{% if variant.has_fields() %} { + {{ loop.index }} => r#{{ e.name() }}::r#{{ variant.name() }}{% if variant.has_fields() %} { {% for field in variant.fields() %} - {{ field.name() }}: {{ field.type_().borrow()|ffi_converter }}::try_read(buf)?, + r#{{ field.name() }}: {{ field.type_().borrow()|ffi_converter }}::try_read(buf)?, {%- endfor %} }{% endif %}, {%- endfor %} diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ErrorTemplate.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ErrorTemplate.rs index d68f783cb328..c4144c7ac60e 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ErrorTemplate.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ErrorTemplate.rs @@ -12,7 +12,7 @@ pub struct {{ e.type_().borrow()|ffi_converter_name }}; #[doc(hidden)] impl uniffi::RustBufferFfiConverter for {{ e.type_().borrow()|ffi_converter_name }} { - type RustType = {{ e.name() }}; + type RustType = r#{{ e.name() }}; {% if e.is_flat() %} @@ -20,12 +20,12 @@ impl uniffi::RustBufferFfiConverter for {{ e.type_().borrow()|ffi_converter_name // as the error message in the foreign language. - fn write(obj: {{ e.name() }}, buf: &mut std::vec::Vec) { + fn write(obj: r#{{ e.name() }}, buf: &mut std::vec::Vec) { use uniffi::deps::bytes::BufMut; let msg = obj.to_string(); match obj { {%- for variant in e.variants() %} - {{ e.name() }}::{{ variant.name() }}{..} => { + r#{{ e.name() }}::r#{{ variant.name() }}{..} => { buf.put_i32({{ loop.index }}); ::write(msg, buf); }, @@ -33,7 +33,7 @@ impl uniffi::RustBufferFfiConverter for {{ e.type_().borrow()|ffi_converter_name }; } - fn try_read(_buf: &mut &[u8]) -> uniffi::deps::anyhow::Result<{{ e.name() }}> { + fn try_read(_buf: &mut &[u8]) -> uniffi::deps::anyhow::Result { // It's not currently possible to send errors from the foreign language *into* Rust. panic!("try_read not supported for flat errors"); } @@ -47,30 +47,30 @@ impl uniffi::RustBufferFfiConverter for {{ e.type_().borrow()|ffi_converter_name // the Rust enum has fields and they're just not listed. In that case we use the `Variant{..}` // syntax to match the variant while ignoring its fields. - fn write(obj: {{ e.name() }}, buf: &mut std::vec::Vec) { + fn write(obj: r#{{ e.name() }}, buf: &mut std::vec::Vec) { use uniffi::deps::bytes::BufMut; match obj { {%- for variant in e.variants() %} - {{ e.name() }}::{{ variant.name() }}{% if variant.has_fields() %} { {% for field in variant.fields() %}{{ field.name() }}, {%- endfor %} }{% else %}{..}{% endif %} => { + r#{{ e.name() }}::r#{{ variant.name() }}{% if variant.has_fields() %} { {% for field in variant.fields() %}r#{{ field.name() }}, {%- endfor %} }{% else %}{..}{% endif %} => { buf.put_i32({{ loop.index }}); {% for field in variant.fields() -%} - {{ field.type_().borrow()|ffi_converter }}::write({{ field.name() }}, buf); + {{ field.type_().borrow()|ffi_converter }}::write(r#{{ field.name() }}, buf); {%- endfor %} }, {%- endfor %} }; } - fn try_read(buf: &mut &[u8]) -> uniffi::deps::anyhow::Result<{{ e.name() }}> { + fn try_read(buf: &mut &[u8]) -> uniffi::deps::anyhow::Result { // It's not currently supported to send errors from the foreign language *into* Rust, // but this is what the supporting code might look like... use uniffi::deps::bytes::Buf; uniffi::check_remaining(buf, 4)?; Ok(match buf.get_i32() { {%- for variant in e.variants() %} - {{ loop.index }} => {{ e.name() }}::{{ variant.name() }}{% if variant.has_fields() %} { + {{ loop.index }} => r#{{ e.name() }}::r#{{ variant.name() }}{% if variant.has_fields() %} { {% for field in variant.fields() %} - {{ field.name() }}: {{ field.type_().borrow()|ffi_converter }}::try_read(buf)?, + r#{{ field.name() }}: {{ field.type_().borrow()|ffi_converter }}::try_read(buf)?, {%- endfor %} }{% endif %}, {%- endfor %} diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ExternalTypesTemplate.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ExternalTypesTemplate.rs index 37134175b0fa..078c4e2462ab 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ExternalTypesTemplate.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ExternalTypesTemplate.rs @@ -26,7 +26,7 @@ trait UniffiCustomTypeConverter { pub struct FfiConverterType{{ name }}; unsafe impl uniffi::FfiConverter for FfiConverterType{{ name }} { - type RustType = {{ name }}; + type RustType = r#{{ name }}; type FfiType = {{ FFIType::from(builtin).borrow()|type_ffi }}; fn lower(obj: {{ name }} ) -> Self::FfiType { @@ -34,14 +34,14 @@ unsafe impl uniffi::FfiConverter for FfiConverterType{{ name }} { } fn try_lift(v: Self::FfiType) -> uniffi::Result<{{ name }}> { - <{{ name }} as UniffiCustomTypeConverter>::into_custom(<{{ builtin|type_rs }} as uniffi::FfiConverter>::try_lift(v)?) + ::into_custom(<{{ builtin|type_rs }} as uniffi::FfiConverter>::try_lift(v)?) } fn write(obj: {{ name }}, buf: &mut Vec) { <{{ builtin|type_rs }} as uniffi::FfiConverter>::write(<{{ name }} as UniffiCustomTypeConverter>::from_custom(obj), buf); } - fn try_read(buf: &mut &[u8]) -> uniffi::Result<{{ name }}> { + fn try_read(buf: &mut &[u8]) -> uniffi::Result { <{{ name }} as UniffiCustomTypeConverter>::into_custom(<{{ builtin|type_rs }} as uniffi::FfiConverter>::try_read(buf)?) } } diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ObjectTemplate.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ObjectTemplate.rs index 3f404e94386a..4d049828f067 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ObjectTemplate.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/ObjectTemplate.rs @@ -29,7 +29,7 @@ fn uniffi_note_threadsafe_deprecation_{{ obj.name() }}() {} // if they are not, but unfortunately it fails with an unactionably obscure error message. // By asserting the requirement explicitly, we help Rust produce a more scrutable error message // and thus help the user debug why the requirement isn't being met. -uniffi::deps::static_assertions::assert_impl_all!({{ obj.name() }}: Sync, Send); +uniffi::deps::static_assertions::assert_impl_all!(r#{{ obj.name() }}: Sync, Send); {% let ffi_free = obj.ffi_object_free() -%} #[doc(hidden)] @@ -38,14 +38,14 @@ pub extern "C" fn {{ ffi_free.name() }}(ptr: *const std::os::raw::c_void, call_s uniffi::call_with_output(call_status, || { assert!(!ptr.is_null()); {#- turn it into an Arc and explicitly drop it. #} - drop(unsafe { std::sync::Arc::from_raw(ptr as *const {{ obj.name() }}) }) + drop(unsafe { std::sync::Arc::from_raw(ptr as *const r#{{ obj.name() }}) }) }) } {%- for cons in obj.constructors() %} #[doc(hidden)] #[no_mangle] - pub extern "C" fn {{ cons.ffi_func().name() }}( + pub extern "C" fn r#{{ cons.ffi_func().name() }}( {%- call rs::arg_list_ffi_decl(cons.ffi_func()) %}) -> *const std::os::raw::c_void /* *const {{ obj.name() }} */ { uniffi::deps::log::debug!("{{ cons.ffi_func().name() }}"); {% if obj.uses_deprecated_threadsafe_attribute() %} @@ -61,7 +61,7 @@ pub extern "C" fn {{ ffi_free.name() }}(ptr: *const std::os::raw::c_void, call_s {%- for meth in obj.methods() %} #[doc(hidden)] #[no_mangle] - pub extern "C" fn {{ meth.ffi_func().name() }}( + pub extern "C" fn r#{{ meth.ffi_func().name() }}( {%- call rs::arg_list_ffi_decl(meth.ffi_func()) %} ) {% call rs::return_signature(meth) %} { uniffi::deps::log::debug!("{{ meth.ffi_func().name() }}"); diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/RecordTemplate.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/RecordTemplate.rs index 98b41b529d8c..6ec85ed03619 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/RecordTemplate.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/RecordTemplate.rs @@ -13,20 +13,20 @@ pub struct {{ rec.type_().borrow()|ffi_converter_name }}; #[doc(hidden)] impl uniffi::RustBufferFfiConverter for {{ rec.type_().borrow()|ffi_converter_name }} { - type RustType = {{ rec.name() }}; + type RustType = r#{{ rec.name() }}; - fn write(obj: {{ rec.name() }}, buf: &mut std::vec::Vec) { + fn write(obj: r#{{ rec.name() }}, buf: &mut std::vec::Vec) { // If the provided struct doesn't match the fields declared in the UDL, then // the generated code here will fail to compile with somewhat helpful error. {%- for field in rec.fields() %} - {{ field.type_().borrow()|ffi_converter }}::write(obj.{{ field.name() }}, buf); + {{ field.type_().borrow()|ffi_converter }}::write(obj.r#{{ field.name() }}, buf); {%- endfor %} } - fn try_read(buf: &mut &[u8]) -> uniffi::deps::anyhow::Result<{{ rec.name() }}> { - Ok({{ rec.name() }} { + fn try_read(buf: &mut &[u8]) -> uniffi::deps::anyhow::Result { + Ok(r#{{ rec.name() }} { {%- for field in rec.fields() %} - {{ field.name() }}: {{ field.type_().borrow()|ffi_converter }}::try_read(buf)?, + r#{{ field.name() }}: {{ field.type_().borrow()|ffi_converter }}::try_read(buf)?, {%- endfor %} }) } diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/TopLevelFunctionTemplate.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/TopLevelFunctionTemplate.rs index f4736bf256e5..5c0c26ea5425 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/TopLevelFunctionTemplate.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/TopLevelFunctionTemplate.rs @@ -6,7 +6,7 @@ #} #[doc(hidden)] #[no_mangle] -pub extern "C" fn {{ func.ffi_func().name() }}( +pub extern "C" fn r#{{ func.ffi_func().name() }}( {% call rs::arg_list_ffi_decl(func.ffi_func()) %} ) {% call rs::return_signature(func) %} { // If the provided function does not match the signature specified in the UDL diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/macros.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/macros.rs index 983ac4c8ee67..22ee543b3eb2 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/macros.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/macros.rs @@ -3,12 +3,12 @@ #} {%- macro to_rs_call(func) -%} -{{ func.name() }}({% call _arg_list_rs_call(func) -%}) +r#{{ func.name() }}({% call _arg_list_rs_call(func) -%}) {%- endmacro -%} {%- macro _arg_list_rs_call(func) %} {%- for arg in func.full_arguments() %} - match {{- arg.type_().borrow()|ffi_converter }}::try_lift({{ arg.name() }}) { + match {{- arg.type_().borrow()|ffi_converter }}::try_lift(r#{{ arg.name() }}) { {%- if arg.by_ref() %} Ok(ref val) => val, {% else %} @@ -36,7 +36,7 @@ -#} {%- macro arg_list_ffi_decl(func) %} {%- for arg in func.arguments() %} - {{- arg.name() }}: {{ arg.type_().borrow()|type_ffi -}}, + r#{{- arg.name() }}: {{ arg.type_().borrow()|type_ffi -}}, {%- endfor %} call_status: &mut uniffi::RustCallStatus {%- endmacro -%} @@ -45,7 +45,7 @@ {{- prefix -}} {%- if meth.arguments().len() > 0 %}, {# whitespace #} {%- for arg in meth.arguments() %} - {{- arg.name() }}: {{ arg.type_().borrow()|type_rs -}}{% if loop.last %}{% else %},{% endif %} + r#{{- arg.name() }}: {{ arg.type_().borrow()|type_rs -}}{% if loop.last %}{% else %},{% endif %} {%- endfor %} {%- endif %} {%- endmacro -%} @@ -57,7 +57,7 @@ {% macro ret(func) %}{% match func.return_type() %}{% when Some with (return_type) %}{{ return_type|ffi_converter }}::lower(_retval){% else %}_retval{% endmatch %}{% endmacro %} {% macro construct(obj, cons) %} - {{- obj.name() }}::{% call to_rs_call(cons) -%} + r#{{- obj.name() }}::{% call to_rs_call(cons) -%} {% endmacro %} {% macro to_rs_constructor_call(obj, cons) %} @@ -81,17 +81,17 @@ {% match meth.throws_type() -%} {% when Some with (e) -%} uniffi::call_with_result(call_status, || { - let _retval = {{ obj.name() }}::{% call to_rs_call(meth) %}.map_err(Into::into).map_err({{ e|ffi_converter }}::lower)?; + let _retval = r#{{ obj.name() }}::{% call to_rs_call(meth) %}.map_err(Into::into).map_err({{ e|ffi_converter }}::lower)?; Ok({% call ret(meth) %}) }) {% else %} uniffi::call_with_output(call_status, || { {% match meth.return_type() -%} {% when Some with (return_type) -%} - let retval = {{ obj.name() }}::{% call to_rs_call(meth) %}; + let retval = r#{{ obj.name() }}::{% call to_rs_call(meth) %}; {{ return_type|ffi_converter }}::lower(retval) {% else -%} - {{ obj.name() }}::{% call to_rs_call(meth) %} + r#{{ obj.name() }}::{% call to_rs_call(meth) %} {% endmatch -%} }) {% endmatch -%} diff --git a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/scaffolding_template.rs b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/scaffolding_template.rs index a78ad8148bfb..11b6507e2984 100644 --- a/third_party/rust/uniffi_bindgen/src/scaffolding/templates/scaffolding_template.rs +++ b/third_party/rust/uniffi_bindgen/src/scaffolding/templates/scaffolding_template.rs @@ -20,32 +20,32 @@ uniffi::deps::static_assertions::assert_impl_all!({{ k|type_rs }}: ::std::cmp::E {% include "RustBuffer.rs" %} // Error definitions, corresponding to `error` in the UDL. -{% for e in ci.iter_error_definitions() %} +{% for e in ci.error_definitions() %} {% include "ErrorTemplate.rs" %} {% endfor %} // Enum defitions, corresponding to `enum` in UDL. -{% for e in ci.iter_enum_definitions() %} +{% for e in ci.enum_definitions() %} {% include "EnumTemplate.rs" %} {% endfor %} // Record definitions, implemented as method-less structs, corresponding to `dictionary` objects. -{% for rec in ci.iter_record_definitions() %} +{% for rec in ci.record_definitions() %} {% include "RecordTemplate.rs" %} {% endfor %} // Top level functions, corresponding to UDL `namespace` functions. -{%- for func in ci.iter_function_definitions() %} +{%- for func in ci.function_definitions() %} {% include "TopLevelFunctionTemplate.rs" %} {% endfor -%} // Object definitions, corresponding to UDL `interface` definitions. -{% for obj in ci.iter_object_definitions() %} +{% for obj in ci.object_definitions() %} {% include "ObjectTemplate.rs" %} {% endfor %} // Callback Interface definitions, corresponding to UDL `callback interface` definitions. -{% for cbi in ci.iter_callback_interface_definitions() %} +{% for cbi in ci.callback_interface_definitions() %} {% include "CallbackInterfaceTemplate.rs" %} {% endfor %} diff --git a/third_party/rust/uniffi_build/.cargo-checksum.json b/third_party/rust/uniffi_build/.cargo-checksum.json index 65340fb20dbd..a48bde870f20 100644 --- a/third_party/rust/uniffi_build/.cargo-checksum.json +++ b/third_party/rust/uniffi_build/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"9a8c997c733714063988577f09377deb9b94dfa7d6cc5aa6d2ecf71e241aa78e","src/lib.rs":"f2a2d5682f49bded815a98364f3354b1c0f6800c711d9bd04329112506d10b27"},"package":"bcb7401cfd8da93541c23a0683c1dab3c782d2a118254536106b0aa4d9b30607"} \ No newline at end of file +{"files":{"Cargo.toml":"18d0f765975c969a3b1f19e840fe565edc53c12b6c0dbaf5c9bc4bdf9a1aad46","src/lib.rs":"4e610802833082b5ffdf2b65ab5cb2556994bc55872dd7a8f4e24094e22b745f"},"package":"8fff0860625e4e621f0317e5f6ac9e79966262bd86a6cfb2049e8425df23afbd"} \ No newline at end of file diff --git a/third_party/rust/uniffi_build/Cargo.toml b/third_party/rust/uniffi_build/Cargo.toml index d68629cc9771..bcb729134110 100644 --- a/third_party/rust/uniffi_build/Cargo.toml +++ b/third_party/rust/uniffi_build/Cargo.toml @@ -10,9 +10,9 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" +edition = "2021" name = "uniffi_build" -version = "0.18.0" +version = "0.19.3" authors = ["Firefox Sync Team "] description = "a multi-language bindings generator for rust (build script helpers)" homepage = "https://mozilla.github.io/uniffi-rs" @@ -23,12 +23,16 @@ keywords = [ ] license = "MPL-2.0" repository = "https://github.com/mozilla/uniffi-rs" +resolver = "2" [dependencies.anyhow] version = "1" +[dependencies.camino] +version = "1.0.8" + [dependencies.uniffi_bindgen] -version = "=0.18.0" +version = "=0.19.3" optional = true [features] diff --git a/third_party/rust/uniffi_build/src/lib.rs b/third_party/rust/uniffi_build/src/lib.rs index 1e6caba830cb..137b8dbb2b3f 100644 --- a/third_party/rust/uniffi_build/src/lib.rs +++ b/third_party/rust/uniffi_build/src/lib.rs @@ -2,14 +2,10 @@ * 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/. */ -use anyhow::Result; +use anyhow::{Context, Result}; +use camino::Utf8Path; use std::env; -#[cfg(not(feature = "builtin-bindgen"))] -use anyhow::{bail, Context}; -#[cfg(not(feature = "builtin-bindgen"))] -use std::process::Command; - /// Generate the rust "scaffolding" required to build a uniffi component. /// /// Given the path to an UDL file, this function will call the `uniffi-bindgen` @@ -25,7 +21,9 @@ use std::process::Command; /// the `uniffi_bindgen` crate and call its methods directly, rather than using the /// command-line tool. This is mostly useful for developers who are working on uniffi /// itself and need to test out their changes to the bindings generator. -pub fn generate_scaffolding(udl_file: &str) -> Result<()> { +pub fn generate_scaffolding(udl_file: impl AsRef) -> Result<()> { + let udl_file = udl_file.as_ref(); + println!("cargo:rerun-if-changed={}", udl_file); // The UNIFFI_TESTS_DISABLE_EXTENSIONS variable disables some bindings, but it is evaluated // at *build* time, so we need to rebuild when it changes. @@ -33,16 +31,25 @@ pub fn generate_scaffolding(udl_file: &str) -> Result<()> { // Why don't we just depend on uniffi-bindgen and call the public functions? // Calling the command line helps making sure that the generated swift/Kotlin/whatever // bindings were generated with the same version of uniffi as the Rust scaffolding code. - let out_dir = env::var("OUT_DIR").map_err(|_| anyhow::anyhow!("$OUT_DIR missing?!"))?; - run_uniffi_bindgen_scaffolding(&out_dir, udl_file) + let out_dir = env::var("OUT_DIR").context("$OUT_DIR missing?!")?; + run_uniffi_bindgen_scaffolding(out_dir.as_ref(), udl_file) } #[cfg(not(feature = "builtin-bindgen"))] -fn run_uniffi_bindgen_scaffolding(out_dir: &str, udl_file: &str) -> Result<()> { +fn run_uniffi_bindgen_scaffolding(out_dir: &Utf8Path, udl_file: &Utf8Path) -> Result<()> { + use anyhow::bail; + use std::process::Command; + let status = Command::new("uniffi-bindgen") - .args(&["scaffolding", "--out-dir", out_dir, udl_file]) + .arg("scaffolding") + .arg("--out-dir") + .arg(out_dir) + .arg(udl_file) .status() - .context("failed to run `uniffi-bindgen` - have you installed it via `cargo install uniffi_bindgen`?")?; + .context( + "failed to run `uniffi-bindgen` - \ + have you installed it via `cargo install uniffi_bindgen`?", + )?; if !status.success() { bail!("Error while generating scaffolding code"); } @@ -50,6 +57,6 @@ fn run_uniffi_bindgen_scaffolding(out_dir: &str, udl_file: &str) -> Result<()> { } #[cfg(feature = "builtin-bindgen")] -fn run_uniffi_bindgen_scaffolding(out_dir: &str, udl_file: &str) -> Result<()> { +fn run_uniffi_bindgen_scaffolding(out_dir: &Utf8Path, udl_file: &Utf8Path) -> Result<()> { uniffi_bindgen::generate_component_scaffolding(udl_file, None, Some(out_dir), false) } diff --git a/third_party/rust/uniffi_macros/.cargo-checksum.json b/third_party/rust/uniffi_macros/.cargo-checksum.json index 579db057b8da..6da7b5cda92e 100644 --- a/third_party/rust/uniffi_macros/.cargo-checksum.json +++ b/third_party/rust/uniffi_macros/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"8b7055c55b98f9f5cbc2cd8321a8d7c515c196daf510b417042d39ef05c181ef","src/lib.rs":"db49a3378cf4c7e39a8a00a5baae41d803494e8c59edd2411319cb6fd42ed933"},"package":"4e7b60ccb030ef51b0c85eb9ca55f28ff68b82c1a29d2bc0c7053777010af0d3"} \ No newline at end of file +{"files":{"Cargo.toml":"bcb221576954dbecc9ec60015254cd00d89b3648054459469036d7c34e73de33","src/lib.rs":"f9bef1786e96ed82eac977e0f4286ad285fa5e597da2d4f3777095a4d940ed7c"},"package":"7956a6c1fb12bff15e537028ea2174f000f90dd4f87912233b276ea782d420f2"} \ No newline at end of file diff --git a/third_party/rust/uniffi_macros/Cargo.toml b/third_party/rust/uniffi_macros/Cargo.toml index fd09b2fa5de1..606ad0767eea 100644 --- a/third_party/rust/uniffi_macros/Cargo.toml +++ b/third_party/rust/uniffi_macros/Cargo.toml @@ -10,9 +10,9 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" +edition = "2021" name = "uniffi_macros" -version = "0.18.0" +version = "0.19.3" authors = ["Firefox Sync Team "] description = "a multi-language bindings generator for rust (convenience macros)" homepage = "https://mozilla.github.io/uniffi-rs" @@ -23,10 +23,14 @@ keywords = [ ] license = "MPL-2.0" repository = "https://github.com/mozilla/uniffi-rs" +resolver = "2" [lib] proc-macro = true +[dependencies.camino] +version = "1.0.8" + [dependencies.glob] version = "0.3" @@ -41,7 +45,7 @@ version = "1.0" features = ["extra-traits"] [dependencies.uniffi_build] -version = "=0.18.0" +version = "=0.19.3" [features] builtin-bindgen = ["uniffi_build/builtin-bindgen"] diff --git a/third_party/rust/uniffi_macros/src/lib.rs b/third_party/rust/uniffi_macros/src/lib.rs index 87012f05cb6e..52d10f07e1d5 100644 --- a/third_party/rust/uniffi_macros/src/lib.rs +++ b/third_party/rust/uniffi_macros/src/lib.rs @@ -7,9 +7,9 @@ //! Currently this is just for easily generating integration tests, but maybe //! we'll put some other code-annotation helper macros in here at some point. +use camino::{Utf8Path, Utf8PathBuf}; use quote::{format_ident, quote}; use std::env; -use std::path::{Path, PathBuf}; use syn::{bracketed, punctuated::Punctuated, LitStr, Token}; /// A macro to build testcases for a component's generated bindings. @@ -38,8 +38,8 @@ pub fn build_foreign_language_testcases(paths: proc_macro::TokenStream) -> proc_ .udl_files .iter() .map(|file_path| { - let pathbuf: PathBuf = [&pkg_dir, file_path].iter().collect(); - let path = pathbuf.to_string_lossy(); + let pathbuf: Utf8PathBuf = [&pkg_dir, file_path].iter().collect(); + let path = pathbuf.to_string(); quote! { #path } }) .collect::>(); @@ -48,12 +48,11 @@ pub fn build_foreign_language_testcases(paths: proc_macro::TokenStream) -> proc_ let test_functions = paths.test_scripts .iter() .map(|file_path| { - let test_file_pathbuf: PathBuf = [&pkg_dir, file_path].iter().collect(); - let test_file_path = test_file_pathbuf.to_string_lossy(); + let test_file_pathbuf: Utf8PathBuf = [&pkg_dir, file_path].iter().collect(); + let test_file_path = test_file_pathbuf.to_string(); let test_file_name = test_file_pathbuf .file_name() - .expect("Test file has no name, cannot build tests for generated bindings") - .to_string_lossy(); + .expect("Test file has no name, cannot build tests for generated bindings"); let test_name = format_ident!( "uniffi_foreign_language_testcase_{}", test_file_name.replace(|c: char| !c.is_alphanumeric(), "_") @@ -79,7 +78,7 @@ pub fn build_foreign_language_testcases(paths: proc_macro::TokenStream) -> proc_ } // UNIFFI_TESTS_DISABLE_EXTENSIONS contains a comma-sep'd list of extensions (without leading `.`) -fn should_skip_path(path: &Path) -> bool { +fn should_skip_path(path: &Utf8Path) -> bool { let ext = path.extension().expect("File has no extension!"); env::var("UNIFFI_TESTS_DISABLE_EXTENSIONS") .map(|v| v.split(',').any(|look| look == ext)) @@ -163,20 +162,19 @@ pub fn generate_and_include_scaffolding( ) -> proc_macro::TokenStream { let udl_file = syn::parse_macro_input!(udl_file as syn::LitStr); let udl_file_string = udl_file.value(); - let udl_file_path = Path::new(udl_file_string.as_str()); + let udl_file_path = Utf8Path::new(&udl_file_string); if std::env::var("OUT_DIR").is_err() { quote! { compile_error!("This macro assumes the crate has a build.rs script, but $OUT_DIR is not present"); } - } else if uniffi_build::generate_scaffolding(&udl_file_path.to_string_lossy()).is_err() { + } else if uniffi_build::generate_scaffolding(udl_file_path).is_err() { quote! { compile_error!(concat!("Failed to generate scaffolding from UDL file at ", #udl_file)); } } else { // We know the filename is good because `generate_scaffolding` succeeded, // so this `unwrap` will never fail. - let name = udl_file_path.file_stem().unwrap().to_os_string(); - let name = LitStr::new(&name.to_string_lossy(), udl_file.span()); + let name = LitStr::new(udl_file_path.file_stem().unwrap(), udl_file.span()); quote! { uniffi_macros::include_scaffolding!(#name); } diff --git a/third_party/rust/weedle2/.cargo-checksum.json b/third_party/rust/weedle2/.cargo-checksum.json index 5f2cdc4e64c2..17060b53ceec 100644 --- a/third_party/rust/weedle2/.cargo-checksum.json +++ b/third_party/rust/weedle2/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"59fad65934e461dc7c34d75e4b1d1cb2713260edaaa9d20be9ba895813ce6177","LICENSE.md":"467e2e44913e850ca4fb6760fa3b78ffefda2a21688a6b1e26a8b706963669eb","README.md":"b4b50c5fb45e6e0ebf8223bf6cf4dbe290582b6ab131091d8957c5dcf3ab14b8","release.toml":"fce2a51533478f7e7d663b11ac69676323856780adf8af158ce213c9dbc86c75","src/argument.rs":"be162d59a9f1ef7d9d51d0f3492946f0dd263202af8355eeaee14ce4181775fc","src/attribute.rs":"b3577059be9c1262d3360b4b4cf4cc6cb052251e5b9d64906fb40fc5e925da69","src/common.rs":"7ac264f83ff596914af32fb08947cc500a75df57e43d9b2fce93163e5a20a738","src/dictionary.rs":"be209d70b0db33acf753ca63998a63dd37a9d4b193583a1490782781360c2d01","src/interface.rs":"bd2f32bfbcab2167f056fabbf92da9852300141ffc80d9542c6e1bbea9d521ac","src/lib.rs":"9c54d1fea9d1f6a16c184e0e0c203b423891d069094ff12e65b3cdeec609009f","src/literal.rs":"a728a5e198a5b2fcc238b53c9093873a7fd5bbe4d68a8dab72e4db45aab784dd","src/macros.rs":"aa95fd957d5175fb2779faec5d40b717fb5efd581f0f13ef7ba3510f37092da3","src/mixin.rs":"d65ff3a49615dabdf3f7845723f01ae730a83c8ef5bdd9a945d35149a9ef2858","src/namespace.rs":"fe6b406c2ab8bd904d0dff8a12321c77f4082ab364559e578e53ab415c8541fa","src/term.rs":"b47af21b66ca0d398b7e9e64106bbcca940b6cd2e2f7dd829eca339ffa26b896","src/types.rs":"0fe236336e71079c88ae4848624af29c87dd16266ba36c30a0d47e7dc4d33587","src/whitespace.rs":"069df2ae0f37d621a8ef84b08408c090ff1ead8164e52caa8ea7d57838f04cac"},"package":"8a69b360c3d0df7dc1a18124677ee8476576c806418f30a360a6cf6cf4e072a6"} \ No newline at end of file +{"files":{"Cargo.toml":"ef6c3a78fff105a0c3f83762619cecc2635f9c45749dc8ed74551cb49517b0b1","LICENSE.md":"467e2e44913e850ca4fb6760fa3b78ffefda2a21688a6b1e26a8b706963669eb","README.md":"b4b50c5fb45e6e0ebf8223bf6cf4dbe290582b6ab131091d8957c5dcf3ab14b8","release.toml":"fce2a51533478f7e7d663b11ac69676323856780adf8af158ce213c9dbc86c75","src/argument.rs":"be162d59a9f1ef7d9d51d0f3492946f0dd263202af8355eeaee14ce4181775fc","src/attribute.rs":"b3577059be9c1262d3360b4b4cf4cc6cb052251e5b9d64906fb40fc5e925da69","src/common.rs":"32d6ce3df2af316e02ab9abdc3cd2ffa5dfb18c713438fa845f21d41b354f5df","src/dictionary.rs":"be209d70b0db33acf753ca63998a63dd37a9d4b193583a1490782781360c2d01","src/interface.rs":"bd2f32bfbcab2167f056fabbf92da9852300141ffc80d9542c6e1bbea9d521ac","src/lib.rs":"5cde00b18e5d6ccf93700083789983c3062add28e88b9a3976f464d117ec9d64","src/literal.rs":"a728a5e198a5b2fcc238b53c9093873a7fd5bbe4d68a8dab72e4db45aab784dd","src/macros.rs":"aa95fd957d5175fb2779faec5d40b717fb5efd581f0f13ef7ba3510f37092da3","src/mixin.rs":"d65ff3a49615dabdf3f7845723f01ae730a83c8ef5bdd9a945d35149a9ef2858","src/namespace.rs":"fe6b406c2ab8bd904d0dff8a12321c77f4082ab364559e578e53ab415c8541fa","src/term.rs":"b8169fc27024bf397af8a8e4740ee0c3034c321a23e0b90846ebc8565335b6e3","src/types.rs":"0fe236336e71079c88ae4848624af29c87dd16266ba36c30a0d47e7dc4d33587","src/whitespace.rs":"069df2ae0f37d621a8ef84b08408c090ff1ead8164e52caa8ea7d57838f04cac"},"package":"5d730d941cf471131c40a64cf2e8a595822009f51e64c05c5afdbc85af155857"} \ No newline at end of file diff --git a/third_party/rust/weedle2/Cargo.toml b/third_party/rust/weedle2/Cargo.toml index 09c87114edd8..8ebbbb83219d 100644 --- a/third_party/rust/weedle2/Cargo.toml +++ b/third_party/rust/weedle2/Cargo.toml @@ -10,9 +10,9 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" +edition = "2021" name = "weedle2" -version = "2.0.1" +version = "3.0.0" authors = [ "Sharad Chand ", "Jan-Erik Rediger ", @@ -24,6 +24,7 @@ documentation = "https://docs.rs/weedle2" readme = "./README.md" license = "MIT" repository = "https://github.com/mozilla/uniffi-rs" +resolver = "2" [lib] name = "weedle" @@ -32,6 +33,6 @@ name = "weedle" version = "2.7.0" [dependencies.nom] -version = "5.0.0" +version = "6.0.0" features = ["std"] default-features = false diff --git a/third_party/rust/weedle2/src/common.rs b/third_party/rust/weedle2/src/common.rs index 81c6aa21a0a1..fd50f4404f6a 100644 --- a/third_party/rust/weedle2/src/common.rs +++ b/third_party/rust/weedle2/src/common.rs @@ -60,14 +60,14 @@ ast_types! { /// Parses `(item1, item2, item3,...)?` struct Punctuated where [T: Parse<'a>, S: Parse<'a> + ::std::default::Default] { - list: Vec = separated_list!(weedle!(S), weedle!(T)), + list: Vec = separated_list0!(weedle!(S), weedle!(T)), separator: S = marker, } /// Parses `item1, item2, item3, ...` struct PunctuatedNonEmpty where [T: Parse<'a>, S: Parse<'a> + ::std::default::Default] { list: Vec = terminated!( - separated_nonempty_list!(weedle!(S), weedle!(T)), + separated_list1!(weedle!(S), weedle!(T)), opt!(weedle!(S)) ), separator: S = marker, diff --git a/third_party/rust/weedle2/src/lib.rs b/third_party/rust/weedle2/src/lib.rs index 378268ec71c2..b891a6c9e798 100644 --- a/third_party/rust/weedle2/src/lib.rs +++ b/third_party/rust/weedle2/src/lib.rs @@ -32,8 +32,8 @@ many0, opt, recognize, - separated_list, - separated_nonempty_list, + separated_list0, + separated_list1, terminated )] extern crate nom; @@ -47,7 +47,7 @@ use self::literal::StringLit; use self::mixin::MixinMembers; use self::namespace::NamespaceMembers; use self::types::{AttributedType, ReturnType}; -pub use nom::{error::ErrorKind, Err, IResult}; +pub use nom::{error::Error, error::ErrorKind, Err, IResult}; #[macro_use] mod macros; @@ -80,7 +80,7 @@ pub mod types; /// /// println!("{:?}", parsed); /// ``` -pub fn parse(raw: &str) -> Result, Err<(&str, ErrorKind)>> { +pub fn parse(raw: &str) -> Result, Err>> { let (remaining, parsed) = Definitions::parse(raw)?; assert!( remaining.is_empty(), diff --git a/third_party/rust/weedle2/src/term.rs b/third_party/rust/weedle2/src/term.rs index 2c81a21e8b17..01612902acbe 100644 --- a/third_party/rust/weedle2/src/term.rs +++ b/third_party/rust/weedle2/src/term.rs @@ -21,11 +21,11 @@ macro_rules! ident_tag ( match tag!($i, $tok) { Err(e) => Err(e), Ok((i, o)) => { - use nom::{character::is_alphanumeric, Err as NomErr, error::ErrorKind}; + use nom::{character::is_alphanumeric, Err as NomErr, error::Error, error::ErrorKind}; let mut res = Ok((i, o)); if let Some(&c) = i.as_bytes().first() { if is_alphanumeric(c) || c == b'_' || c == b'-' { - res = Err(NomErr::Error(($i, ErrorKind::Tag))); + res = Err(NomErr::Error(Error::new($i, ErrorKind::Tag))); } } res diff --git a/toolkit/components/glean/Cargo.toml b/toolkit/components/glean/Cargo.toml index 89e354b0d885..7bb5f9f6a448 100644 --- a/toolkit/components/glean/Cargo.toml +++ b/toolkit/components/glean/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "MPL-2.0" [dependencies] -glean = { version = "50.1.0", features = ["rkv-safe-mode"] } +glean = { version = "50.1.2", features = ["rkv-safe-mode"] } log = "0.4" nserror = { path = "../../../xpcom/rust/nserror" } nsstring = { path = "../../../xpcom/rust/nsstring" } diff --git a/toolkit/components/glean/api/Cargo.toml b/toolkit/components/glean/api/Cargo.toml index e65b3b9072ca..3ecf0702ed0a 100644 --- a/toolkit/components/glean/api/Cargo.toml +++ b/toolkit/components/glean/api/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] bincode = "1.0" chrono = "0.4.10" -glean = "50.1.0" +glean = "50.1.2" inherent = "1.0.0" log = "0.4" nsstring = { path = "../../../../xpcom/rust/nsstring", optional = true }