From 845b465f655666b7ac6c9e4620800b069f5b025b Mon Sep 17 00:00:00 2001 From: Akos Vandra Date: Mon, 10 Oct 2022 17:55:36 +0200 Subject: [PATCH 1/3] remove hard dependency for tokio net and tokio signal --- actix-rt/Cargo.toml | 5 +++-- actix-rt/src/lib.rs | 6 ++++-- actix-rt/src/runtime.rs | 9 +++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/actix-rt/Cargo.toml b/actix-rt/Cargo.toml index 10eac079..356c1f09 100644 --- a/actix-rt/Cargo.toml +++ b/actix-rt/Cargo.toml @@ -19,15 +19,16 @@ name = "actix_rt" path = "src/lib.rs" [features] -default = ["macros"] +default = ["macros", "net"] macros = ["actix-macros"] io-uring = ["tokio-uring"] +net = ["tokio/net", "tokio/signal"] [dependencies] actix-macros = { version = "0.2.3", optional = true } futures-core = { version = "0.3", default-features = false } -tokio = { version = "1.13.1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] } +tokio = { version = "1.13.1", features = ["rt", "parking_lot", "sync", "time"] } # runtime for `io-uring` feature [target.'cfg(target_os = "linux")'.dependencies] diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index 23dd01e8..22002b8f 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -69,17 +69,19 @@ pub use self::arbiter::{Arbiter, ArbiterHandle}; pub use self::runtime::Runtime; pub use self::system::{System, SystemRunner}; +#[cfg(feature = "net")] pub mod signal { //! Asynchronous signal handling (Tokio re-exports). #[cfg(unix)] pub mod unix { //! Unix specific signals (Tokio re-exports). - pub use tokio::signal::unix::*; + // pub use tokio::signal::unix::*; } - pub use tokio::signal::ctrl_c; + // pub use tokio::signal::ctrl_c; } +#[cfg(feature = "net")] pub mod net { //! TCP/UDP/Unix bindings (mostly Tokio re-exports). diff --git a/actix-rt/src/runtime.rs b/actix-rt/src/runtime.rs index 557dfcfe..227977fc 100644 --- a/actix-rt/src/runtime.rs +++ b/actix-rt/src/runtime.rs @@ -12,6 +12,7 @@ pub struct Runtime { rt: tokio::runtime::Runtime, } +#[cfg(feature = "net")] pub(crate) fn default_tokio_runtime() -> io::Result { tokio::runtime::Builder::new_current_thread() .enable_io() @@ -19,6 +20,14 @@ pub(crate) fn default_tokio_runtime() -> io::Result { .build() } +#[cfg(not(feature = "net"))] +pub(crate) fn default_tokio_runtime() -> io::Result { + tokio::runtime::Builder::new_current_thread() + .enable_time() + .build() +} + + impl Runtime { /// Returns a new runtime initialized with default configuration values. #[allow(clippy::new_ret_no_self)] From 234758cd5527b6c8994c0a1a1f9488674fef41fb Mon Sep 17 00:00:00 2001 From: Akos Vandra Date: Mon, 10 Oct 2022 17:57:36 +0200 Subject: [PATCH 2/3] fix fmt --- actix-rt/src/runtime.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/actix-rt/src/runtime.rs b/actix-rt/src/runtime.rs index 227977fc..fb0182ea 100644 --- a/actix-rt/src/runtime.rs +++ b/actix-rt/src/runtime.rs @@ -27,7 +27,6 @@ pub(crate) fn default_tokio_runtime() -> io::Result { .build() } - impl Runtime { /// Returns a new runtime initialized with default configuration values. #[allow(clippy::new_ret_no_self)] From 26289b8427153bd2c3fc33f06ddb2383e31e11dd Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 6 Nov 2023 22:27:11 +0000 Subject: [PATCH 3/3] simplify default_tokio_runtime --- actix-rt/src/lib.rs | 5 +++-- actix-rt/src/runtime.rs | 11 +---------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index 39eb4ab5..b06a6cea 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -45,6 +45,7 @@ #![allow(clippy::type_complexity)] #![doc(html_logo_url = "https://actix.rs/img/logo.png")] #![doc(html_favicon_url = "https://actix.rs/favicon.ico")] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #[cfg(all(not(target_os = "linux"), feature = "io-uring"))] compile_error!("io_uring is a linux only feature."); @@ -78,9 +79,9 @@ pub mod signal { #[cfg(unix)] pub mod unix { //! Unix specific signals (Tokio re-exports). - // pub use tokio::signal::unix::*; + pub use tokio::signal::unix::*; } - // pub use tokio::signal::ctrl_c; + pub use tokio::signal::ctrl_c; } #[cfg(feature = "net")] diff --git a/actix-rt/src/runtime.rs b/actix-rt/src/runtime.rs index cac9f962..4b1afd6e 100644 --- a/actix-rt/src/runtime.rs +++ b/actix-rt/src/runtime.rs @@ -12,18 +12,9 @@ pub struct Runtime { rt: tokio::runtime::Runtime, } -#[cfg(feature = "net")] pub(crate) fn default_tokio_runtime() -> io::Result { tokio::runtime::Builder::new_current_thread() - .enable_io() - .enable_time() - .build() -} - -#[cfg(not(feature = "net"))] -pub(crate) fn default_tokio_runtime() -> io::Result { - tokio::runtime::Builder::new_current_thread() - .enable_time() + .enable_all() .build() }