diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index fc34586b8..f427fbe7d 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -2,6 +2,11 @@ Breaking changes: +- `setup_tracing` has been renamed `init_platform`; in addition to the `TracingConfiguration` + parameter it also now takes a boolean indicating whether to spawn a minimal tokio runtime for the + application; in general for main app processes this can be set to `false`, and memory-constrained + programs can set it to `true`. + - Matrix client API errors coming from API responses will now be mapped to `ClientError::MatrixApi`, containing both the original message and the associated error code and kind. diff --git a/bindings/matrix-sdk-ffi/src/platform.rs b/bindings/matrix-sdk-ffi/src/platform.rs index 9fd03c2ce..6fa0f9fa5 100644 --- a/bindings/matrix-sdk-ffi/src/platform.rs +++ b/bindings/matrix-sdk-ffi/src/platform.rs @@ -348,20 +348,39 @@ fn build_tracing_filter(config: &TracingConfiguration) -> String { filters.join(",") } +/// Sets up logs and the tokio runtime for the current application. +/// +/// If `use_lightweight_tokio_runtime` is set to true, this will set up a +/// lightweight tokio runtime, for processes that have memory limitations (like +/// the NSE process on iOS). Otherwise, this can remain false, in which case a +/// multithreaded tokio runtime will be set up. #[matrix_sdk_ffi_macros::export] -pub fn setup_tracing(config: TracingConfiguration) { +pub fn init_platform(config: TracingConfiguration, use_lightweight_tokio_runtime: bool) { log_panics(); tracing_subscriber::registry() .with(EnvFilter::new(build_tracing_filter(&config))) .with(text_layers(config)) .init(); + + if use_lightweight_tokio_runtime { + setup_lightweight_tokio_runtime(); + } else { + setup_multithreaded_tokio_runtime(); + } } -/// Set up a lightweight tokio runtime, for processes that have memory -/// limitations (like the NSE process on iOS). -#[matrix_sdk_ffi_macros::export] -pub fn setup_lightweight_tokio_runtime() { +fn setup_multithreaded_tokio_runtime() { + async_compat::set_runtime_builder(Box::new(|| { + eprintln!("spawning a multithreaded tokio runtime"); + + let mut builder = tokio::runtime::Builder::new_multi_thread(); + builder.enable_all(); + builder + })); +} + +fn setup_lightweight_tokio_runtime() { async_compat::set_runtime_builder(Box::new(|| { eprintln!("spawning a lightweight tokio runtime");