Skip to content

Commit

Permalink
Update uniffi and add logging support (#795)
Browse files Browse the repository at this point in the history
## Type of change
```
- [ ] Bug fix
- [ ] New feature development
- [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
```

## Objective
Update Uniffi to 0.29.2 to solve a memory leak in RustBuffer, and also
add a logging implementation for the mobile clients.
Note that `env_logger` doesn't work for Android so it needs a `Logcat`
specific logger. (Thankfully this one [doesn't
panic](https://docs.rs/android_logger/latest/android_logger/fn.init_once.html)
when called repeatedly)
  • Loading branch information
dani-garcia committed May 23, 2024
1 parent 656cf5d commit ef3bcb7
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 36 deletions.
83 changes: 53 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/bitwarden-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sha1 = ">=0.10.5, <0.11"
sha2 = ">=0.10.6, <0.11"
subtle = ">=2.5.0, <3.0"
thiserror = ">=1.0.40, <2.0"
uniffi = { version = "=0.27.1", optional = true }
uniffi = { version = "=0.27.2", optional = true }
uuid = { version = ">=1.3.3, <2.0", features = ["serde"] }
zeroize = { version = ">=1.7.0, <2.0", features = ["derive", "aarch64"] }

Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-generators/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] }
serde = { version = ">=1.0, <2.0", features = ["derive"] }
serde_json = ">=1.0.96, <2.0"
thiserror = ">=1.0.40, <2.0"
uniffi = { version = "=0.27.1", optional = true }
uniffi = { version = "=0.27.2", optional = true }

[dev-dependencies]
rand_chacha = "0.3.1"
Expand Down
8 changes: 6 additions & 2 deletions crates/bitwarden-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ chrono = { version = ">=0.4.26, <0.5", features = [
"serde",
"std",
], default-features = false }
log = "0.4.20"
env_logger = "0.11.1"
schemars = { version = ">=0.8, <0.9", optional = true }
uniffi = "=0.27.1"
uniffi = "=0.27.2"
uuid = ">=1.3.3, <2"

[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.13"

[build-dependencies]
uniffi = { version = "=0.27.1", features = ["build"] }
uniffi = { version = "=0.27.2", features = ["build"] }

[lints]
workspace = true
12 changes: 12 additions & 0 deletions crates/bitwarden-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl Client {
/// Initialize a new instance of the SDK client
#[uniffi::constructor]
pub fn new(settings: Option<ClientSettings>) -> Arc<Self> {
init_logger();
Arc::new(Self(RwLock::new(bitwarden::Client::new(settings))))
}

Expand Down Expand Up @@ -68,3 +69,14 @@ impl Client {
msg
}
}

fn init_logger() {
#[cfg(not(target_os = "android"))]
let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.try_init();

#[cfg(target_os = "android")]
android_logger::init_once(
android_logger::Config::default().with_max_level(uniffi::deps::log::LevelFilter::Info),
);
}
2 changes: 1 addition & 1 deletion crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ serde_repr = ">=0.1.12, <0.2"
sha1 = ">=0.10.5, <0.11"
sha2 = ">=0.10.6, <0.11"
thiserror = ">=1.0.40, <2.0"
uniffi = { version = "=0.27.1", optional = true, features = ["tokio"] }
uniffi = { version = "=0.27.2", optional = true, features = ["tokio"] }
uuid = { version = ">=1.3.3, <2.0", features = ["serde"] }
zxcvbn = ">= 2.2.2, <3.0"

Expand Down
2 changes: 1 addition & 1 deletion crates/uniffi-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"

[dependencies]
uniffi = { version = "=0.27.1", features = ["cli"] }
uniffi = { version = "=0.27.2", features = ["cli"] }

0 comments on commit ef3bcb7

Please sign in to comment.