mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-24 17:19:01 +00:00
refactor: remove direct actix-rt support (#1679)
actix- runtime feature flags are now aliases for tokio- flags
This commit is contained in:
parent
9a6d07f10a
commit
7adbb7fefc
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -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"
|
||||
@ -2644,7 +2634,6 @@ dependencies = [
|
||||
name = "sqlx-rt"
|
||||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"actix-rt",
|
||||
"async-native-tls",
|
||||
"async-std",
|
||||
"futures-rustls",
|
||||
|
||||
13
Cargo.toml
13
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 = []
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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 = []
|
||||
|
||||
@ -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? {
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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 = ();
|
||||
|
||||
@ -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<io::Result<()>> {
|
||||
match &mut *self {
|
||||
Socket::Tcp(s) => Pin::new(s).poll_shutdown(cx),
|
||||
|
||||
@ -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<io::Result<()>> {
|
||||
match &mut *self {
|
||||
MaybeTlsStream::Raw(s) => Pin::new(s).poll_shutdown(cx),
|
||||
|
||||
@ -203,7 +203,7 @@ impl<C: DerefMut<Target = PgConnection>> PgCopyIn<C> {
|
||||
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
|
||||
|
||||
@ -20,11 +20,7 @@ default = ["runtime-tokio-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 = []
|
||||
|
||||
|
||||
@ -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");
|
||||
};
|
||||
|
||||
@ -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 }
|
||||
|
||||
@ -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, R>(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};
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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")]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user