Skip to content

Commit 9fb37a2

Browse files
committed
Rename cargo features in preparation for rustls support
1 parent 4bfd7a5 commit 9fb37a2

File tree

23 files changed

+153
-111
lines changed

23 files changed

+153
-111
lines changed

.github/workflows/sqlx.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
runs-on: ubuntu-20.04
3333
strategy:
3434
matrix:
35-
runtime: [async-std, tokio, actix]
35+
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
3636
steps:
3737
- uses: actions/checkout@v2
3838

@@ -145,7 +145,7 @@ jobs:
145145
runs-on: ubuntu-20.04
146146
strategy:
147147
matrix:
148-
runtime: [async-std, tokio, actix]
148+
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
149149
needs: check
150150
steps:
151151
- uses: actions/checkout@v2
@@ -181,7 +181,7 @@ jobs:
181181
strategy:
182182
matrix:
183183
postgres: [12, 10, 9_6, 9_5]
184-
runtime: [async-std, tokio, actix]
184+
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
185185
needs: check
186186
steps:
187187
- uses: actions/checkout@v2
@@ -233,7 +233,7 @@ jobs:
233233
strategy:
234234
matrix:
235235
mysql: [8, 5_7, 5_6]
236-
runtime: [async-std, tokio, actix]
236+
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
237237
needs: check
238238
steps:
239239
- uses: actions/checkout@v2
@@ -276,7 +276,7 @@ jobs:
276276
strategy:
277277
matrix:
278278
mariadb: [10_5, 10_4, 10_3, 10_2, 10_1]
279-
runtime: [async-std, tokio, actix]
279+
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
280280
needs: check
281281
steps:
282282
- uses: actions/checkout@v2
@@ -320,7 +320,7 @@ jobs:
320320
strategy:
321321
matrix:
322322
mssql: [2019]
323-
runtime: [async-std, tokio, actix]
323+
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
324324
needs: check
325325
steps:
326326
- uses: actions/checkout@v2

Cargo.toml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ features = [ "all" ]
3636
rustdoc-args = ["--cfg", "docsrs"]
3737

3838
[features]
39-
default = [ "macros", "runtime-async-std", "migrate" ]
39+
default = [ "macros", "runtime-async-std-native-tls", "migrate" ]
4040
macros = [ "sqlx-macros" ]
4141
migrate = [ "sqlx-macros/migrate", "sqlx-core/migrate" ]
4242

@@ -52,10 +52,21 @@ all = [ "tls", "all-databases", "all-types" ]
5252
all-databases = [ "mysql", "sqlite", "postgres", "mssql", "any" ]
5353
all-types = [ "bigdecimal", "decimal", "json", "time", "chrono", "ipnetwork", "uuid", "bit-vec" ]
5454

55-
# runtime
56-
runtime-async-std = [ "sqlx-core/runtime-async-std", "sqlx-macros/runtime-async-std" ]
57-
runtime-actix = [ "sqlx-core/runtime-actix", "sqlx-macros/runtime-actix" ]
58-
runtime-tokio = [ "sqlx-core/runtime-tokio", "sqlx-macros/runtime-tokio" ]
55+
# previous runtimes, available as features for error messages better than just
56+
# "feature doesn't exist"
57+
runtime-actix = []
58+
runtime-async-std = []
59+
runtime-tokio = []
60+
61+
# actual runtimes
62+
runtime-actix-native-tls = [ "sqlx-core/runtime-actix-native-tls", "sqlx-macros/runtime-actix-native-tls", "_rt-actix" ]
63+
runtime-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-macros/runtime-async-std-native-tls", "_rt-async-std" ]
64+
runtime-tokio-native-tls = [ "sqlx-core/runtime-tokio-native-tls", "sqlx-macros/runtime-tokio-native-tls", "_rt-tokio" ]
65+
66+
# for conditional compilation
67+
_rt-actix = []
68+
_rt-async-std = []
69+
_rt-tokio = []
5970

6071
# database
6172
any = [ "sqlx-core/any" ]

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ SQLx is an async, pure Rust<sub>†</sub> SQL crate featuring compile-time check
6666

6767
* **Pure Rust**. The Postgres and MySQL/MariaDB drivers are written in pure Rust using **zero** unsafe<sub>††</sub> code.
6868

