Skip to content

Commit a1e186e

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 a1e186e

File tree

3 files changed

+388
-191
lines changed

3 files changed

+388
-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: 33 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,35 @@ features = [
7774
"reqwest",
7875
]
7976

77+
[target.'cfg(target_family = "wasm")'.dependencies]
78+
console_error_panic_hook = "0.1.7"
79+
matrix-sdk-ui = { workspace = true, features = ["js", "uniffi"] }
80+
ruma-common = { workspace = true, features = ["js"] }
81+
tokio = { workspace = true, features = ["sync", "macros"] }
82+
uniffi = { workspace = true, features = ["wasm-unstable-single-threaded"] }
83+
wasm-rs-async-executor = "0.9.0"
84+
85+
[target.'cfg(target_family = "wasm")'.dependencies.matrix-sdk]
86+
workspace = true
87+
features = [
88+
"anyhow",
89+
"e2e-encryption",
90+
"experimental-widgets",
91+
"markdown",
92+
"rustls-tls",
93+
"socks",
94+
"indexeddb",
95+
"uniffi",
96+
]
97+
98+
[target.'cfg(not(target_family = "wasm"))'.dependencies]
99+
async-compat.workspace = true
100+
matrix-sdk-ui = { workspace = true, features = ["uniffi"] }
101+
ruma-common = { workspace = true }
102+
sentry-tracing = "0.36.0"
103+
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
104+
uniffi = { workspace = true, features = ["tokio"] }
105+
80106
[target.'cfg(target_os = "android")'.dependencies]
81107
paranoid-android = "0.2.1"
82108

0 commit comments

Comments
 (0)