Skip to content

Commit

Permalink
Update Rust crate uniffi to v0.25.0 (#303)
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
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>
  • Loading branch information
dani-garcia and renovate[bot] authored Nov 1, 2023
1 parent 1c86c09 commit 4819efd
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 68 deletions.
154 changes: 128 additions & 26 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
4 changes: 2 additions & 2 deletions crates/bitwarden-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
10 changes: 9 additions & 1 deletion crates/bitwarden-uniffi/src/error.rs
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -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<T, E = BitwardenError> = std::result::Result<T, E>;
8 changes: 0 additions & 8 deletions crates/bitwarden-uniffi/src/sdk.udl

This file was deleted.

Loading

0 comments on commit 4819efd

Please sign in to comment.