69-
* **Runtime Agnostic**. Works on [async-std](https://crates.io/crates/async-std) or [tokio](https://crates.io/crates/tokio) with the `runtime-async-std` or `runtime-tokio` cargo feature flag.
69+
* **Runtime Agnostic**. Works on different runtimes ([async-std](https://crates.io/crates/async-std) / [tokio](https://crates.io/crates/tokio) / [actix](https://crates.io/crates/actix-rt)).
7070

7171
<sub><sup>† The SQLite driver uses the libsqlite3 C library as SQLite is an embedded database (the only way
7272
we could be pure Rust for SQLite is by porting _all_ of SQLite to Rust).</sup></sub>
@@ -103,32 +103,29 @@ with C, those interactions are `unsafe`.</sup></sub>
103103

104104
## Install
105105

106-
SQLx is compatible with the [`async-std`] and [`tokio`] runtimes.
106+
SQLx is compatible with the [`async-std`], [`tokio`] and [`actix`] runtimes.
107107

108108
[`async-std`]: https://github.com/async-rs/async-std
109109
[`tokio`]: https://github.com/tokio-rs/tokio
110+
[`actix`]: https://github.com/actix/actix-net
110111

111-
**async-std**
112+
By default, you get `async-std`. If you want a different runtime or TLS backend, just disable the default features and activate the corresponding feature, for example for tokio:
112113

113114
```toml
114115
# Cargo.toml
115116
[dependencies]
116-
sqlx = "0.4.0-beta.1"
117+
sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runtime-tokio-native-tls", "macros" ] }
117118
```
118119

119-
**tokio**
120-
121-
```toml
122-
# Cargo.toml
123-
[dependencies]
124-
sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runtime-tokio", "macros" ] }
125-
```
120+
<sub><sup>The runtime and TLS backend not being separate feature sets to select is a workaround for a [Cargo issue](https://github.com/rust-lang/cargo/issues/3494).</sup></sub>
126121

127122
#### Cargo Feature Flags
128123

129-
* `runtime-async-std` (on by default): Use the `async-std` runtime.
124+
* `runtime-async-std-native-tls` (on by default): Use the `async-std` runtime and `native-tls` TLS backend.
125+
126+
* `runtime-tokio-native-tls`: Use the `tokio` runtime and `native-tls` TLS backend.
130127

131-
* `runtime-tokio`: Use the `tokio` runtime. Mutually exclusive with the `runtime-async-std` feature.
128+
* `runtime-actix-native-tls`: Use the `actix` runtime and `native-tls` TLS backend.
132129

133130
* `postgres`: Add support for the Postgres database server.
134131

sqlx-bench/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ edition = "2018"
66
publish = false
77

88
[features]
9-
runtime-actix = ["sqlx/runtime-actix", "sqlx-rt/runtime-actix"]
10-
runtime-async-std = ["sqlx/runtime-async-std", "sqlx-rt/runtime-async-std"]
11-
runtime-tokio = ["sqlx/runtime-tokio", "sqlx-rt/runtime-tokio"]
9+
runtime-actix-native-tls = [ "sqlx/runtime-actix-native-tls", "sqlx-rt/runtime-actix-native-tls" ]
10+
runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls" ]
11+
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls", "sqlx-rt/runtime-tokio-native-tls" ]
1212

1313
postgres = ["sqlx/postgres"]
1414

sqlx-bench/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ This Cargo project implements various benchmarks for SQLx using
2323
You must choose a runtime to execute the benchmarks on; the feature flags are the same as the `sqlx` crate:
2424

2525
```bash
26-
cargo bench --features runtime-tokio
27-
cargo bench --features runtime-async-std
26+
cargo bench --features runtime-tokio-native-tls
27+
cargo bench --features runtime-async-std-native-tls
2828
```
2929

3030
When complete, the benchmark results will be in `target/criterion/`.

sqlx-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ path = "src/bin/cargo-sqlx.rs"
2727
[dependencies]
2828
dotenv = "0.15"
2929
tokio = { version = "0.2", features = ["macros"] }
30-
sqlx = { version = "0.4.0-beta.1", path = "..", default-features = false, features = [ "runtime-async-std", "migrate", "any", "offline" ] }
30+
sqlx = { version = "0.4.0-beta.1", path = "..", default-features = false, features = [ "runtime-async-std-native-tls", "migrate", "any", "offline" ] }
3131
futures = "0.3"
3232
clap = "=3.0.0-beta.2"
3333
chrono = "0.4"

sqlx-core/Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ authors = [
1616
features = ["all-databases", "all-types", "offline"]
1717

1818
[features]
19-
default = [ "runtime-async-std", "migrate" ]
19+
default = [ "runtime-async-std-native-tls", "migrate" ]
2020
migrate = [ "sha2", "crc" ]
2121

2222
# databases
@@ -34,9 +34,14 @@ decimal = [ "rust_decimal", "num-bigint" ]
3434
json = [ "serde", "serde_json" ]
3535

3636
# runtimes
37-
runtime-async-std = [ "sqlx-rt/runtime-async-std" ]
38-
runtime-tokio = [ "sqlx-rt/runtime-tokio" ]
39-
runtime-actix = [ "sqlx-rt/runtime-actix" ]
37+
runtime-actix-native-tls = [ "sqlx-rt/runtime-actix-native-tls", "_rt-actix" ]
38+
runtime-async-std-native-tls = [ "sqlx-rt/runtime-async-std-native-tls", "_rt-async-std" ]
39+
runtime-tokio-native-tls = [ "sqlx-rt/runtime-tokio-native-tls", "_rt-tokio" ]
40+
41+
# for conditional compilation
42+
_rt-actix = []
43+
_rt-async-std = []
44+
_rt-tokio = []
4045

4146
# support offline/decoupled building (enables serialization of `Describe`)
4247
offline = [ "serde", "either/serde" ]

sqlx-core/src/mysql/connection/tls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ async fn upgrade(stream: &mut MySqlStream, options: &MySqlConnectOptions) -> Res
6767
}
6868
}
6969

70-
#[cfg(not(feature = "runtime-async-std"))]
70+
#[cfg(not(feature = "_rt-async-std"))]
7171
let connector = builder.build().map_err(Error::tls)?;
7272

73-
#[cfg(feature = "runtime-async-std")]
73+
#[cfg(feature = "_rt-async-std")]
7474
let connector = builder;
7575

7676
stream.upgrade(&options.host, connector.into()).await?;

sqlx-core/src/mysql/options/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub use ssl_mode::MySqlSslMode;
3434
/// # use sqlx_core::mysql::{MySqlConnectOptions, MySqlConnection, MySqlSslMode};
3535
/// #
3636
/// # fn main() {
37-
/// # #[cfg(feature = "runtime-async-std")]
37+
/// # #[cfg(feature = "_rt-async-std")]
3838
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
3939
/// // URI connection string
4040
/// let conn = MySqlConnection::connect("mysql://root:password@localhost/db").await?;

sqlx-core/src/net/socket.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl AsyncRead for Socket {
6060
}
6161
}
6262

63-
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
63+
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
6464
fn poll_read_buf<B>(
6565
mut self: Pin<&mut Self>,
6666
cx: &mut Context<'_>,
@@ -102,7 +102,7 @@ impl AsyncWrite for Socket {
102102
}
103103
}
104104

105-
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
105+
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
106106
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
107107
match &mut *self {
108108
Socket::Tcp(s) => Pin::new(s).poll_shutdown(cx),
@@ -112,7 +112,7 @@ impl AsyncWrite for Socket {
112112
}
113113
}
114114

115-
#[cfg(feature = "runtime-async-std")]
115+
#[cfg(feature = "_rt-async-std")]
116116
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
117117
match &mut *self {
118118
Socket::Tcp(s) => Pin::new(s).poll_close(cx),
@@ -122,7 +122,7 @@ impl AsyncWrite for Socket {
122122
}
123123
}
124124

125-
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
125+
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
126126
fn poll_write_buf<B>(
127127
mut self: Pin<&mut Self>,
128128
cx: &mut Context<'_>,

sqlx-core/src/net/tls.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ where
7272
}
7373
}
7474

75-
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
75+
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
7676
fn poll_read_buf<B>(
7777
mut self: Pin<&mut Self>,
7878
cx: &mut Context<'_>,
@@ -117,7 +117,7 @@ where
117117
}
118118
}
119119

