From ffc8453c632d833c6cdd8edf481ee367a2d2cd5b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 11 Jan 2023 12:26:09 +0100 Subject: [PATCH] bindings: Use async-compat tokio runtime --- Cargo.lock | 13 +++++++++++++ Cargo.toml | 3 +++ bindings/matrix-sdk-ffi/Cargo.toml | 1 + bindings/matrix-sdk-ffi/src/lib.rs | 12 +++--------- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d987f84fd..f55709e3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -240,6 +240,18 @@ dependencies = [ "futures-core", ] +[[package]] +name = "async-compat" +version = "0.2.1" +source = "git+https://github.com/jplatte/async-compat?rev=b83b197622d8b5756d3594ce73b720896b07faae#b83b197622d8b5756d3594ce73b720896b07faae" +dependencies = [ + "futures-core", + "futures-io", + "once_cell", + "pin-project-lite", + "tokio", +] + [[package]] name = "async-compression" version = "0.4.0" @@ -2782,6 +2794,7 @@ name = "matrix-sdk-ffi" version = "0.2.0" dependencies = [ "anyhow", + "async-compat", "base64 0.21.0", "extension-trait", "eyeball", diff --git a/Cargo.toml b/Cargo.toml index 7bfaf3fe1..5d9c36a9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,3 +79,6 @@ incremental = false # Compile all non-workspace crate in the dependency tree with optimizations [profile.reldbg.package."*"] opt-level = 3 + +[patch.crates-io] +async-compat = { git = "https://github.com/jplatte/async-compat", rev = "b83b197622d8b5756d3594ce73b720896b07faae" } diff --git a/bindings/matrix-sdk-ffi/Cargo.toml b/bindings/matrix-sdk-ffi/Cargo.toml index 1d51ff26e..7c926ae9e 100644 --- a/bindings/matrix-sdk-ffi/Cargo.toml +++ b/bindings/matrix-sdk-ffi/Cargo.toml @@ -22,6 +22,7 @@ vergen = { version = "8.1.3", features = ["build", "git", "gitcl"] } [dependencies] anyhow = { workspace = true } +async-compat = "0.2.1" base64 = "0.21" eyeball = { workspace = true } eyeball-im = { workspace = true } diff --git a/bindings/matrix-sdk-ffi/src/lib.rs b/bindings/matrix-sdk-ffi/src/lib.rs index 5cdb34516..c448528d1 100644 --- a/bindings/matrix-sdk-ffi/src/lib.rs +++ b/bindings/matrix-sdk-ffi/src/lib.rs @@ -36,15 +36,7 @@ pub mod sliding_sync; pub mod timeline; pub mod tracing; -use once_cell::sync::Lazy; -use tokio::runtime::Runtime; - -// Re-exports for more convenient use inside other submodules -use self::{client::Client, error::ClientError}; - -pub static RUNTIME: Lazy = - Lazy::new(|| Runtime::new().expect("Can't start Tokio runtime")); - +use async_compat::TOKIO1 as RUNTIME; pub use matrix_sdk::ruma::{api::client::account::register, UserId}; pub use matrix_sdk_ui::timeline::PaginationOutcome; pub use platform::*; @@ -53,6 +45,8 @@ pub use self::{ authentication_service::*, client::*, event::*, notification::*, room::*, room_member::*, session_verification::*, sliding_sync::*, timeline::*, tracing::*, }; +// Re-exports for more convenient use inside other submodules +use self::{client::Client, error::ClientError}; uniffi::include_scaffolding!("api");