Skip to content

Commit 92f12e1

Browse files
committed
Add support for Tokio
1 parent 96f14c0 commit 92f12e1

26 files changed

+256
-98
lines changed

.github/workflows/postgres.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ jobs:
5050
# -----------------------------------------------------
5151

5252
# Check that we build with TLS support (TODO: we need a postgres image with SSL certs to test)
53-
- run: cargo check -p sqlx-core --no-default-features --features 'postgres macros uuid chrono tls'
53+
- run: cargo check -p sqlx-core --no-default-features --features 'runtime-async-std postgres macros uuid chrono tls'
5454

55-
- run: cargo test -p sqlx --no-default-features --features 'postgres macros uuid chrono'
55+
# Test on async-std
56+
- run: cargo test -p sqlx --no-default-features --features 'runtime-async-std postgres macros uuid chrono'
57+
env:
58+
DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres
59+
60+
# Test on tokio
61+
- run: cargo test -p sqlx --no-default-features --features 'runtime-tokio postgres macros uuid chrono'
5662
env:
5763
DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres
5864

.github/workflows/rust.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ jobs:
3232

3333
# -----------------------------------------------------
3434

35-
- run: cargo check --all-features
35+
- run: cargo check --no-default-features --features 'chrono uuid postgres mysql macros tls runtime-async-std'
3636

37-
- run: cargo test -p sqlx-core --all-features
37+
- run: cargo check --no-default-features --features 'chrono uuid postgres mysql macros tls runtime-tokio'
38+
39+
- run: cargo test -p sqlx-core --no-default-features --features 'chrono uuid postgres mysql macros tls runtime-async-std'
40+
41+
- run: cargo test -p sqlx-core --no-default-features --features 'chrono uuid postgres mysql macros tls runtime-tokio'
3842

3943
# Rust ------------------------------------------------
4044

Cargo.lock

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ authors = [
2828
all-features = true
2929

3030
[features]
31-
default = [ "macros" ]
31+
default = [ "macros", "runtime-async-std" ]
3232
macros = [ "sqlx-macros" ]
33-
tls = ["sqlx-core/tls"]
33+
tls = [ "sqlx-core/tls" ]
34+
35+
# runtime
36+
runtime-async-std = [ "sqlx-core/runtime-async-std" ]
37+
runtime-tokio = [ "sqlx-core/runtime-tokio" ]
3438

3539
# database
3640
postgres = [ "sqlx-core/postgres", "sqlx-macros/postgres" ]
@@ -49,6 +53,7 @@ anyhow = "1.0.26"
4953
futures = "0.3.1"
5054
env_logger = "0.7"
5155
async-std = { version = "1.4.0", features = [ "attributes" ] }
56+
tokio = { version = "0.2.0", features = [ "full" ] }
5257
dotenv = "0.15.0"
5358

5459
[[test]]

release.toml

Lines changed: 0 additions & 10 deletions
This file was deleted.

sqlx-core/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ default = []
2020
unstable = []
2121
postgres = [ "md-5", "sha2", "base64", "sha-1", "rand", "hmac" ]
2222
mysql = [ "sha-1", "sha2", "generic-array", "num-bigint", "base64", "digest", "rand" ]
23-
tls = ["async-native-tls"]
23+
tls = [ "async-native-tls" ]
24+
runtime-async-std = [ "async-native-tls/runtime-async-std", "async-std" ]
25+
runtime-tokio = [ "async-native-tls/runtime-tokio", "tokio" ]
2426

2527
[dependencies]
26-
async-native-tls = { version = "0.3", optional = true }
27-
async-std = "1.4.0"
28+
async-native-tls = { version = "0.3", default-features = false, optional = true }
29+
async-std = { version = "1.4.0", optional = true }
30+
tokio = { version = "0.2", default-features = false, features = [ "dns", "fs", "time", "tcp" ], optional = true }
2831
async-stream = { version = "0.2.0", default-features = false }
2932
base64 = { version = "0.11.0", default-features = false, optional = true, features = [ "std" ] }
3033
bitflags = { version = "1.2.1", default-features = false }

sqlx-core/release.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

sqlx-core/src/io/buf_stream.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use async_std::io::{
2-
prelude::{ReadExt, WriteExt},
3-
Read, Write,
4-
};
51
use std::io;
62
use std::ops::{Deref, DerefMut};
73

4+
use crate::runtime::{AsyncRead, AsyncReadExt, AsyncWriteExt, AsyncWrite};
5+
86
const RBUF_SIZE: usize = 8 * 1024;
97

108
pub struct BufStream<S> {
@@ -24,7 +22,7 @@ pub struct BufStream<S> {
2422

2523
impl<S> BufStream<S>
2624
where
27-
S: Read + Write + Unpin,
25+
S: AsyncRead + AsyncWrite + Unpin,
2826
{
2927
pub fn new(stream: S) -> Self {
3028
Self {

sqlx-core/src/io/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod buf_stream;
44
mod buf;
55
mod buf_mut;
66
mod byte_str;
7-
87
mod tls;
98

109
pub use self::{

0 commit comments

Comments
 (0)