Skip to content

Commit 9ace356

Browse files
Daniel SalinasDaniel Salinas
authored andcommitted
Add ability to configure indexedb instead of sqlite for wasm platforms
The challenge is to maintain a compatible -ffi API, despite the fact that both cannot be used on both platforms. Approach is to use runtime panics here to stop usage if it is being misused.
1 parent becbb63 commit 9ace356

File tree

3 files changed

+338
-191
lines changed

3 files changed

+338
-191
lines changed

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Breaking changes:
1818
- `RoomInfo` replaces its field `is_tombstoned: bool` with `tombstone: Option<RoomTombstoneInfo>`,
1919
containing the data needed to implement the room migration UI, a message and the replacement room id.
2020
([#5027](https://github.com/matrix-org/matrix-rust-sdk/pull/5027))
21+
- Encapsulate the configuration of the sqlite system into a builder `SqliteSessionBuilder` to allow for
22+
swapping with `IndexedDbSessionBuilder` on Wasm platforms.
2123

2224
Additions:
2325

bindings/matrix-sdk-ffi/Cargo.toml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ publish = false
1414
release = true
1515

1616
[lib]
17-
crate-type = ["cdylib", "staticlib"]
17+
crate-type = ["cdylib", "staticlib", "lib"]
1818

1919
[features]
2020
default = ["bundled-sqlite", "unstable-msc4274"]
2121
bundled-sqlite = ["matrix-sdk/bundled-sqlite"]
2222
unstable-msc4274 = ["matrix-sdk-ui/unstable-msc4274"]
23+
js = []
2324

2425
[dependencies]
2526
anyhow.workspace = true
2627
as_variant.workspace = true
27-
async-compat = "0.2.4"
2828
extension-trait = "1.0.1"
2929
eyeball-im.workspace = true
3030
futures-util.workspace = true
@@ -36,21 +36,18 @@ matrix-sdk-ui = { workspace = true, features = ["uniffi"] }
3636
mime = "0.3.16"
3737
once_cell.workspace = true
3838
ruma = { workspace = true, features = ["html", "unstable-unspecified", "unstable-msc3488", "compat-unset-avatar", "unstable-msc3245-v1-compat", "unstable-msc4278"] }
39-
sentry-tracing = "0.36.0"
4039
serde.workspace = true
4140
serde_json.workspace = true
4241
thiserror.workspace = true
43-
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
4442
tracing.workspace = true
4543
tracing-appender = { version = "0.2.2" }
4644
tracing-core.workspace = true
4745
tracing-subscriber = { workspace = true, features = ["env-filter"] }
48-
uniffi = { workspace = true, features = ["tokio"] }
4946
url.workspace = true
5047
uuid = { version = "1.4.1", features = ["v4"] }
5148
zeroize.workspace = true
5249

53-
[target.'cfg(not(target_os = "android"))'.dependencies.matrix-sdk]
50+
[target.'cfg(all(not(target_os = "android"), not(target_family = "wasm")))'.dependencies.matrix-sdk]
5451
workspace = true
5552
features = [
5653
"anyhow",
@@ -64,7 +61,7 @@ features = [
6461
"uniffi",
6562
]
6663

67-
[target.'cfg(not(target_os = "android"))'.dependencies.sentry]
64+
[target.'cfg(all(not(target_os = "android"), not(target_family = "wasm")))'.dependencies.sentry]
6865
version = "0.36.0"
6966
default-features = false
7067
features = [
@@ -77,6 +74,31 @@ features = [
7774
"reqwest",
7875
]
7976

77+
[target.'cfg(target_family = "wasm")'.dependencies]
78+
matrix-sdk-ui = { workspace = true, features = ["js", "uniffi"] }
79+
tokio = { workspace = true, features = ["sync", "macros"] }
80+
uniffi = { workspace = true, features = [] }
81+
82+
[target.'cfg(target_family = "wasm")'.dependencies.matrix-sdk]
83+
workspace = true
84+
features = [
85+
"anyhow",
86+
"e2e-encryption",
87+
"experimental-widgets",
88+
"markdown",
89+
"rustls-tls",
90+
"socks",
91+
"indexeddb",
92+
"uniffi",
93+
]
94+
95+
[target.'cfg(not(target_family = "wasm"))'.dependencies]
96+
async-compat.workspace = true
97+
matrix-sdk-ui = { workspace = true, features = ["uniffi"] }
98+
sentry-tracing = "0.36.0"
99+
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
100+
uniffi = { workspace = true, features = ["tokio"] }
101+
80102
[target.'cfg(target_os = "android")'.dependencies]
81103
paranoid-android = "0.2.1"
82104

0 commit comments

Comments
 (0)