From 4819efd70240ced59f2a12f16d0ef13f01fb9fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Wed, 1 Nov 2023 12:45:05 +0100 Subject: [PATCH] Update Rust crate uniffi to v0.25.0 (#303) ## Type of change ``` - [ ] Bug fix - [ ] New feature development - [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ``` ## Objective Updated Uniffi to 0.25.0. This required some code changes: - BitwardenError now needs to implement Error. - Defining the uniffi_support types in both crates seems to be causing duplicate symbols on xcode at least, so we instead use `ffi_converter_forward!` to forward the type definitions from the `bitwarden` crate to the `bitwarden-uniffi` crate. - There is a name collision with our `Send`, and Rust's `Send`, so I've changed the imports to use `vault::Send`. - Removed the unused UDL file. --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 154 +++++++++++++++--- Cargo.toml | 12 +- crates/bitwarden-uniffi/Cargo.toml | 4 +- crates/bitwarden-uniffi/src/error.rs | 10 +- crates/bitwarden-uniffi/src/sdk.udl | 8 - crates/bitwarden-uniffi/src/uniffi_support.rs | 17 +- crates/bitwarden-uniffi/src/vault/sends.rs | 16 +- crates/bitwarden/Cargo.toml | 2 +- crates/uniffi-bindgen/Cargo.toml | 2 +- 9 files changed, 157 insertions(+), 68 deletions(-) delete mode 100644 crates/bitwarden-uniffi/src/sdk.udl diff --git a/Cargo.lock b/Cargo.lock index b865c9fe6..e4bf4f9df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -287,7 +287,7 @@ dependencies = [ "flate2", "globset", "home", - "nu-ansi-term", + "nu-ansi-term 0.49.0", "once_cell", "path_abs", "plist", @@ -1263,6 +1263,19 @@ dependencies = [ "slab", ] +[[package]] +name = "generator" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e" +dependencies = [ + "cc", + "libc", + "log", + "rustversion", + "windows", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -1717,6 +1730,29 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "loom" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" +dependencies = [ + "cfg-if", + "generator", + "pin-utils", + "scoped-tls", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.6.4" @@ -1870,6 +1906,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.49.0" @@ -1963,6 +2009,15 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oneshot" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f6640c6bda7731b1fdbab747981a0f896dd1fedaf9f4a53fa237a04a84431f4" +dependencies = [ + "loom", +] + [[package]] name = "onig" version = "6.4.0" @@ -2045,6 +2100,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "owo-colors" version = "3.5.0" @@ -2432,10 +2493,19 @@ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata", + "regex-automata 0.4.3", "regex-syntax 0.8.2", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + [[package]] name = "regex-automata" version = "0.4.3" @@ -2447,6 +2517,12 @@ dependencies = [ "regex-syntax 0.8.2", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.7.5" @@ -3254,9 +3330,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -3277,15 +3365,33 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" dependencies = [ + "matchers", + "nu-ansi-term 0.46.0", + "once_cell", + "regex", "sharded-slab", + "smallvec", "thread_local", + "tracing", "tracing-core", + "tracing-log", ] [[package]] @@ -3344,8 +3450,8 @@ checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "uniffi" -version = "0.24.1" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +version = "0.25.0" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "anyhow", "camino", @@ -3365,8 +3471,8 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.24.1" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +version = "0.25.0" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "anyhow", "askama", @@ -3380,7 +3486,6 @@ dependencies = [ "once_cell", "paste", "serde", - "serde_json", "toml 0.5.11", "uniffi_meta", "uniffi_testing", @@ -3389,8 +3494,8 @@ dependencies = [ [[package]] name = "uniffi_build" -version = "0.24.1" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +version = "0.25.0" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "anyhow", "camino", @@ -3399,8 +3504,8 @@ dependencies = [ [[package]] name = "uniffi_checksum_derive" -version = "0.24.1" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +version = "0.25.0" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "quote", "syn 2.0.38", @@ -3408,23 +3513,23 @@ dependencies = [ [[package]] name = "uniffi_core" -version = "0.24.1" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +version = "0.25.0" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "anyhow", "bytes", "camino", - "cargo_metadata", "log", "once_cell", + "oneshot", "paste", "static_assertions", ] [[package]] name = "uniffi_macros" -version = "0.24.1" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +version = "0.25.0" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "bincode", "camino", @@ -3441,34 +3546,31 @@ dependencies = [ [[package]] name = "uniffi_meta" -version = "0.24.1" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +version = "0.25.0" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "anyhow", "bytes", - "serde", "siphasher", "uniffi_checksum_derive", ] [[package]] name = "uniffi_testing" -version = "0.24.1" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +version = "0.25.0" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "anyhow", "camino", "cargo_metadata", "fs-err", "once_cell", - "serde", - "serde_json", ] [[package]] name = "uniffi_udl" -version = "0.24.1" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +version = "0.25.0" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "anyhow", "uniffi_meta", @@ -3675,7 +3777,7 @@ dependencies = [ [[package]] name = "weedle2" version = "4.0.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=53d5ac7274d8b4d66ad35b68cb6e2d89898f96af#53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" +source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" dependencies = [ "nom", ] diff --git a/Cargo.toml b/Cargo.toml index dbd4ed30f..a192c14e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,10 +22,10 @@ codegen-units = 1 # This is fine as long as we don't have any unhandled panics, but let's keep it disabled for now # strip = true -# Uniffi proc-macro support is still not part of a release, so we need to use the git version for now +# Using master until 0.25.1 is released to fix https://github.com/mozilla/uniffi-rs/issues/1798 [patch.crates-io] -uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" } -uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" } -uniffi_bindgen = { git = "https://github.com/mozilla/uniffi-rs", rev = "53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" } -uniffi_core = { git = "https://github.com/mozilla/uniffi-rs", rev = "53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" } -uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "53d5ac7274d8b4d66ad35b68cb6e2d89898f96af" } +uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } +uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } +uniffi_bindgen = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } +uniffi_core = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } +uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } diff --git a/crates/bitwarden-uniffi/Cargo.toml b/crates/bitwarden-uniffi/Cargo.toml index 759e84e19..a7b774c3c 100644 --- a/crates/bitwarden-uniffi/Cargo.toml +++ b/crates/bitwarden-uniffi/Cargo.toml @@ -18,13 +18,13 @@ chrono = { version = ">=0.4.26, <0.5", features = [ "std", ], default-features = false } env_logger = "0.10.0" -uniffi = "=0.24.1" +uniffi = "=0.25.0" schemars = { version = ">=0.8, <0.9", optional = true } bitwarden = { path = "../bitwarden", features = ["mobile", "internal"] } [build-dependencies] -uniffi = { version = "=0.24.1", features = ["build"] } +uniffi = { version = "=0.25.0", features = ["build"] } [target.'cfg(any(target_os = "android", target_os = "ios"))'.dependencies] openssl = { version = "0.10", features = ["vendored"] } diff --git a/crates/bitwarden-uniffi/src/error.rs b/crates/bitwarden-uniffi/src/error.rs index 1a1e9d29a..b6175eb3b 100644 --- a/crates/bitwarden-uniffi/src/error.rs +++ b/crates/bitwarden-uniffi/src/error.rs @@ -1,7 +1,7 @@ use std::fmt::{Display, Formatter}; // Name is converted from *Error to *Exception, so we can't just name the enum Error because Exception already exists -#[derive(uniffi::Error)] +#[derive(uniffi::Error, Debug)] #[uniffi(flat_error)] pub enum BitwardenError { E(bitwarden::error::Error), @@ -21,4 +21,12 @@ impl Display for BitwardenError { } } +impl std::error::Error for BitwardenError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + BitwardenError::E(e) => Some(e), + } + } +} + pub type Result = std::result::Result; diff --git a/crates/bitwarden-uniffi/src/sdk.udl b/crates/bitwarden-uniffi/src/sdk.udl deleted file mode 100644 index 96cfb31c0..000000000 --- a/crates/bitwarden-uniffi/src/sdk.udl +++ /dev/null @@ -1,8 +0,0 @@ -interface Client { - constructor(optional string settings = ""); - string run_command(string command); -}; - -namespace bitwarden { - -}; diff --git a/crates/bitwarden-uniffi/src/uniffi_support.rs b/crates/bitwarden-uniffi/src/uniffi_support.rs index f2a0bfde6..82cd343a7 100644 --- a/crates/bitwarden-uniffi/src/uniffi_support.rs +++ b/crates/bitwarden-uniffi/src/uniffi_support.rs @@ -1,16 +1,3 @@ -use crate::UniffiCustomTypeConverter; - +// Forward the type definitions to the main bitwarden crate type DateTime = chrono::DateTime; -uniffi::custom_type!(DateTime, std::time::SystemTime); - -impl UniffiCustomTypeConverter for chrono::DateTime { - type Builtin = std::time::SystemTime; - - fn into_custom(val: Self::Builtin) -> uniffi::Result { - Ok(Self::from(val)) - } - - fn from_custom(obj: Self) -> Self::Builtin { - obj.into() - } -} +uniffi::ffi_converter_forward!(DateTime, bitwarden::UniFfiTag, crate::UniFfiTag); diff --git a/crates/bitwarden-uniffi/src/vault/sends.rs b/crates/bitwarden-uniffi/src/vault/sends.rs index 6e2f1b879..696c4a861 100644 --- a/crates/bitwarden-uniffi/src/vault/sends.rs +++ b/crates/bitwarden-uniffi/src/vault/sends.rs @@ -1,6 +1,6 @@ use std::{path::Path, sync::Arc}; -use bitwarden::vault::{Send, SendListView, SendView}; +use bitwarden::vault::{self, SendListView, SendView}; use crate::{Client, Result}; @@ -10,12 +10,12 @@ pub struct ClientSends(pub Arc); #[uniffi::export] impl ClientSends { /// Encrypt send - pub async fn encrypt(&self, send: SendView) -> Result { + pub async fn encrypt(&self, send: SendView) -> Result { Ok(self.0 .0.read().await.vault().sends().encrypt(send).await?) } /// Encrypt a send file in memory - pub async fn encrypt_buffer(&self, send: Send, buffer: Vec) -> Result> { + pub async fn encrypt_buffer(&self, send: vault::Send, buffer: Vec) -> Result> { Ok(self .0 .0 @@ -30,7 +30,7 @@ impl ClientSends { /// Encrypt a send file located in the file system pub async fn encrypt_file( &self, - send: Send, + send: vault::Send, decrypted_file_path: String, encrypted_file_path: String, ) -> Result<()> { @@ -50,12 +50,12 @@ impl ClientSends { } /// Decrypt send - pub async fn decrypt(&self, send: Send) -> Result { + pub async fn decrypt(&self, send: vault::Send) -> Result { Ok(self.0 .0.read().await.vault().sends().decrypt(send).await?) } /// Decrypt send list - pub async fn decrypt_list(&self, sends: Vec) -> Result> { + pub async fn decrypt_list(&self, sends: Vec) -> Result> { Ok(self .0 .0 @@ -68,7 +68,7 @@ impl ClientSends { } /// Decrypt a send file in memory - pub async fn decrypt_buffer(&self, send: Send, buffer: Vec) -> Result> { + pub async fn decrypt_buffer(&self, send: vault::Send, buffer: Vec) -> Result> { Ok(self .0 .0 @@ -83,7 +83,7 @@ impl ClientSends { /// Decrypt a send file located in the file system pub async fn decrypt_file( &self, - send: Send, + send: vault::Send, encrypted_file_path: String, decrypted_file_path: String, ) -> Result<()> { diff --git a/crates/bitwarden/Cargo.toml b/crates/bitwarden/Cargo.toml index fcbe5b3ac..65db9db7d 100644 --- a/crates/bitwarden/Cargo.toml +++ b/crates/bitwarden/Cargo.toml @@ -50,7 +50,7 @@ chrono = { version = ">=0.4.26, <0.5", features = [ "serde", "std", ], default-features = false } -uniffi = { version = "=0.24.1", optional = true } +uniffi = { version = "=0.25.0", optional = true } # We don't use this directly (it's used by rand), but we need it here to enable WASM support getrandom = { version = ">=0.2.9", features = ["js"] } diff --git a/crates/uniffi-bindgen/Cargo.toml b/crates/uniffi-bindgen/Cargo.toml index c9c177c84..980434e89 100644 --- a/crates/uniffi-bindgen/Cargo.toml +++ b/crates/uniffi-bindgen/Cargo.toml @@ -10,4 +10,4 @@ name = "uniffi-bindgen" path = "uniffi-bindgen.rs" [dependencies] -uniffi = { version = "=0.24.1", features = ["cli"] } +uniffi = { version = "=0.25.0", features = ["cli"] }