fix(sdk): Use a consistent naming scheme for our features

This commit is contained in:
Damir Jelić
2022-03-30 09:52:13 +02:00
parent e720b4d5e3
commit f5d2ea0efa
15 changed files with 77 additions and 78 deletions

View File

@@ -13,13 +13,13 @@ default = ["native-tls"]
anyhow = ["matrix-sdk/anyhow"]
encryption = ["matrix-sdk/encryption"]
eyre = ["matrix-sdk/eyre"]
sled_state_store = ["matrix-sdk/sled_state_store"]
sled_cryptostore = ["matrix-sdk/sled_cryptostore"]
sled-state-store = ["matrix-sdk/sled-state-store"]
sled-crypto-store = ["matrix-sdk/sled-crypto-store"]
markdown = ["matrix-sdk/markdown"]
native-tls = ["matrix-sdk/native-tls"]
rustls-tls = ["matrix-sdk/rustls-tls"]
socks = ["matrix-sdk/socks"]
sso_login = ["matrix-sdk/sso_login"]
sso-login = ["matrix-sdk/sso-login"]
docs = []

View File

@@ -18,34 +18,34 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
default = [
"encryption",
"sled_cryptostore",
"sled_state_store",
"sled-crypto-store",
"sled-state-store",
"native-tls"
]
indexeddb_state_store = ["matrix-sdk-indexeddb"]
indexeddb_cryptostore = ["matrix-sdk-indexeddb/encryption", "encryption"]
indexeddb-state-store = ["matrix-sdk-indexeddb"]
indexeddb-crypto-store = ["matrix-sdk-indexeddb/encryption", "encryption"]
encryption = ["matrix-sdk-base/encryption"]
qrcode = ["encryption", "matrix-sdk-base/qrcode"]
# TODO merge those two sled features
sled_state_store = ["matrix-sdk-sled/state-store"]
sled_cryptostore = ["matrix-sdk-sled/crypto-store", "encryption"]
sled-state-store = ["matrix-sdk-sled/state-store"]
sled-crypto-store = ["matrix-sdk-sled/crypto-store", "encryption"]
markdown = ["ruma/markdown"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls"]
socks = ["reqwest/socks"]
sso_login = ["warp", "rand", "tokio-stream"]
sso-login = ["warp", "rand", "tokio-stream"]
appservice = ["ruma/appservice-api-s", "ruma/appservice-api-helper"]
image_proc = ["image"]
image_rayon = ["image_proc", "image/jpeg_rayon"]
image-proc = ["image"]
image-rayon = ["image-proc", "image/jpeg_rayon"]
docsrs = [
"encryption",
"sled_cryptostore",
"sled_state_store",
"sso_login",
"sled-crypto-store",
"sled-state-store",
"sso-login",
"qrcode",
"image_proc",
"image-proc",
]
[dependencies]

View File

@@ -59,20 +59,19 @@ More examples can be found in the [examples] directory.
The following crate feature flags are available:
| Feature | Default | Description |
| ------------------ | :-----: | --------------------------------------------------------------------- |
| `anyhow` | No | Better logging for event handlers that return `anyhow::Result` |
| `encryption` | Yes | End-to-end encryption support |
| `eyre` | No | Better logging for event handlers that return `eyre::Result` |
| `image_proc` | No | Enables image processing to generate thumbnails |
| `image_rayon` | No | Enables faster image processing |
| `markdown` | No | Support to send Markdown-formatted messages |
| `qrcode` | Yes | QR code verification support |
| `sled_cryptostore` | Yes | Persistent storage for E2EE related data |
| `sled_statestore` | No | Persistent storage of state data with sled |
| `socks` | No | Enables SOCKS support in the default HTTP client, [`reqwest`] |
| `sso_login` | No | Enables SSO login with a local HTTP server |
| `indexedb_stores` | No | Persistent storage of state & e2ee data with indexeddb for web/wasm32 |
| Feature | Default | Description |
| ------------------- | :-----: | --------------------------------------------------------------------- |
| `anyhow` | No | Better logging for event handlers that return `anyhow::Result` |
| `encryption` | Yes | End-to-end encryption support |
| `eyre` | No | Better logging for event handlers that return `eyre::Result` |
| `image-proc` | No | Enables image processing to generate thumbnails |
| `image-rayon` | No | Enables faster image processing |
| `markdown` | No | Support to send Markdown-formatted messages |
| `qrcode` | Yes | QR code verification support |
| `sled-crypto-store` | Yes | Persistent storage for E2EE related data |
| `sled-state-store` | No | Persistent storage of state data with sled |
| `socks` | No | Enables SOCKS support in the default HTTP client, [`reqwest`] |
| `sso-login` | No | Enables SSO login with a local HTTP server |
[`reqwest`]: https://docs.rs/reqwest/0.11.5/reqwest/index.html

View File

@@ -44,7 +44,7 @@ async fn login_and_sync(
#[allow(unused_mut)]
let mut client_builder = Client::builder().homeserver_url(homeserver_url);
#[cfg(feature = "sled_state_store")]
#[cfg(feature = "sled-state-store")]
{
// The location to save files to
let mut home = dirs::home_dir().expect("no home directory found");
@@ -53,7 +53,7 @@ async fn login_and_sync(
client_builder = client_builder.state_store(Box::new(state_store));
}
#[cfg(feature = "indexeddb_state_store")]
#[cfg(feature = "indexeddb-state-store")]
{
let state_store = matrix_sdk_indexeddb::StateStore::open();
client_builder = client_builder.state_store(Box::new(state_store));

View File

@@ -39,7 +39,7 @@ async fn login_and_sync(
#[allow(unused_mut)]
let mut client_builder = Client::builder().homeserver_url(homeserver_url);
#[cfg(feature = "sled_state_store")]
#[cfg(feature = "sled-state-store")]
{
// The location to save files to
let mut home = dirs::home_dir().expect("no home directory found");
@@ -48,7 +48,7 @@ async fn login_and_sync(
client_builder = client_builder.state_store(Box::new(state_store));
}
#[cfg(feature = "indexeddb_state_store")]
#[cfg(feature = "indexeddb-state-store")]
{
let state_store = matrix_sdk_indexeddb::StateStore::open();
client_builder = client_builder.state_store(Box::new(state_store));

View File

@@ -25,7 +25,7 @@ getrandom = { version = "0.2.4", features = ["js"] }
[dependencies.matrix-sdk]
path = "../.."
default-features = false
features = ["native-tls", "encryption", "indexeddb_state_store", "indexeddb_cryptostore"]
features = ["native-tls", "encryption", "indexeddb-state-store", "indexeddb-crypto-store"]
[workspace]

View File

@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
use std::io::{BufRead, Cursor, Seek};
use std::{io::Read, time::Duration};
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
use image::GenericImageView;
use ruma::{
assign,
@@ -27,7 +27,7 @@ use ruma::{
TransactionId, UInt,
};
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
use crate::ImageError;
/// Base metadata about an image.
@@ -182,9 +182,9 @@ pub struct AttachmentConfig<'a, R: Read> {
pub(crate) txn_id: Option<&'a TransactionId>,
pub(crate) info: Option<AttachmentInfo>,
pub(crate) thumbnail: Option<Thumbnail<'a, R>>,
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
pub(crate) generate_thumbnail: bool,
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
pub(crate) thumbnail_size: Option<(u32, u32)>,
}
@@ -197,9 +197,9 @@ impl AttachmentConfig<'static, &'static [u8]> {
txn_id: Default::default(),
info: Default::default(),
thumbnail: None,
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
generate_thumbnail: Default::default(),
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
thumbnail_size: Default::default(),
}
}
@@ -216,7 +216,7 @@ impl AttachmentConfig<'static, &'static [u8]> {
///
/// * `size` - The size of the thumbnail in pixels as a `(width, height)`
/// tuple. If set to `None`, defaults to `(800, 600)`.
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
#[must_use]
pub fn generate_thumbnail(mut self, size: Option<(u32, u32)>) -> Self {
self.generate_thumbnail = true;
@@ -247,9 +247,9 @@ impl<'a, R: Read> AttachmentConfig<'a, R> {
txn_id: Default::default(),
info: Default::default(),
thumbnail: Some(thumbnail),
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
generate_thumbnail: Default::default(),
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
thumbnail_size: Default::default(),
}
}
@@ -338,7 +338,7 @@ impl<'a, R: Read> AttachmentConfig<'a, R> {
/// }
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
/// ```
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
pub fn generate_image_thumbnail<R: BufRead + Seek>(
content_type: &mime::Mime,
reader: &mut R,

View File

@@ -431,12 +431,12 @@ pub enum ClientBuildError {
Http(#[from] HttpError),
/// Error opening the indexeddb store.
#[cfg(any(feature = "indexeddb_state_store", feature = "indexeddb_cryptostore"))]
#[cfg(any(feature = "indexeddb-state-store", feature = "indexeddb-crypto-store"))]
#[error(transparent)]
IndexeddbStore(#[from] matrix_sdk_indexeddb::OpenStoreError),
/// Error opening the sled store.
#[cfg(any(feature = "sled_state_store", feature = "sled_cryptostore"))]
#[cfg(any(feature = "sled-statehstore", feature = "sled-crypto-store"))]
#[error(transparent)]
SledStore(#[from] matrix_sdk_sled::OpenStoreError),
}

View File

@@ -807,7 +807,7 @@ impl Client {
/// [`get_sso_login_url`]: #method.get_sso_login_url
/// [`login_with_token`]: #method.login_with_token
/// [`restore_login`]: #method.restore_login
#[cfg(all(feature = "sso_login", not(target_arch = "wasm32")))]
#[cfg(all(feature = "sso-login", not(target_arch = "wasm32")))]
#[deny(clippy::future_not_send)]
pub async fn login_with_sso<C>(
&self,
@@ -2406,8 +2406,8 @@ pub(crate) mod test {
assert_eq!(client.homeserver().await, Url::parse(&mockito::server_url()).unwrap());
}
#[cfg(feature = "sso_login")]
#[async_test]
#[cfg(feature = "sso-login")]
async fn login_with_sso() {
let _m_login = mock("POST", "/_matrix/client/r0/login")
.with_status(200)

View File

@@ -218,7 +218,7 @@ is **not** supported using the default store.
| Failure | Cause | Fix |
| ------------------- | ----- | ----------- |
| No messages get encrypted nor decrypted | The `encryption` feature is disabled | [Enable the feature in your `Cargo.toml` file] |
| Messages that were decryptable aren't after a restart | Storage isn't setup to be persistent | Ensure you've activated the persistent storage backend feature, e.g. `sled_state_store` |
| Messages that were decryptable aren't after a restart | Storage isn't setup to be persistent | Ensure you've activated the persistent storage backend feature, e.g. `sled-crypto-store` |
| Messages are encrypted but can't be decrypted | The access token that the client is using is tied to another device | Clear storage to create a new device, read the [Restoring a Client] section |
| Messages don't get encrypted but get decrypted | The `m.room.encryption` event is missing | Make sure encryption is [enabled] for the room and the event isn't [filtered] out, otherwise it might be a deserialization bug |

View File

@@ -165,7 +165,7 @@ pub enum Error {
UserTagName(#[from] InvalidUserTagName),
/// An error while processing images.
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
#[error(transparent)]
ImageError(#[from] ImageError),
}
@@ -272,7 +272,7 @@ impl From<ReqwestError> for Error {
}
/// All possible errors that can happen during image processing.
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
#[derive(Error, Debug)]
pub enum ImageError {
/// Error processing the image data.

View File

@@ -23,11 +23,11 @@ compile_error!("one of 'native-tls' or 'rustls-tls' features must be enabled");
#[cfg(all(feature = "native-tls", feature = "rustls-tls",))]
compile_error!("only one of 'native-tls' or 'rustls-tls' features can be enabled");
#[cfg(all(feature = "sso_login", target_arch = "wasm32"))]
compile_error!("'sso_login' cannot be enabled on 'wasm32' arch");
#[cfg(all(feature = "sso-login", target_arch = "wasm32"))]
compile_error!("'sso-login' cannot be enabled on 'wasm32' arch");
#[cfg(all(feature = "image_rayon", target_arch = "wasm32"))]
compile_error!("'image_rayon' cannot be enabled on 'wasm32' arch");
#[cfg(all(feature = "image-rayon", target_arch = "wasm32"))]
compile_error!("'image-rayon' cannot be enabled on 'wasm32' arch");
pub use bytes;
pub use matrix_sdk_base::{
@@ -58,7 +58,7 @@ pub mod encryption;
pub use account::Account;
pub use client::{Client, ClientBuildError, ClientBuilder, LoopCtrl};
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
pub use error::ImageError;
pub use error::{Error, HttpError, HttpResult, Result};
pub use http_client::HttpSend;

View File

@@ -1,4 +1,4 @@
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
use std::io::Cursor;
#[cfg(feature = "encryption")]
use std::sync::Arc;
@@ -38,7 +38,7 @@ use tracing::debug;
#[cfg(feature = "encryption")]
use tracing::instrument;
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
use crate::{attachment::generate_image_thumbnail, error::ImageError};
use crate::{
attachment::{AttachmentConfig, Thumbnail},
@@ -650,16 +650,16 @@ impl Joined {
) -> Result<send_message_event::v3::Response> {
let reader = &mut BufReader::new(reader);
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
let mut cursor;
if config.thumbnail.is_some() {
self.prepare_and_send_attachment(body, content_type, reader, config).await
} else {
#[cfg(not(feature = "image_proc"))]
#[cfg(not(feature = "image-proc"))]
let thumbnail = Thumbnail::NONE;
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
let thumbnail = if config.generate_thumbnail {
match generate_image_thumbnail(content_type, reader, config.thumbnail_size) {
Ok((thumbnail_data, thumbnail_info)) => {
@@ -688,9 +688,9 @@ impl Joined {
txn_id: config.txn_id,
info: config.info,
thumbnail,
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
generate_thumbnail: false,
#[cfg(feature = "image_proc")]
#[cfg(feature = "image-proc")]
thumbnail_size: None,
};

View File

@@ -16,8 +16,8 @@
//! The re-exports present here depend on the store-related features that are
//! enabled:
//!
//! 1. `sled_state_store` provides a `StateStore`, while
//! `sled_cryptostore` provides also a `CryptoStore` for encryption data. This
//! 1. `sled-state-store` provides a `StateStore`, while
//! `sled-crypto-store` provides also a `CryptoStore` for encryption data. This
//! is the default persistent store implementation for non-WebAssembly.
//! 2. `indexeddb_store` provides both a `StateStore` and a `CryptoStore` if
//! `encryption` is also enabled. This is the default persistent store
@@ -29,9 +29,9 @@
//! [`StoreConfig`]: crate::config::StoreConfig
//! [`ClientBuilder::store_config()`]: crate::ClientBuilder::store_config
#[cfg(any(feature = "indexeddb_state_store", feature = "indexeddb_cryptostore"))]
#[cfg(any(feature = "indexeddb-state-store", feature = "indexeddb-crypto-store"))]
pub use matrix_sdk_indexeddb::*;
#[cfg(any(feature = "sled_state_store", feature = "sled_cryptostore"))]
#[cfg(any(feature = "sled-state-store", feature = "sled-crypto-store"))]
pub use matrix_sdk_sled::*;
// FIXME Move these two methods back to the matrix-sdk-sled crate once weak
@@ -42,18 +42,18 @@ pub use matrix_sdk_sled::*;
/// with the same parameters is also opened.
///
/// [`StoreConfig`]: #crate::config::StoreConfig
#[cfg(any(feature = "sled_state_store", feature = "sled_cryptostore"))]
#[cfg(any(feature = "sled-state-store", feature = "sled-crypto-store"))]
pub fn make_store_config(
path: impl AsRef<std::path::Path>,
passphrase: Option<&str>,
) -> Result<crate::config::StoreConfig, OpenStoreError> {
#[cfg(all(feature = "encryption", feature = "sled_state_store"))]
#[cfg(all(feature = "encryption", feature = "sled-state-store"))]
{
let (state_store, crypto_store) = open_stores_with_path(path, passphrase)?;
Ok(crate::config::StoreConfig::new().state_store(state_store).crypto_store(crypto_store))
}
#[cfg(all(feature = "encryption", not(feature = "sled_state_store")))]
#[cfg(all(feature = "encryption", not(feature = "sled-state-store")))]
{
let crypto_store = CryptoStore::open_with_passphrase(path, passphrase)?;
Ok(crate::config::StoreConfig::new().crypto_store(Box::new(crypto_store)))
@@ -73,7 +73,7 @@ pub fn make_store_config(
/// Create a [`StateStore`] and a [`CryptoStore`] that use the same database and
/// passphrase.
#[cfg(all(feature = "sled_state_store", feature = "sled_cryptostore"))]
#[cfg(all(feature = "sled-state-store", feature = "sled-crypto-store"))]
fn open_stores_with_path(
path: impl AsRef<std::path::Path>,
passphrase: Option<&str>,

View File

@@ -138,17 +138,17 @@ fn run_tests() -> Result<()> {
fn run_feature_tests(cmd: Option<FeatureSet>) -> Result<()> {
let args = BTreeMap::from([
(FeatureSet::NoEncryption, "--no-default-features --features sled_state_store,native-tls"),
(FeatureSet::NoEncryption, "--no-default-features --features sled-state-store,native-tls"),
(FeatureSet::NoSled, "--no-default-features --features encryption,native-tls"),
(FeatureSet::NoEncryptionAndSled, "--no-default-features --features native-tls"),
(
FeatureSet::SledCryptostore,
"--no-default-features --features encryption,sled_cryptostore,native-tls",
"--no-default-features --features encryption,sled-crypto-store,native-tls",
),
(FeatureSet::RustlsTls, "--no-default-features --features rustls-tls"),
(FeatureSet::Markdown, "--features markdown"),
(FeatureSet::Socks, "--features socks"),
(FeatureSet::SsoLogin, "--features sso_login"),
(FeatureSet::SsoLogin, "--features sso-login"),
]);
let run = |arg_set: &str| {
@@ -193,14 +193,14 @@ fn run_wasm_checks(cmd: Option<WasmFeatureSet>) -> Result<()> {
WasmFeatureSet::MatrixSdkNoDefault,
"-p matrix-sdk \
--no-default-features \
--features qrcode,encryption,indexeddb_state_store,indexeddb_cryptostore,rustls-tls",
--features qrcode,encryption,indexeddb-state-store,indexeddb-crypto-store,rustls-tls",
),
(WasmFeatureSet::MatrixSdkBase, "-p matrix-sdk-base"),
(WasmFeatureSet::MatrixSdkCommon, "-p matrix-sdk-common"),
(WasmFeatureSet::MatrixSdkCrypto, "-p matrix-sdk-crypto"),
(
WasmFeatureSet::MatrixSdkIndexeddbStores,
"-p matrix-sdk --no-default-features --features indexeddb_state_store,indexeddb_cryptostore,encryption,rustls-tls",
"-p matrix-sdk --no-default-features --features indexeddb-state-store,indexeddb-crypto-store,encryption,rustls-tls",
),
]);