From 7750cd45bc9cbc05516d6ecf7abf1dacb68c7e4d Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 5 Feb 2022 04:20:35 +0000 Subject: [PATCH] refactor: remove direct actix-rt support actix- runtime feature flags are now aliases for tokio- flags --- Cargo.lock | 11 ---- Cargo.toml | 13 +--- README.md | 4 -- sqlx-bench/Cargo.toml | 10 +-- sqlx-core/Cargo.toml | 15 +---- sqlx-core/src/migrate/source.rs | 2 +- sqlx-core/src/mssql/connection/mod.rs | 2 +- sqlx-core/src/net/mod.rs | 4 +- sqlx-core/src/net/socket.rs | 4 +- sqlx-core/src/net/tls/mod.rs | 2 +- sqlx-core/src/postgres/copy.rs | 2 +- sqlx-macros/Cargo.toml | 13 +--- sqlx-macros/src/lib.rs | 9 --- sqlx-rt/Cargo.toml | 6 +- sqlx-rt/src/lib.rs | 90 +++++---------------------- src/lib.rs | 6 +- tests/postgres/postgres.rs | 2 +- 17 files changed, 34 insertions(+), 161 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ae3b0508f..311db81496 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,16 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "actix-rt" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ea16c295198e958ef31930a6ef37d0fb64e9ca3b6116e6b93a8bdae96ee1000" -dependencies = [ - "futures-core", - "tokio", -] - [[package]] name = "ahash" version = "0.7.6" @@ -2673,7 +2663,6 @@ dependencies = [ name = "sqlx-rt" version = "0.6.0" dependencies = [ - "actix-rt", "async-native-tls", "async-std", "futures-rustls", diff --git a/Cargo.toml b/Cargo.toml index b36bc198d0..3947b9b868 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,11 +75,7 @@ runtime-async-std = [] runtime-tokio = [] # actual runtimes -runtime-actix-native-tls = [ - "sqlx-core/runtime-actix-native-tls", - "sqlx-macros/runtime-actix-native-tls", - "_rt-actix", -] +runtime-actix-native-tls = ["runtime-tokio-native-tls"] runtime-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-macros/runtime-async-std-native-tls", @@ -91,11 +87,7 @@ runtime-tokio-native-tls = [ "_rt-tokio", ] -runtime-actix-rustls = [ - "sqlx-core/runtime-actix-rustls", - "sqlx-macros/runtime-actix-rustls", - "_rt-actix", -] +runtime-actix-rustls = ["runtime-tokio-rustls"] runtime-async-std-rustls = [ "sqlx-core/runtime-async-std-rustls", "sqlx-macros/runtime-async-std-rustls", @@ -108,7 +100,6 @@ runtime-tokio-rustls = [ ] # for conditional compilation -_rt-actix = [] _rt-async-std = [] _rt-tokio = [] diff --git a/README.md b/README.md index 2a36885c25..7eb5292080 100644 --- a/README.md +++ b/README.md @@ -218,10 +218,6 @@ async-std = { version = "1", features = [ "attributes" ] } # Tokio: sqlx = { version = "0.5", features = [ "runtime-tokio-native-tls" , "postgres" ] } tokio = { version = "1", features = ["full"] } - -# Actix-web: -sqlx = { version = "0.5", features = [ "runtime-actix-native-tls" , "postgres" ] } -actix-web = "3" ``` ```rust diff --git a/sqlx-bench/Cargo.toml b/sqlx-bench/Cargo.toml index b09c395c67..b911d82a70 100644 --- a/sqlx-bench/Cargo.toml +++ b/sqlx-bench/Cargo.toml @@ -6,10 +6,7 @@ edition = "2021" publish = false [features] -runtime-actix-native-tls = [ - "sqlx/runtime-actix-native-tls", - "sqlx-rt/runtime-actix-native-tls", -] +runtime-actix-native-tls = ["runtime-tokio-native-tls"] runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls", @@ -19,10 +16,7 @@ runtime-tokio-native-tls = [ "sqlx-rt/runtime-tokio-native-tls", ] -runtime-actix-rustls = [ - "sqlx/runtime-actix-rustls", - "sqlx-rt/runtime-actix-rustls", -] +runtime-actix-rustls = ["runtime-tokio-rustls"] runtime-async-std-rustls = [ "sqlx/runtime-async-std-rustls", "sqlx-rt/runtime-async-std-rustls", diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml index f3689e30b5..aee91bf23f 100644 --- a/sqlx-core/Cargo.toml +++ b/sqlx-core/Cargo.toml @@ -65,12 +65,7 @@ decimal = ["rust_decimal", "num-bigint"] json = ["serde", "serde_json"] # runtimes -runtime-actix-native-tls = [ - "sqlx-rt/runtime-actix-native-tls", - "sqlx/runtime-actix-native-tls", - "_tls-native-tls", - "_rt-actix", -] +runtime-actix-native-tls = ["runtime-tokio-native-tls"] runtime-async-std-native-tls = [ "sqlx-rt/runtime-async-std-native-tls", "sqlx/runtime-async-std-native-tls", @@ -84,12 +79,7 @@ runtime-tokio-native-tls = [ "_rt-tokio", ] -runtime-actix-rustls = [ - "sqlx-rt/runtime-actix-rustls", - "sqlx/runtime-actix-rustls", - "_tls-rustls", - "_rt-actix" -] +runtime-actix-rustls = ['runtime-tokio-rustls'] runtime-async-std-rustls = [ "sqlx-rt/runtime-async-std-rustls", "sqlx/runtime-async-std-rustls", @@ -104,7 +94,6 @@ runtime-tokio-rustls = [ ] # for conditional compilation -_rt-actix = ["tokio-stream"] _rt-async-std = [] _rt-tokio = ["tokio-stream"] _tls-native-tls = [] diff --git a/sqlx-core/src/migrate/source.rs b/sqlx-core/src/migrate/source.rs index 4fde9f09a6..cd0cdca39d 100644 --- a/sqlx-core/src/migrate/source.rs +++ b/sqlx-core/src/migrate/source.rs @@ -24,7 +24,7 @@ impl<'s> MigrationSource<'s> for &'s Path { let mut s = fs::read_dir(self.canonicalize()?).await?; let mut migrations = Vec::new(); - #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] + #[cfg(feature = "_rt-tokio")] let mut s = tokio_stream::wrappers::ReadDirStream::new(s); while let Some(entry) = s.try_next().await? { diff --git a/sqlx-core/src/mssql/connection/mod.rs b/sqlx-core/src/mssql/connection/mod.rs index 9df50b1a93..8585f7cf99 100644 --- a/sqlx-core/src/mssql/connection/mod.rs +++ b/sqlx-core/src/mssql/connection/mod.rs @@ -45,7 +45,7 @@ impl Connection for MssqlConnection { ready(self.stream.shutdown(Shutdown::Both).map_err(Into::into)).boxed() } - #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] + #[cfg(feature = "_rt-tokio")] { use sqlx_rt::AsyncWriteExt; diff --git a/sqlx-core/src/net/mod.rs b/sqlx-core/src/net/mod.rs index 6b8371ef50..429c5f6c44 100644 --- a/sqlx-core/src/net/mod.rs +++ b/sqlx-core/src/net/mod.rs @@ -7,11 +7,11 @@ pub use tls::{CertificateInput, MaybeTlsStream}; #[cfg(feature = "_rt-async-std")] type PollReadBuf<'a> = [u8]; -#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] +#[cfg(feature = "_rt-tokio")] type PollReadBuf<'a> = sqlx_rt::ReadBuf<'a>; #[cfg(feature = "_rt-async-std")] type PollReadOut = usize; -#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] +#[cfg(feature = "_rt-tokio")] type PollReadOut = (); diff --git a/sqlx-core/src/net/socket.rs b/sqlx-core/src/net/socket.rs index f06832a3f8..df345147ff 100644 --- a/sqlx-core/src/net/socket.rs +++ b/sqlx-core/src/net/socket.rs @@ -51,7 +51,7 @@ impl Socket { } } - #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] + #[cfg(feature = "_rt-tokio")] { use sqlx_rt::AsyncWriteExt; @@ -103,7 +103,7 @@ impl AsyncWrite for Socket { } } - #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] + #[cfg(feature = "_rt-tokio")] fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match &mut *self { Socket::Tcp(s) => Pin::new(s).poll_shutdown(cx), diff --git a/sqlx-core/src/net/tls/mod.rs b/sqlx-core/src/net/tls/mod.rs index 7239cc392e..85e5dda7c1 100644 --- a/sqlx-core/src/net/tls/mod.rs +++ b/sqlx-core/src/net/tls/mod.rs @@ -190,7 +190,7 @@ where } } - #[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))] + #[cfg(feature = "_rt-tokio")] fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match &mut *self { MaybeTlsStream::Raw(s) => Pin::new(s).poll_shutdown(cx), diff --git a/sqlx-core/src/postgres/copy.rs b/sqlx-core/src/postgres/copy.rs index ebb44a5f52..0bad775085 100644 --- a/sqlx-core/src/postgres/copy.rs +++ b/sqlx-core/src/postgres/copy.rs @@ -203,7 +203,7 @@ impl> PgCopyIn { loop { let read = match () { // Tokio lets us read into the buffer without zeroing first - #[cfg(any(feature = "runtime-tokio", feature = "runtime-actix"))] + #[cfg(feature = "runtime-tokio")] _ if buf.len() != buf.capacity() => { // in case we have some data in the buffer, which can occur // if the previous write did not fill the buffer diff --git a/sqlx-macros/Cargo.toml b/sqlx-macros/Cargo.toml index 4a86dadb29..c0249566c9 100644 --- a/sqlx-macros/Cargo.toml +++ b/sqlx-macros/Cargo.toml @@ -20,11 +20,7 @@ default = ["runtime-async-std-native-tls", "migrate"] migrate = ["sha2", "sqlx-core/migrate"] # runtimes -runtime-actix-native-tls = [ - "sqlx-core/runtime-actix-native-tls", - "sqlx-rt/runtime-actix-native-tls", - "_rt-actix", -] +runtime-actix-native-tls = ["runtime-tokio-native-tls"] runtime-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls", @@ -36,11 +32,7 @@ runtime-tokio-native-tls = [ "_rt-tokio", ] -runtime-actix-rustls = [ - "sqlx-core/runtime-actix-rustls", - "sqlx-rt/runtime-actix-rustls", - "_rt-actix", -] +runtime-actix-rustls = ["runtime-tokio-rustls"] runtime-async-std-rustls = [ "sqlx-core/runtime-async-std-rustls", "sqlx-rt/runtime-async-std-rustls", @@ -53,7 +45,6 @@ runtime-tokio-rustls = [ ] # for conditional compilation -_rt-actix = [] _rt-async-std = [] _rt-tokio = [] diff --git a/sqlx-macros/src/lib.rs b/sqlx-macros/src/lib.rs index c1f173e655..459879a431 100644 --- a/sqlx-macros/src/lib.rs +++ b/sqlx-macros/src/lib.rs @@ -128,15 +128,6 @@ pub fn test(_attr: TokenStream, input: TokenStream) -> TokenStream { ::sqlx_rt::async_std::task::block_on(async { #body }) } } - } else if cfg!(feature = "_rt-actix") { - quote! { - #[test] - #(#attrs)* - fn #name() #ret { - ::sqlx_rt::actix_rt::System::new() - .block_on(async { #body }) - } - } } else { panic!("one of 'runtime-actix', 'runtime-async-std' or 'runtime-tokio' features must be enabled"); }; diff --git a/sqlx-rt/Cargo.toml b/sqlx-rt/Cargo.toml index 8d98009d89..45fa53abdc 100644 --- a/sqlx-rt/Cargo.toml +++ b/sqlx-rt/Cargo.toml @@ -11,7 +11,7 @@ authors = [ ] [features] -runtime-actix-native-tls = ["_rt-actix", "_tls-native-tls", "tokio-native-tls"] +runtime-actix-native-tls = ["runtime-tokio-native-tls"] runtime-async-std-native-tls = [ "_rt-async-std", "_tls-native-tls", @@ -19,12 +19,11 @@ runtime-async-std-native-tls = [ ] runtime-tokio-native-tls = ["_rt-tokio", "_tls-native-tls", "tokio-native-tls"] -runtime-actix-rustls = ["_rt-actix", "_tls-rustls", "tokio-rustls"] +runtime-actix-rustls = ["runtime-tokio-rustls"] runtime-async-std-rustls = ["_rt-async-std", "_tls-rustls", "futures-rustls"] runtime-tokio-rustls = ["_rt-tokio", "_tls-rustls", "tokio-rustls"] # Not used directly and not re-exported from sqlx -_rt-actix = ["actix-rt", "tokio", "once_cell"] _rt-async-std = ["async-std"] _rt-tokio = ["tokio", "once_cell"] _tls-native-tls = ["native-tls"] @@ -33,7 +32,6 @@ _tls-rustls = [] [dependencies] async-native-tls = { version = "0.4.0", optional = true } futures-rustls = { version = "0.22.0", optional = true } -actix-rt = { version = "2.0.0", default-features = false, optional = true } async-std = { version = "1.7.0", features = ["unstable"], optional = true } tokio-native-tls = { version = "0.3.0", optional = true } tokio-rustls = { version = "0.23.0", optional = true } diff --git a/sqlx-rt/src/lib.rs b/sqlx-rt/src/lib.rs index a9a6f21d64..7df8139407 100644 --- a/sqlx-rt/src/lib.rs +++ b/sqlx-rt/src/lib.rs @@ -1,8 +1,6 @@ #[cfg(not(any( - feature = "runtime-actix-native-tls", feature = "runtime-async-std-native-tls", feature = "runtime-tokio-native-tls", - feature = "runtime-actix-rustls", feature = "runtime-async-std-rustls", feature = "runtime-tokio-rustls", )))] @@ -13,8 +11,6 @@ compile_error!( ); #[cfg(any( - all(feature = "_rt-actix", feature = "_rt-async-std"), - all(feature = "_rt-actix", feature = "_rt-tokio"), all(feature = "_rt-async-std", feature = "_rt-tokio"), all(feature = "_tls-native-tls", feature = "_tls-rustls"), ))] @@ -28,33 +24,23 @@ compile_error!( pub use native_tls; // -// Actix *OR* Tokio +// Tokio // -#[cfg(all( - any(feature = "_rt-tokio", feature = "_rt-actix"), - not(feature = "_rt-async-std"), -))] +#[cfg(all(feature = "_rt-tokio", not(feature = "_rt-async-std")))] pub use tokio::{ self, fs, io::AsyncRead, io::AsyncReadExt, io::AsyncWrite, io::AsyncWriteExt, io::ReadBuf, net::TcpStream, runtime::Handle, sync::Mutex as AsyncMutex, task::spawn, task::yield_now, time::sleep, time::timeout, }; -#[cfg(all( - unix, - any(feature = "_rt-tokio", feature = "_rt-actix"), - not(feature = "_rt-async-std"), -))] +#[cfg(all(unix, feature = "_rt-tokio", not(feature = "_rt-async-std")))] pub use tokio::net::UnixStream; -#[cfg(all( - any(feature = "_rt-tokio", feature = "_rt-actix"), - not(feature = "_rt-async-std"), -))] +#[cfg(all(feature = "_rt-tokio", not(feature = "_rt-async-std")))] pub use tokio_runtime::{block_on, enter_runtime}; -#[cfg(any(feature = "_rt-tokio", feature = "_rt-actix"))] +#[cfg(feature = "_rt-tokio")] mod tokio_runtime { use once_cell::sync::Lazy; use tokio::runtime::{self, Runtime}; @@ -83,26 +69,19 @@ mod tokio_runtime { #[cfg(all( feature = "_tls-native-tls", - any(feature = "_rt-tokio", feature = "_rt-actix"), + feature = "_rt-tokio", not(any(feature = "_tls-rustls", feature = "_rt-async-std")), ))] pub use tokio_native_tls::{TlsConnector, TlsStream}; #[cfg(all( feature = "_tls-rustls", - any(feature = "_rt-tokio", feature = "_rt-actix"), + feature = "_rt-tokio", not(any(feature = "_tls-native-tls", feature = "_rt-async-std")), ))] pub use tokio_rustls::{client::TlsStream, TlsConnector}; -// -// tokio -// - -#[cfg(all( - feature = "_rt-tokio", - not(any(feature = "_rt-actix", feature = "_rt-async-std")), -))] +#[cfg(all(feature = "_rt-tokio", not(feature = "_rt-async-std")))] #[macro_export] macro_rules! blocking { ($($expr:tt)*) => { @@ -111,45 +90,18 @@ macro_rules! blocking { }; } -// -// actix -// - -#[cfg(feature = "_rt-actix")] -pub use actix_rt; - -#[cfg(all( - feature = "_rt-actix", - not(any(feature = "_rt-tokio", feature = "_rt-async-std")), -))] -#[macro_export] -macro_rules! blocking { - ($($expr:tt)*) => { - // spawn_blocking is a re-export from tokio - $crate::actix_rt::task::spawn_blocking(move || { $($expr)* }) - .await - .expect("Blocking task failed to complete.") - }; -} - // // async-std // -#[cfg(all( - feature = "_rt-async-std", - not(any(feature = "_rt-actix", feature = "_rt-tokio")), -))] +#[cfg(all(feature = "_rt-async-std", not(feature = "_rt-tokio")))] pub use async_std::{ self, fs, future::timeout, io::prelude::ReadExt as AsyncReadExt, io::prelude::WriteExt as AsyncWriteExt, io::Read as AsyncRead, io::Write as AsyncWrite, net::TcpStream, sync::Mutex as AsyncMutex, task::sleep, task::spawn, task::yield_now, }; -#[cfg(all( - feature = "_rt-async-std", - not(any(feature = "_rt-actix", feature = "_rt-tokio")), -))] +#[cfg(all(feature = "_rt-async-std", not(feature = "_rt-tokio")))] #[macro_export] macro_rules! blocking { ($($expr:tt)*) => { @@ -157,23 +109,13 @@ macro_rules! blocking { }; } -#[cfg(all( - unix, - feature = "_rt-async-std", - not(any(feature = "_rt-actix", feature = "_rt-tokio")), -))] +#[cfg(all(unix, feature = "_rt-async-std", not(feature = "_rt-tokio")))] pub use async_std::os::unix::net::UnixStream; -#[cfg(all( - feature = "_rt-async-std", - not(any(feature = "_rt-actix", feature = "_rt-tokio")), -))] +#[cfg(all(feature = "_rt-async-std", not(feature = "_rt-tokio")))] pub use async_std::task::block_on; -#[cfg(all( - feature = "_rt-async-std", - not(any(feature = "_rt-actix", feature = "_rt-tokio")), -))] +#[cfg(all(feature = "_rt-async-std", not(feature = "_rt-tokio")))] pub fn enter_runtime(f: F) -> R where F: FnOnce() -> R, @@ -188,10 +130,6 @@ pub use async_native_tls::{TlsConnector, TlsStream}; #[cfg(all( feature = "_tls-rustls", feature = "_rt-async-std", - not(any( - feature = "_tls-native-tls", - feature = "_rt-tokio", - feature = "_rt-actix" - )), + not(any(feature = "_tls-native-tls", feature = "_rt-tokio")), ))] pub use futures_rustls::{client::TlsStream, TlsConnector}; diff --git a/src/lib.rs b/src/lib.rs index 6a08bd1ac0..a017f323dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,6 @@ #![cfg_attr(docsrs, feature(doc_cfg))] -#[cfg(any( - feature = "runtime-actix", - feature = "runtime-async-std", - feature = "runtime-tokio" -))] +#[cfg(any(feature = "runtime-async-std", feature = "runtime-tokio"))] compile_error!( "the features 'runtime-actix', 'runtime-async-std' and 'runtime-tokio' have been removed in favor of new features 'runtime-{rt}-{tls}' where rt is one of 'actix', 'async-std' and 'tokio' diff --git a/tests/postgres/postgres.rs b/tests/postgres/postgres.rs index 30f06b5972..a796ec196d 100644 --- a/tests/postgres/postgres.rs +++ b/tests/postgres/postgres.rs @@ -938,7 +938,7 @@ from (values (null)) vals(val) #[sqlx_macros::test] async fn test_listener_cleanup() -> anyhow::Result<()> { - #[cfg(any(feature = "_rt-tokio", feature = "_rt-actix"))] + #[cfg(feature = "_rt-tokio")] use tokio::time::timeout; #[cfg(feature = "_rt-async-std")]