From 37ee8b70bae3c27c738f45ec883a6f98a44ed46a Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Thu, 15 Aug 2024 18:54:59 +0100 Subject: [PATCH] Split up librqbit http_api and tracing_subscriber into separate features (#188) * fix lints that were under features * Split up some features and fix desktop * fix github script * fix github script * fix github script * try caching check-desktop --- .github/workflows/test.yml | 12 ++++++++++++ Cargo.lock | 11 ++++------- crates/librqbit/Cargo.toml | 12 +++++------- crates/librqbit/build.rs | 1 + crates/librqbit/src/api.rs | 15 +++++++++++---- crates/librqbit/src/api_error.rs | 2 ++ crates/librqbit/src/http_api.rs | 4 +++- crates/librqbit/src/lib.rs | 3 +++ crates/rqbit/Cargo.toml | 7 +++++-- desktop/src-tauri/Cargo.lock | 10 +++++----- desktop/src-tauri/Cargo.toml | 6 +++++- desktop/src-tauri/src/main.rs | 18 +++++++++--------- 12 files changed, 65 insertions(+), 36 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 725931f9c..16af870d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,18 @@ jobs: - run: rustup override set ${{ matrix.rust_version }} - name: cargo check run: cargo check + check-desktop: + runs-on: windows-latest + steps: + - name: rustup toolchain install 1.75 + run: | + rustup toolchain install 1.75 + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + - run: rustup override set 1.75 + - name: cargo check desktop + working-directory: desktop/src-tauri + run: cargo check test: runs-on: windows-latest steps: diff --git a/Cargo.lock b/Cargo.lock index b59ba8719..80d77b8bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1476,7 +1476,6 @@ dependencies = [ "bitvec", "byteorder", "bytes", - "crypto-hash", "dashmap", "futures", "hex 0.4.3", @@ -1494,7 +1493,6 @@ dependencies = [ "lru", "memmap2", "mime_guess", - "openssl", "parking_lot", "rand", "regex", @@ -1504,7 +1502,6 @@ dependencies = [ "serde_json", "serde_urlencoded", "serde_with", - "sha1", "size_format", "sqlx", "tempfile", @@ -2596,9 +2593,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] @@ -2617,9 +2614,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", diff --git a/crates/librqbit/Cargo.toml b/crates/librqbit/Cargo.toml index 27a069571..ac98be7a5 100644 --- a/crates/librqbit/Cargo.toml +++ b/crates/librqbit/Cargo.toml @@ -13,12 +13,14 @@ readme = "README.md" [features] default = ["default-tls"] +http-api = ["axum", "tower-http"] webui = [] timed_existence = [] default-tls = ["reqwest/default-tls"] rust-tls = ["reqwest/rustls-tls"] storage_middleware = ["lru"] storage_examples = [] +tracing-subscriber-utils = ["tracing-subscriber"] postgres = ["sqlx"] [dependencies] @@ -42,8 +44,8 @@ tokio = { version = "1", features = [ "fs", "io-util", ] } -axum = { version = "0.7.4" } -tower-http = { version = "0.5", features = ["cors", "trace"] } +axum = { version = "0.7.4", optional = true } +tower-http = { version = "0.5", features = ["cors", "trace"], optional = true } tokio-stream = "0.1" serde = { version = "1", features = ["derive"] } serde_json = "1" @@ -64,15 +66,11 @@ parking_lot = "0.12" tracing = "0.1.40" size_format = "1" rand = "0.8" - -openssl = { version = "0.10", optional = true } -crypto-hash = { version = "0.3", optional = true } -sha1 = { version = "0.10", optional = true } tracing-subscriber = { version = "0.3", default-features = false, features = [ "json", "fmt", "env-filter", -] } +], optional = true } uuid = { version = "1.2", features = ["v4"] } futures = "0.3" url = "2" diff --git a/crates/librqbit/build.rs b/crates/librqbit/build.rs index a63a6a0b9..a0e9bc0db 100644 --- a/crates/librqbit/build.rs +++ b/crates/librqbit/build.rs @@ -2,6 +2,7 @@ use anyhow::{bail, Context}; use std::path::Path; use std::process::Command; +#[allow(dead_code)] fn run_cmd(cwd: &Path, cmd: &str) -> anyhow::Result<()> { #[cfg(target_os = "windows")] let (shell, shell_args) = ("powershell", ["-command"].as_slice()); diff --git a/crates/librqbit/src/api.rs b/crates/librqbit/src/api.rs index f795cb76e..4bbfdd3e4 100644 --- a/crates/librqbit/src/api.rs +++ b/crates/librqbit/src/api.rs @@ -3,12 +3,10 @@ use std::{collections::HashSet, marker::PhantomData, net::SocketAddr, str::FromS use anyhow::Context; use buffers::ByteBufOwned; use dht::{DhtStats, Id20}; -use futures::Stream; use http::StatusCode; use librqbit_core::torrent_metainfo::TorrentMetaV1Info; use serde::{Deserialize, Serialize}; use tokio::sync::mpsc::UnboundedSender; -use tokio_stream::wrappers::{errors::BroadcastStreamRecvError, BroadcastStream}; use tracing::warn; use crate::{ @@ -20,9 +18,15 @@ use crate::{ peer::stats::snapshot::{PeerStatsFilter, PeerStatsSnapshot}, FileStream, ManagedTorrentHandle, }, - tracing_subscriber_config_utils::LineBroadcast, }; +#[cfg(feature = "tracing-subscriber-utils")] +use crate::tracing_subscriber_config_utils::LineBroadcast; +#[cfg(feature = "tracing-subscriber-utils")] +use futures::Stream; +#[cfg(feature = "tracing-subscriber-utils")] +use tokio_stream::wrappers::{errors::BroadcastStreamRecvError, BroadcastStream}; + pub use crate::torrent_state::stats::{LiveStats, TorrentStats}; pub type Result = std::result::Result; @@ -33,6 +37,7 @@ pub type Result = std::result::Result; pub struct Api { session: Arc, rust_log_reload_tx: Option>, + #[cfg(feature = "tracing-subscriber-utils")] line_broadcast: Option, } @@ -127,11 +132,12 @@ impl Api { pub fn new( session: Arc, rust_log_reload_tx: Option>, - line_broadcast: Option, + #[cfg(feature = "tracing-subscriber-utils")] line_broadcast: Option, ) -> Self { Self { session, rust_log_reload_tx, + #[cfg(feature = "tracing-subscriber-utils")] line_broadcast, } } @@ -258,6 +264,7 @@ impl Api { Ok(Default::default()) } + #[cfg(feature = "tracing-subscriber-utils")] pub fn api_log_lines_stream( &self, ) -> Result< diff --git a/crates/librqbit/src/api_error.rs b/crates/librqbit/src/api_error.rs index 57108171c..b3822f1d3 100644 --- a/crates/librqbit/src/api_error.rs +++ b/crates/librqbit/src/api_error.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "http-api")] use axum::response::{IntoResponse, Response}; use http::StatusCode; use serde::{Serialize, Serializer}; @@ -147,6 +148,7 @@ impl std::fmt::Display for ApiError { } } +#[cfg(feature = "http-api")] impl IntoResponse for ApiError { fn into_response(self) -> Response { let mut response = axum::Json(&self).into_response(); diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index c1f0ed251..4fbeacdff 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -1,7 +1,7 @@ use anyhow::Context; use axum::body::Bytes; use axum::extract::{Path, Query, State}; -use axum::response::{IntoResponse, Redirect}; +use axum::response::IntoResponse; use axum::routing::{get, post}; use futures::future::BoxFuture; use futures::{FutureExt, TryStreamExt}; @@ -459,6 +459,8 @@ impl HttpApi { #[cfg(feature = "webui")] { + use axum::response::Redirect; + let webui_router = Router::new() .route( "/", diff --git a/crates/librqbit/src/lib.rs b/crates/librqbit/src/lib.rs index 1f66a3bd5..e6a5a2761 100644 --- a/crates/librqbit/src/lib.rs +++ b/crates/librqbit/src/lib.rs @@ -32,7 +32,9 @@ mod create_torrent_file; mod dht_utils; pub mod file_info; mod file_ops; +#[cfg(feature = "http-api")] pub mod http_api; +#[cfg(feature = "http-api")] pub mod http_api_client; mod merge_streams; mod peer_connection; @@ -44,6 +46,7 @@ mod spawn_utils; pub mod storage; mod stream_connect; mod torrent_state; +#[cfg(feature = "tracing-subscriber-utils")] pub mod tracing_subscriber_config_utils; mod type_aliases; diff --git a/crates/rqbit/Cargo.toml b/crates/rqbit/Cargo.toml index 228a518d5..77092eed8 100644 --- a/crates/rqbit/Cargo.toml +++ b/crates/rqbit/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["default-tls", "webui", "postgres"] +default = ["default-tls", "postgres", "webui"] openssl-vendored = ["openssl/vendored"] tokio-console = ["console-subscriber", "tokio/tracing"] webui = ["librqbit/webui"] @@ -23,7 +23,10 @@ debug_slow_disk = ["librqbit/storage_middleware"] postgres = ["librqbit/postgres"] [dependencies] -librqbit = { path = "../librqbit", default-features = false, version = "7.0.0-beta.0" } +librqbit = { path = "../librqbit", default-features = false, features = [ + "http-api", + "tracing-subscriber-utils", +], version = "7.0.0-beta.0" } tokio = { version = "1", features = ["macros", "rt-multi-thread"] } console-subscriber = { version = "0.2", optional = true } anyhow = "1" diff --git a/desktop/src-tauri/Cargo.lock b/desktop/src-tauri/Cargo.lock index d2ddd3305..2814267df 100644 --- a/desktop/src-tauri/Cargo.lock +++ b/desktop/src-tauri/Cargo.lock @@ -3031,7 +3031,7 @@ dependencies = [ [[package]] name = "rqbit-desktop" -version = "7.0.0-beta.0" +version = "7.0.0" dependencies = [ "anyhow", "base64 0.21.7", @@ -3213,9 +3213,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] @@ -3234,9 +3234,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", diff --git a/desktop/src-tauri/Cargo.toml b/desktop/src-tauri/Cargo.toml index 4a39e462a..c76eea109 100644 --- a/desktop/src-tauri/Cargo.toml +++ b/desktop/src-tauri/Cargo.toml @@ -16,7 +16,11 @@ tauri-build = { version = "1.5", features = [] } tauri = { version = "1.6.7", features = ["shell-open"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -librqbit = { path = "../../crates/librqbit", features = ["webui"] } +librqbit = { path = "../../crates/librqbit", features = [ + "tracing-subscriber-utils", + "http-api", + "webui", +] } tokio = { version = "1.34.0", features = ["rt-multi-thread"] } anyhow = "1.0.75" base64 = "0.21.5" diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 36f6b5311..a8e43067f 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -15,8 +15,8 @@ use config::RqbitDesktopConfig; use http::StatusCode; use librqbit::{ api::{ - ApiAddTorrentResponse, EmptyJsonResponse, TorrentDetailsResponse, TorrentListResponse, - TorrentStats, + ApiAddTorrentResponse, EmptyJsonResponse, TorrentDetailsResponse, TorrentIdOrHash, + TorrentListResponse, TorrentStats, }, dht::PersistentDhtConfig, tracing_subscriber_config_utils::{init_logging, InitLoggingOptions, InitLoggingResult}, @@ -261,7 +261,7 @@ async fn torrent_create_from_base64_file( #[tauri::command] async fn torrent_details( state: tauri::State<'_, State>, - id: usize, + id: TorrentIdOrHash, ) -> Result { state.api()?.api_torrent_details(id) } @@ -269,7 +269,7 @@ async fn torrent_details( #[tauri::command] async fn torrent_stats( state: tauri::State<'_, State>, - id: usize, + id: TorrentIdOrHash, ) -> Result { state.api()?.api_stats_v1(id) } @@ -277,7 +277,7 @@ async fn torrent_stats( #[tauri::command] async fn torrent_action_delete( state: tauri::State<'_, State>, - id: usize, + id: TorrentIdOrHash, ) -> Result { state.api()?.api_torrent_action_delete(id).await } @@ -285,7 +285,7 @@ async fn torrent_action_delete( #[tauri::command] async fn torrent_action_pause( state: tauri::State<'_, State>, - id: usize, + id: TorrentIdOrHash, ) -> Result { state.api()?.api_torrent_action_pause(id).await } @@ -293,7 +293,7 @@ async fn torrent_action_pause( #[tauri::command] async fn torrent_action_forget( state: tauri::State<'_, State>, - id: usize, + id: TorrentIdOrHash, ) -> Result { state.api()?.api_torrent_action_forget(id).await } @@ -301,7 +301,7 @@ async fn torrent_action_forget( #[tauri::command] async fn torrent_action_start( state: tauri::State<'_, State>, - id: usize, + id: TorrentIdOrHash, ) -> Result { state.api()?.api_torrent_action_start(id).await } @@ -309,7 +309,7 @@ async fn torrent_action_start( #[tauri::command] async fn torrent_action_configure( state: tauri::State<'_, State>, - id: usize, + id: TorrentIdOrHash, only_files: Vec, ) -> Result { state