Skip to content

Commit

Permalink
Generate immutable records in uniffi bindings (#332)
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 the uniffi code generation to output immutable structs. I've
pointed the dependencies to my fork until this is included in the main
uniffi repo, but it should be enough to let the mobile devs test if the
solution is appropiate for them.
  • Loading branch information
dani-garcia authored Nov 20, 2023
1 parent d64782e commit 27045bf
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 29 deletions.
38 changes: 19 additions & 19 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

# Using master until 0.25.1 is released to fix https://github.com/mozilla/uniffi-rs/issues/1798
# Using git dependency temporarily to add support for immutable records in generated code
[patch.crates-io]
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" }
uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" }
uniffi_bindgen = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" }
uniffi_core = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" }
uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" }
uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "0a03b713306d6ce3de033157fc2ce92a238c2e24" }
uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "0a03b713306d6ce3de033157fc2ce92a238c2e24" }
uniffi_bindgen = { git = "https://github.com/mozilla/uniffi-rs", rev = "0a03b713306d6ce3de033157fc2ce92a238c2e24" }
uniffi_core = { git = "https://github.com/mozilla/uniffi-rs", rev = "0a03b713306d6ce3de033157fc2ce92a238c2e24" }
uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "0a03b713306d6ce3de033157fc2ce92a238c2e24" }
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.25.0"
uniffi = "=0.25.1"
schemars = { version = ">=0.8, <0.9", optional = true }

bitwarden = { path = "../bitwarden", features = ["mobile", "internal"] }

[build-dependencies]
uniffi = { version = "=0.25.0", features = ["build"] }
uniffi = { version = "=0.25.1", features = ["build"] }

[target.'cfg(any(target_os = "android", target_os = "ios"))'.dependencies]
openssl = { version = "0.10", features = ["vendored"] }
2 changes: 2 additions & 0 deletions crates/bitwarden-uniffi/uniffi.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[bindings.kotlin]
package_name = "com.bitwarden.sdk"
cdylib_name = "bitwarden_uniffi"
generate_immutable_records = true

[bindings.swift]
ffi_module_name = "BitwardenFFI"
module_name = "BitwardenSDK"
generate_immutable_records = true
2 changes: 1 addition & 1 deletion crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ chrono = { version = ">=0.4.26, <0.5", features = [
"serde",
"std",
], default-features = false }
uniffi = { version = "=0.25.0", optional = true }
uniffi = { version = "=0.25.1", 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"] }
Expand Down
2 changes: 2 additions & 0 deletions crates/bitwarden/uniffi.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[bindings.kotlin]
package_name = "com.bitwarden.core"
generate_immutable_records = true

[bindings.swift]
ffi_module_name = "BitwardenCoreFFI"
module_name = "BitwardenCore"
generate_immutable_records = true
2 changes: 1 addition & 1 deletion crates/uniffi-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"

[dependencies]
uniffi = { version = "=0.25.0", features = ["cli"] }
uniffi = { version = "=0.25.1", features = ["cli"] }

0 comments on commit 27045bf

Please sign in to comment.