feat!(ffi): rename setup_tracing into init_platform (#4790)

And make it take a boolean indicating whether we want to set up a
lightweight tokio runtime or not, instead of having
`setup_lightweight_tokio_runtime` as a public function + another
function, both of which would have to be called anyways.

cc @stefanceriu @jmartinesp
This commit is contained in:
Benjamin Bouvier
2025-03-12 10:41:01 +01:00
committed by GitHub
parent 2ac3b6e9a2
commit d3daa18bf8
2 changed files with 29 additions and 5 deletions

View File

@@ -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.

View File

@@ -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");