Skip to content

Commit 01ef8b1

Browse files
committed
[WIP] Add rustls support
1 parent 9fb37a2 commit 01ef8b1

File tree

10 files changed

+154
-14
lines changed

10 files changed

+154
-14
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ runtime-actix-native-tls = [ "sqlx-core/runtime-actix-native-tls", "sqlx-macros/
6363
runtime-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-macros/runtime-async-std-native-tls", "_rt-async-std" ]
6464
runtime-tokio-native-tls = [ "sqlx-core/runtime-tokio-native-tls", "sqlx-macros/runtime-tokio-native-tls", "_rt-tokio" ]
6565

66+
runtime-actix-rustls = [ "sqlx-core/runtime-actix-rustls", "sqlx-macros/runtime-actix-rustls", "_rt-actix" ]
67+
runtime-async-std-rustls = [ "sqlx-core/runtime-async-std-rustls", "sqlx-macros/runtime-async-std-rustls", "_rt-async-std" ]
68+
runtime-tokio-rustls = [ "sqlx-core/runtime-tokio-rustls", "sqlx-macros/runtime-tokio-rustls", "_rt-tokio" ]
69+
6670
# for conditional compilation
6771
_rt-actix = []
6872
_rt-async-std = []

README.md

Lines changed: 11 additions & 3 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 different runtimes ([async-std](https://crates.io/crates/async-std) / [tokio](https://crates.io/crates/tokio) / [actix](https://crates.io/crates/actix-rt)).
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)) and TLS backends ([native-tls](https://crates.io/crates/native-tls), [rustls](https://crates.io/crates/rustls)).
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>
@@ -109,12 +109,14 @@ SQLx is compatible with the [`async-std`], [`tokio`] and [`actix`] runtimes.
109109
[`tokio`]: https://github.com/tokio-rs/tokio
110110
[`actix`]: https://github.com/actix/actix-net
111111

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:
112+
You can also select between [`native-tls`] and [`rustls`] for the TLS backend.
113+
114+
By default, you get `async-std` + `native-tls`. If you want a different runtime or TLS backend, just disable the default features and activate the corresponding feature, for example for tokio + rustls:
113115

114116
```toml
115117
# Cargo.toml
116118
[dependencies]
117-
sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runtime-tokio-native-tls", "macros" ] }
119+
sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runtime-tokio-rustls", "macros" ] }
118120
```
119121

120122
<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>
@@ -123,10 +125,16 @@ sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runti
123125

124126
* `runtime-async-std-native-tls` (on by default): Use the `async-std` runtime and `native-tls` TLS backend.
125127

128+
* `runtime-async-std-rustls`: Use the `async-std` runtime and `rustls` TLS backend.
129+
126130
* `runtime-tokio-native-tls`: Use the `tokio` runtime and `native-tls` TLS backend.
127131

132+
* `runtime-tokio-rustls`: Use the `tokio` runtime and `rustls` TLS backend.
133+
128134
* `runtime-actix-native-tls`: Use the `actix` runtime and `native-tls` TLS backend.
129135

136+
* `runtime-actix-rustls`: Use the `actix` runtime and `rustls` TLS backend.
137+
130138
* `postgres`: Add support for the Postgres database server.
131139

132140
* `mysql`: Add support for the MySQL (and MariaDB) database server.

sqlx-bench/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ runtime-actix-native-tls = [ "sqlx/runtime-actix-native-tls", "sqlx-rt/runtime-a
1010
runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls" ]
1111
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls", "sqlx-rt/runtime-tokio-native-tls" ]
1212

13+
runtime-actix-rustls = [ "sqlx/runtime-actix-rustls", "sqlx-rt/runtime-actix-rustls" ]
14+
runtime-async-std-rustls = [ "sqlx/runtime-async-std-rustls", "sqlx-rt/runtime-async-std-rustls" ]
15+
runtime-tokio-rustls = [ "sqlx/runtime-tokio-rustls", "sqlx-rt/runtime-tokio-rustls" ]
16+
1317
postgres = ["sqlx/postgres"]
1418

1519
[dependencies]

sqlx-bench/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ You must choose a runtime to execute the benchmarks on; the feature flags are th
2424

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

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

sqlx-core/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ runtime-actix-native-tls = [ "sqlx-rt/runtime-actix-native-tls", "_rt-actix" ]
3838
runtime-async-std-native-tls = [ "sqlx-rt/runtime-async-std-native-tls", "_rt-async-std" ]
3939
runtime-tokio-native-tls = [ "sqlx-rt/runtime-tokio-native-tls", "_rt-tokio" ]
4040

41+
runtime-actix-rustls = [ "sqlx-rt/runtime-actix-rustls", "_rt-actix" ]
42+
runtime-async-std-rustls = [ "sqlx-rt/runtime-async-std-rustls", "_rt-async-std" ]
43+
runtime-tokio-rustls = [ "sqlx-rt/runtime-tokio-rustls", "_rt-tokio" ]
44+
4145
# for conditional compilation
4246
_rt-actix = []
4347
_rt-async-std = []

sqlx-macros/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ runtime-actix-native-tls = [ "sqlx-core/runtime-actix-native-tls", "sqlx-rt/runt
2424
runtime-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls", "_rt-async-std" ]
2525
runtime-tokio-native-tls = [ "sqlx-core/runtime-tokio-native-tls", "sqlx-rt/runtime-tokio-native-tls", "_rt-tokio" ]
2626

27+
runtime-actix-rustls = [ "sqlx-core/runtime-actix-rustls", "sqlx-rt/runtime-actix-rustls", "_rt-actix" ]
28+
runtime-async-std-rustls = [ "sqlx-core/runtime-async-std-rustls", "sqlx-rt/runtime-async-std-rustls", "_rt-async-std" ]
29+
runtime-tokio-rustls = [ "sqlx-core/runtime-tokio-rustls", "sqlx-rt/runtime-tokio-rustls", "_rt-tokio" ]
30+
2731
# for conditional compilation
2832
_rt-actix = []
2933
_rt-async-std = []

sqlx-rt/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,25 @@ runtime-actix-native-tls = [ "_rt-actix", "_tls-native-tls", "tokio-native-tls"
1515
runtime-async-std-native-tls = [ "_rt-async-std", "_tls-native-tls", "async-native-tls" ]
1616
runtime-tokio-native-tls = [ "_rt-tokio", "_tls-native-tls", "tokio-native-tls" ]
1717

18+
runtime-actix-rustls = [ "_rt-actix", "_tls-rustls", "tokio-rustls" ]
19+
runtime-async-std-rustls = [ "_rt-async-std", "_tls-rustls", "async-rustls" ]
20+
runtime-tokio-rustls = [ "_rt-tokio", "_tls-rustls", "tokio-rustls" ]
21+
1822
# Not used directly and not re-exported from sqlx
1923
_rt-actix = [ "actix-rt", "actix-threadpool", "tokio", "once_cell" ]
2024
_rt-async-std = [ "async-std" ]
2125
_rt-tokio = [ "tokio", "once_cell" ]
2226
_tls-native-tls = [ "native-tls" ]
27+
_tls-rustls = [ ]
2328

2429
[dependencies]
2530
async-native-tls = { version = "0.3.3", optional = true }
31+
async-rustls = { version = "0.1.0", optional = true }
2632
actix-rt = { version = "1.1.1", optional = true }
2733
actix-threadpool = { version = "0.3.2", optional = true }
2834
async-std = { version = "1.6.0", features = [ "unstable" ], optional = true }
2935
tokio = { version = "0.2.21", optional = true, features = [ "blocking", "stream", "fs", "tcp", "uds", "macros", "rt-core", "rt-threaded", "time", "dns", "io-util" ] }
3036
tokio-native-tls = { version = "0.1.0", optional = true }
37+
tokio-rustls = { version = "0.14.0", optional = true }
3138
native-tls = { version = "0.2.4", optional = true }
3239
once_cell = { version = "1.4", features = ["std"], optional = true }

sqlx-rt/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22
feature = "runtime-actix-native-tls",
33
feature = "runtime-async-std-native-tls",
44
feature = "runtime-tokio-native-tls",
5+
feature = "runtime-actix-rustls",
6+
feature = "runtime-async-std-rustls",
7+
feature = "runtime-tokio-rustls",
58
)))]
69
compile_error!(
710
"one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \
8-
'runtime-tokio-native-tls'] must be enabled"
11+
'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', \
12+
'runtime-tokio-rustls'] must be enabled"
913
);
1014

