From c3acd0d3e0008c005dcbcaa53cbf412a6f75ebd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 28 Nov 2025 13:59:50 +0100 Subject: [PATCH] refactor(sdk): Put ruma-federation-api dependency behind a feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In theory clients shouldn't make requests to the server-server API. A way to work around it for this specific case would be to implement MSC4383. In the meantime, clients that don't want to use `Client::server_vendor_info()` won't have to build the extra dependencies added by ruma-federation-api. The feature is enabled for the bindings, so it isn't a breaking change for matrix-sdk-ffi. Signed-off-by: Kévin Commaille --- bindings/matrix-sdk-ffi/Cargo.toml | 1 + crates/matrix-sdk/CHANGELOG.md | 3 +++ crates/matrix-sdk/Cargo.toml | 5 +++-- crates/matrix-sdk/src/client/mod.rs | 4 +++- crates/matrix-sdk/tests/integration/client.rs | 2 ++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bindings/matrix-sdk-ffi/Cargo.toml b/bindings/matrix-sdk-ffi/Cargo.toml index d2303ed66d4..273d3204afa 100644 --- a/bindings/matrix-sdk-ffi/Cargo.toml +++ b/bindings/matrix-sdk-ffi/Cargo.toml @@ -57,6 +57,7 @@ matrix-sdk = { workspace = true, features = [ "markdown", "socks", "uniffi", + "federation-api", ] } matrix-sdk-base.workspace = true matrix-sdk-common.workspace = true diff --git a/crates/matrix-sdk/CHANGELOG.md b/crates/matrix-sdk/CHANGELOG.md index f5907bbff0f..52d96fdfde2 100644 --- a/crates/matrix-sdk/CHANGELOG.md +++ b/crates/matrix-sdk/CHANGELOG.md @@ -8,6 +8,9 @@ All notable changes to this project will be documented in this file. ### Refactor +- [**breaking**]: `Client::server_vendor_info()` requires to enable the + `federation-api` feature. + ([#5912](https://github.com/matrix-org/matrix-rust-sdk/pull/5912)) - [**breaking**]: `Client::reset_server_info()` has been split into `reset_supported_versions()` and `reset_well_known()`. ([#5910](https://github.com/matrix-org/matrix-rust-sdk/pull/5910)) diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index 2b54afccb7e..2df89c0040a 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -61,12 +61,14 @@ rustls-tls = ["reqwest/rustls-tls"] socks = ["reqwest/socks"] local-server = ["dep:axum", "dep:rand", "dep:tower"] sso-login = ["local-server"] +# Enable methods that make calls to the federation API. +federation-api = ["ruma/federation-api-c"] uniffi = ["dep:uniffi", "matrix-sdk-base/uniffi", "dep:matrix-sdk-ffi-macros"] experimental-widgets = ["dep:uuid", "experimental-send-custom-to-device"] -docsrs = ["e2e-encryption", "sqlite", "indexeddb", "sso-login", "qrcode"] +docsrs = ["e2e-encryption", "sqlite", "indexeddb", "sso-login", "qrcode", "federation-api"] # Add support for inline media galleries via msgtypes unstable-msc4274 = ["ruma/unstable-msc4274", "matrix-sdk-base/unstable-msc4274"] @@ -116,7 +118,6 @@ pin-project-lite.workspace = true rand = { workspace = true, optional = true } ruma = { workspace = true, features = [ "rand", - "federation-api-c", "unstable-msc2448", "unstable-msc4191", "unstable-msc3930", diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 6a61c068876..f6f526796b1 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -73,7 +73,6 @@ use ruma::{ user_directory::search_users, }, error::FromHttpResponseError, - federation::discovery::get_server_version, path_builder::PathBuilder, }, assign, @@ -604,10 +603,13 @@ impl Client { /// ); /// # anyhow::Ok(()) }; /// ``` + #[cfg(feature = "federation-api")] pub async fn server_vendor_info( &self, request_config: Option, ) -> HttpResult { + use ruma::api::federation::discovery::get_server_version; + let res = self .send_inner(get_server_version::v1::Request::new(), request_config, Default::default()) .await?; diff --git a/crates/matrix-sdk/tests/integration/client.rs b/crates/matrix-sdk/tests/integration/client.rs index 8f1ee0a111f..c678c766eb7 100644 --- a/crates/matrix-sdk/tests/integration/client.rs +++ b/crates/matrix-sdk/tests/integration/client.rs @@ -1513,6 +1513,7 @@ async fn test_room_sync_state_after() { assert_eq!(*member.membership(), MembershipState::Leave); } +#[cfg(feature = "federation-api")] #[async_test] async fn test_server_vendor_info() { let server = MatrixMockServer::new().await; @@ -1567,6 +1568,7 @@ async fn test_server_version_without_auth() { .expect("We should not fail here since we did not provide an auth token."); } +#[cfg(feature = "federation-api")] #[async_test] async fn test_server_vendor_info_with_missing_fields() { let server = MatrixMockServer::new().await;