Skip to content

Commit 769c953

Browse files
Daniel SalinasDaniel Salinas
authored andcommitted
Fix remaining wasm platform issues
1 parent e1ebaea commit 769c953

File tree

3 files changed

+26
-33
lines changed

3 files changed

+26
-33
lines changed

bindings/matrix-sdk-ffi/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ js = []
2424
[dependencies]
2525
anyhow.workspace = true
2626
as_variant.workspace = true
27-
async-compat.workspace = true
2827
extension-trait = "1.0.1"
2928
eyeball-im.workspace = true
3029
futures-util.workspace = true
@@ -44,7 +43,6 @@ tracing.workspace = true
4443
tracing-appender = { version = "0.2.2" }
4544
tracing-core.workspace = true
4645
tracing-subscriber = { workspace = true, features = ["env-filter"] }
47-
uniffi = { workspace = true, features = ["tokio"] }
4846
url.workspace = true
4947
uuid = { version = "1.4.1", features = ["v4"] }
5048
zeroize.workspace = true
@@ -68,9 +66,10 @@ paranoid-android = "0.2.1"
6866
[target.'cfg(target_family = "wasm")'.dependencies]
6967
console_error_panic_hook = "0.1.7"
7068
tokio = { workspace = true, features = ["sync", "macros"] }
71-
uniffi = { workspace = true, features = ["tokio", "wasm-unstable-single-threaded"] }
69+
uniffi = { workspace = true, features = ["wasm-unstable-single-threaded"] }
7270

7371
[target.'cfg(not(target_family = "wasm"))'.dependencies]
72+
async-compat.workspace = true
7473
sentry-tracing = "0.36.0"
7574
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
7675
uniffi = { workspace = true, features = ["tokio"] }

bindings/matrix-sdk-ffi/src/client_builder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::{fs, num::NonZeroUsize, path::Path, sync::Arc, time::Duration};
22

33
use futures_util::StreamExt;
44
#[cfg(not(target_family = "wasm"))]
5-
use matrix_sdk::reqwest::{Certificate, Proxy};
5+
use matrix_sdk::{
6+
reqwest::{Certificate, Proxy},
7+
SqliteStoreConfig
8+
};
69
use matrix_sdk::{
710
authentication::oauth::qrcode::{self, DeviceCodeErrorResponseType, LoginFailureReason}, crypto::{
811
types::qr_login::{LoginQrCodeDecodeError, QrCodeModeData},

bindings/matrix-sdk-ffi/src/platform.rs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -562,40 +562,31 @@ fn setup_multithreaded_tokio_runtime() {
562562
}));
563563
}
564564

565+
#[cfg(not(target_family = "wasm"))]
565566
fn setup_lightweight_tokio_runtime() {
566567
async_compat::set_runtime_builder(Box::new(|| {
567568
eprintln!("spawning a lightweight tokio runtime");
568569

569-
#[cfg(not(target_family = "wasm"))]
570-
{
571-
// Get the number of available cores through the system, if possible.
572-
let num_available_cores =
573-
std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1);
574-
575-
// The number of worker threads will be either that or 4, whichever is smaller.
576-
let num_worker_threads = num_available_cores.min(4);
577-
578-
// Chosen by a fair dice roll.
579-
let num_blocking_threads = 2;
580-
581-
// 1 MiB of memory per worker thread. Should be enough for everyone™.
582-
let max_memory_bytes = 1024 * 1024;
583-
584-
let mut builder = tokio::runtime::Builder::new_multi_thread();
585-
builder
586-
.enable_all()
587-
.worker_threads(num_worker_threads)
588-
.thread_stack_size(max_memory_bytes)
589-
.max_blocking_threads(num_blocking_threads);
590-
builder
591-
}
570+
// Get the number of available cores through the system, if possible.
571+
let num_available_cores =
572+
std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1);
592573

593-
#[cfg(target_family = "wasm")]
594-
{
595-
let mut builder = tokio::runtime::Builder::new_current_thread();
596-
builder.enable_all();
597-
builder
598-
}
574+
// The number of worker threads will be either that or 4, whichever is smaller.
575+
let num_worker_threads = num_available_cores.min(4);
576+
577+
// Chosen by a fair dice roll.
578+
let num_blocking_threads = 2;
579+
580+
// 1 MiB of memory per worker thread. Should be enough for everyone™.
581+
let max_memory_bytes = 1024 * 1024;
582+
583+
let mut builder = tokio::runtime::Builder::new_multi_thread();
584+
builder
585+
.enable_all()
586+
.worker_threads(num_worker_threads)
587+
.thread_stack_size(max_memory_bytes)
588+
.max_blocking_threads(num_blocking_threads);
589+
builder
599590
}));
600591
}
601592

0 commit comments

Comments
 (0)