120-
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
120+
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
121121
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
122122
match &mut *self {
123123
MaybeTlsStream::Raw(s) => Pin::new(s).poll_shutdown(cx),
@@ -127,7 +127,7 @@ where
127127
}
128128
}
129129

130-
#[cfg(feature = "runtime-async-std")]
130+
#[cfg(feature = "_rt-async-std")]
131131
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
132132
match &mut *self {
133133
MaybeTlsStream::Raw(s) => Pin::new(s).poll_close(cx),
@@ -137,7 +137,7 @@ where
137137
}
138138
}
139139

140-
#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
140+
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
141141
fn poll_write_buf<B>(
142142
mut self: Pin<&mut Self>,
143143
cx: &mut Context<'_>,
@@ -166,10 +166,10 @@ where
166166
match self {
167167
MaybeTlsStream::Raw(s) => s,
168168

169-
#[cfg(not(feature = "runtime-async-std"))]
169+
#[cfg(not(feature = "_rt-async-std"))]
170170
MaybeTlsStream::Tls(s) => s.get_ref().get_ref().get_ref(),
171171

172-
#[cfg(feature = "runtime-async-std")]
172+
#[cfg(feature = "_rt-async-std")]
173173
MaybeTlsStream::Tls(s) => s.get_ref(),
174174

175175
MaybeTlsStream::Upgrading => panic!(io::Error::from(io::ErrorKind::ConnectionAborted)),
@@ -185,10 +185,10 @@ where
185185
match self {
186186
MaybeTlsStream::Raw(s) => s,
187187

188-
#[cfg(not(feature = "runtime-async-std"))]
188+
#[cfg(not(feature = "_rt-async-std"))]
189189
MaybeTlsStream::Tls(s) => s.get_mut().get_mut().get_mut(),
190190

191-
#[cfg(feature = "runtime-async-std")]
191+
#[cfg(feature = "_rt-async-std")]
192192
MaybeTlsStream::Tls(s) => s.get_mut(),
193193

194194
MaybeTlsStream::Upgrading => panic!(io::Error::from(io::ErrorKind::ConnectionAborted)),

sqlx-core/src/postgres/connection/tls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ async fn upgrade(stream: &mut PgStream, options: &PgConnectOptions) -> Result<bo
8484
}
8585
}
8686

87-
#[cfg(not(feature = "runtime-async-std"))]
87+
#[cfg(not(feature = "_rt-async-std"))]
8888
let connector = builder.build().map_err(Error::tls)?;
8989

90-
#[cfg(feature = "runtime-async-std")]
90+
#[cfg(feature = "_rt-async-std")]
9191
let connector = builder;
9292

9393
stream.upgrade(&options.host, connector.into()).await?;

sqlx-core/src/postgres/listener.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl PgListener {
150150
/// # use sqlx_core::postgres::PgListener;
151151
/// # use sqlx_core::error::Error;
152152
/// #
153-
/// # #[cfg(feature = "runtime-async-std")]
153+
/// # #[cfg(feature = "_rt-async-std")]
154154
/// # sqlx_rt::block_on::<_, Result<(), Error>>(async move {
155155
/// # let mut listener = PgListener::connect("postgres:// ...").await?;
156156
/// loop {
@@ -183,7 +183,7 @@ impl PgListener {
183183
/// # use sqlx_core::postgres::PgListener;
184184
/// # use sqlx_core::error::Error;
185185
/// #
186-
/// # #[cfg(feature = "runtime-async-std")]
186+
/// # #[cfg(feature = "_rt-async-std")]
187187
/// # sqlx_rt::block_on::<_, Result<(), Error>>(async move {
188188
/// # let mut listener = PgListener::connect("postgres:// ...").await?;
189189
/// loop {

sqlx-core/src/postgres/options/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub use ssl_mode::PgSslMode;
5454
/// # use sqlx_core::postgres::{PgConnectOptions, PgConnection, PgSslMode};
5555
/// #
5656
/// # fn main() {
57-
/// # #[cfg(feature = "runtime-async-std")]
57+
/// # #[cfg(feature = "_rt-async-std")]
5858
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
5959
/// // URI connection string
6060
/// let conn = PgConnection::connect("postgres://localhost/mydb").await?;

sqlx-core/src/sqlite/options/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::{borrow::Cow, time::Duration};
3030
/// use std::str::FromStr;
3131
///
3232
/// # fn main() {
33-
/// # #[cfg(feature = "runtime-async-std")]
33+
/// # #[cfg(feature = "_rt-async-std")]
3434
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
3535
/// let conn = SqliteConnectOptions::from_str("sqlite://data.db")?
3636
/// .journal_mode(SqliteJournalMode::Wal)

sqlx-macros/Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ authors = [
1616
proc-macro = true
1717

1818
[features]
19-
default = [ "runtime-async-std", "migrate" ]
19+
default = [ "runtime-async-std-native-tls", "migrate" ]
2020
migrate = [ "sha2" ]
2121

2222
# runtimes
23-
runtime-async-std = [ "sqlx-core/runtime-async-std", "sqlx-rt/runtime-async-std" ]
24-
runtime-tokio = [ "sqlx-core/runtime-tokio", "sqlx-rt/runtime-tokio" ]
25-
runtime-actix = [ "sqlx-core/runtime-actix", "sqlx-rt/runtime-actix" ]
23+
runtime-actix-native-tls = [ "sqlx-core/runtime-actix-native-tls", "sqlx-rt/runtime-actix-native-tls", "_rt-actix" ]
24+
runtime-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls", "_rt-async-std" ]
25+
runtime-tokio-native-tls = [ "sqlx-core/runtime-tokio-native-tls", "sqlx-rt/runtime-tokio-native-tls", "_rt-tokio" ]
26+
27+
# for conditional compilation
28+
_rt-actix = []
29+
_rt-async-std = []
30+
_rt-tokio = []
2631

2732
# offline building support
2833
offline = ["sqlx-core/offline", "serde", "serde_json", "hex", "sha2"]

0 commit comments

Comments
 (0)