1115
#[cfg(any(
1216
all(feature = "_rt-actix", feature = "_rt-async-std"),
1317
all(feature = "_rt-actix", feature = "_rt-tokio"),
1418
all(feature = "_rt-async-std", feature = "_rt-tokio"),
19+
all(feature = "_tls-native-tls", feature = "_tls-rustls"),
1520
))]
1621
compile_error!(
1722
"only one of ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \
18-
'runtime-tokio-native-tls'] can be enabled"
23+
'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', \
24+
'runtime-tokio-rustls'] can be enabled"
1925
);
2026

21-
#[cfg(all(feature = "_tls-native-tls"))]
27+
#[cfg(all(feature = "_tls-native-tls", not(feature = "_tls-rustls")))]
2228
pub use native_tls::{self, Error as TlsError};
2329

2430
//

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
))]
88
compile_error!(
99
"the features 'runtime-actix', 'runtime-async-std' and 'runtime-tokio' have been removed in
10-
favor of new features 'runtime-{rt}-{tls}' where rt is one of 'actix', 'async-std' and
11-
'tokio'."
10+
favor of new features 'runtime-{rt}-{tls}' where rt is one of 'actix', 'async-std' and 'tokio'
11+
and 'tls' is one of 'native-tls' and 'rustls'."
1212
);
1313

1414
pub use sqlx_core::acquire::Acquire;

0 commit comments

Comments
 (0)