From 1cd18f49aa91a271310fbb55c1e08d641d4ba637 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 20 Jul 2022 12:29:36 +0300 Subject: [PATCH 1/5] chore(bindings/apple): Remove now unnecessary debug script module import following module map rename --- bindings/apple/debug_build_xcframework.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings/apple/debug_build_xcframework.sh b/bindings/apple/debug_build_xcframework.sh index 60625dd03..a34673059 100755 --- a/bindings/apple/debug_build_xcframework.sh +++ b/bindings/apple/debug_build_xcframework.sh @@ -84,8 +84,6 @@ if [ "$IS_CI" = false ] ; then echo "Preparing matrix-rust-components-swift" # Debug -> Copy generated files over to ../../../matrix-rust-components-swift - echo "$(printf "import MatrixSDKFFIWrapper\n\n"; cat "${SWIFT_DIR}/sdk.swift")" > "${SWIFT_DIR}/sdk.swift" - rsync -a --delete "${GENERATED_DIR}/MatrixSDKFFI.xcframework" "${SRC_ROOT}/../matrix-rust-components-swift/" rsync -a --delete "${GENERATED_DIR}/swift/" "${SRC_ROOT}/../matrix-rust-components-swift/Sources/MatrixRustSDK" fi From f9bb86c52f62e9eadf0ddaecb4a029fff068300e Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 20 Jul 2022 12:56:42 +0300 Subject: [PATCH 2/5] feat(bindings/sdk-ffi): Allow ffi users to configure tracing and log levels --- bindings/matrix-sdk-ffi/Cargo.toml | 1 + bindings/matrix-sdk-ffi/src/api.udl | 10 ++++++++++ bindings/matrix-sdk-ffi/src/lib.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/bindings/matrix-sdk-ffi/Cargo.toml b/bindings/matrix-sdk-ffi/Cargo.toml index bc2f81bb1..04824f389 100644 --- a/bindings/matrix-sdk-ffi/Cargo.toml +++ b/bindings/matrix-sdk-ffi/Cargo.toml @@ -31,6 +31,7 @@ thiserror = "1.0.30" tokio = { version = "1", features = ["rt-multi-thread", "macros"] } tokio-stream = "0.1.8" tracing = "0.1.32" +tracing-subscriber = { version = "0.3", features = [ "env-filter" ]} # keep in sync with uniffi dependency in matrix-sdk-crypto-ffi, and uniffi_bindgen in ffi CI job uniffi = "0.18.0" uniffi_macros = "0.18.0" diff --git a/bindings/matrix-sdk-ffi/src/api.udl b/bindings/matrix-sdk-ffi/src/api.udl index 2c705695f..1db732a0f 100644 --- a/bindings/matrix-sdk-ffi/src/api.udl +++ b/bindings/matrix-sdk-ffi/src/api.udl @@ -1,9 +1,19 @@ namespace sdk { + void setup_tracing(LogLevel log_level); + MediaSource media_source_from_url(string url); MessageEventContent message_event_content_from_markdown(string md); string gen_transaction_id(); }; +enum LogLevel { + "Trace", + "Debug", + "Info", + "Warn", + "Error", +}; + [Error] interface ClientError { Generic(string msg); diff --git a/bindings/matrix-sdk-ffi/src/lib.rs b/bindings/matrix-sdk-ffi/src/lib.rs index 7fb23d268..f47405d7e 100644 --- a/bindings/matrix-sdk-ffi/src/lib.rs +++ b/bindings/matrix-sdk-ffi/src/lib.rs @@ -17,6 +17,7 @@ use matrix_sdk::Session; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use tokio::runtime::Runtime; +use tracing_subscriber::{fmt, prelude::*, EnvFilter}; pub use uniffi_api::*; pub static RUNTIME: Lazy = @@ -55,3 +56,30 @@ impl From for ClientError { ClientError::Generic { msg: e.to_string() } } } + +pub enum LogLevel { + Trace, + Debug, + Info, + Warn, + Error, +} + +impl LogLevel { + fn as_str(&self) -> &'static str { + match self { + LogLevel::Trace => "trace", + LogLevel::Debug => "debug", + LogLevel::Info => "info", + LogLevel::Warn => "warn", + LogLevel::Error => "error", + } + } +} + +fn setup_tracing(log_level: LogLevel) { + tracing_subscriber::registry() + .with(EnvFilter::new(log_level.as_str())) + .with(fmt::layer().with_ansi(false)) + .init(); +} From 0043de4028744e97850960d391322952fa410ae6 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 20 Jul 2022 13:28:58 +0300 Subject: [PATCH 3/5] Update bindings/matrix-sdk-ffi/Cargo.toml Co-authored-by: Jonas Platte --- bindings/matrix-sdk-ffi/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-ffi/Cargo.toml b/bindings/matrix-sdk-ffi/Cargo.toml index 04824f389..a686272a9 100644 --- a/bindings/matrix-sdk-ffi/Cargo.toml +++ b/bindings/matrix-sdk-ffi/Cargo.toml @@ -31,7 +31,7 @@ thiserror = "1.0.30" tokio = { version = "1", features = ["rt-multi-thread", "macros"] } tokio-stream = "0.1.8" tracing = "0.1.32" -tracing-subscriber = { version = "0.3", features = [ "env-filter" ]} +tracing-subscriber = { version = "0.3", features = ["env-filter"] } # keep in sync with uniffi dependency in matrix-sdk-crypto-ffi, and uniffi_bindgen in ffi CI job uniffi = "0.18.0" uniffi_macros = "0.18.0" From 021bf5507400b97819acd518bdf2981075edd941 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 20 Jul 2022 13:39:15 +0300 Subject: [PATCH 4/5] feat(bindings/sdk-ffi): Expose full tracing configuration string through ffi. --- bindings/matrix-sdk-ffi/src/api.udl | 10 +--------- bindings/matrix-sdk-ffi/src/lib.rs | 24 ++---------------------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/api.udl b/bindings/matrix-sdk-ffi/src/api.udl index 1db732a0f..76d2ada9f 100644 --- a/bindings/matrix-sdk-ffi/src/api.udl +++ b/bindings/matrix-sdk-ffi/src/api.udl @@ -1,19 +1,11 @@ namespace sdk { - void setup_tracing(LogLevel log_level); + void setup_tracing(string configuration); MediaSource media_source_from_url(string url); MessageEventContent message_event_content_from_markdown(string md); string gen_transaction_id(); }; -enum LogLevel { - "Trace", - "Debug", - "Info", - "Warn", - "Error", -}; - [Error] interface ClientError { Generic(string msg); diff --git a/bindings/matrix-sdk-ffi/src/lib.rs b/bindings/matrix-sdk-ffi/src/lib.rs index f47405d7e..db2461303 100644 --- a/bindings/matrix-sdk-ffi/src/lib.rs +++ b/bindings/matrix-sdk-ffi/src/lib.rs @@ -57,29 +57,9 @@ impl From for ClientError { } } -pub enum LogLevel { - Trace, - Debug, - Info, - Warn, - Error, -} - -impl LogLevel { - fn as_str(&self) -> &'static str { - match self { - LogLevel::Trace => "trace", - LogLevel::Debug => "debug", - LogLevel::Info => "info", - LogLevel::Warn => "warn", - LogLevel::Error => "error", - } - } -} - -fn setup_tracing(log_level: LogLevel) { +fn setup_tracing(configuration: String) { tracing_subscriber::registry() - .with(EnvFilter::new(log_level.as_str())) + .with(EnvFilter::new(configuration)) .with(fmt::layer().with_ansi(false)) .init(); } From 5c53a5f6990a9364cb085919ec872d4ff50c2ac5 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 20 Jul 2022 14:53:00 +0300 Subject: [PATCH 5/5] chore(bindings/apple): Remove unnecessary +nightly flag from debug builds --- bindings/apple/debug_build_xcframework.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/apple/debug_build_xcframework.sh b/bindings/apple/debug_build_xcframework.sh index a34673059..ace17ec24 100755 --- a/bindings/apple/debug_build_xcframework.sh +++ b/bindings/apple/debug_build_xcframework.sh @@ -34,7 +34,7 @@ REL_TYPE_DIR="debug" # iOS Simulator arm64 if [ "$ACTIVE_ARCH" = "arm64" ]; then - cargo +nightly build -p matrix-sdk-ffi ${REL_FLAG} --target "aarch64-apple-ios-sim" + cargo build -p matrix-sdk-ffi ${REL_FLAG} --target "aarch64-apple-ios-sim" lipo -create \ "${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \ @@ -42,7 +42,7 @@ if [ "$ACTIVE_ARCH" = "arm64" ]; then # iOS Simulator intel else - cargo +nightly build -p matrix-sdk-ffi ${REL_FLAG} --target "x86_64-apple-ios" + cargo build -p matrix-sdk-ffi ${REL_FLAG} --target "x86_64-apple-ios" lipo -create \ "${TARGET_DIR}/x86_64-apple-ios/${REL_TYPE_DIR}/libmatrix_sdk_ffi.a" \