Skip to content

Commit

Permalink
Rename cargo features in preparation for rustls support
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Oct 20, 2020
1 parent 4bfd7a5 commit 9fb37a2
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 111 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/sqlx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
strategy:
matrix:
postgres: [12, 10, 9_6, 9_5]
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -233,7 +233,7 @@ jobs:
strategy:
matrix:
mysql: [8, 5_7, 5_6]
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -276,7 +276,7 @@ jobs:
strategy:
matrix:
mariadb: [10_5, 10_4, 10_3, 10_2, 10_1]
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -320,7 +320,7 @@ jobs:
strategy:
matrix:
mssql: [2019]
runtime: [async-std, tokio, actix]
runtime: [async-std-native-tls, tokio-native-tls, actix-native-tls]
needs: check
steps:
- uses: actions/checkout@v2
Expand Down
21 changes: 16 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ features = [ "all" ]
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = [ "macros", "runtime-async-std", "migrate" ]
default = [ "macros", "runtime-async-std-native-tls", "migrate" ]
macros = [ "sqlx-macros" ]
migrate = [ "sqlx-macros/migrate", "sqlx-core/migrate" ]

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

# runtime
runtime-async-std = [ "sqlx-core/runtime-async-std", "sqlx-macros/runtime-async-std" ]
runtime-actix = [ "sqlx-core/runtime-actix", "sqlx-macros/runtime-actix" ]
runtime-tokio = [ "sqlx-core/runtime-tokio", "sqlx-macros/runtime-tokio" ]
# previous runtimes, available as features for error messages better than just
# "feature doesn't exist"
runtime-actix = []
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-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-macros/runtime-async-std-native-tls", "_rt-async-std" ]
runtime-tokio-native-tls = [ "sqlx-core/runtime-tokio-native-tls", "sqlx-macros/runtime-tokio-native-tls", "_rt-tokio" ]

# for conditional compilation
_rt-actix = []
_rt-async-std = []
_rt-tokio = []

# database
any = [ "sqlx-core/any" ]
Expand Down
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SQLx is an async, pure Rust<sub>†</sub> SQL crate featuring compile-time check

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

* **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.
* **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)).

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

## Install

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

[`async-std`]: https://github.com/async-rs/async-std
[`tokio`]: https://github.com/tokio-rs/tokio
[`actix`]: https://github.com/actix/actix-net

**async-std**
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:

```toml
# Cargo.toml
[dependencies]
sqlx = "0.4.0-beta.1"
sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runtime-tokio-native-tls", "macros" ] }
```

**tokio**

```toml
# Cargo.toml
[dependencies]
sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runtime-tokio", "macros" ] }
```
<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>

#### Cargo Feature Flags

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

* `runtime-tokio-native-tls`: Use the `tokio` runtime and `native-tls` TLS backend.

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

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

Expand Down
6 changes: 3 additions & 3 deletions sqlx-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2018"
publish = false

[features]
runtime-actix = ["sqlx/runtime-actix", "sqlx-rt/runtime-actix"]
runtime-async-std = ["sqlx/runtime-async-std", "sqlx-rt/runtime-async-std"]
runtime-tokio = ["sqlx/runtime-tokio", "sqlx-rt/runtime-tokio"]
runtime-actix-native-tls = [ "sqlx/runtime-actix-native-tls", "sqlx-rt/runtime-actix-native-tls" ]
runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls" ]
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls", "sqlx-rt/runtime-tokio-native-tls" ]

postgres = ["sqlx/postgres"]

Expand Down
4 changes: 2 additions & 2 deletions sqlx-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ This Cargo project implements various benchmarks for SQLx using
You must choose a runtime to execute the benchmarks on; the feature flags are the same as the `sqlx` crate:

```bash
cargo bench --features runtime-tokio
cargo bench --features runtime-async-std
cargo bench --features runtime-tokio-native-tls
cargo bench --features runtime-async-std-native-tls
```

When complete, the benchmark results will be in `target/criterion/`.
Expand Down
2 changes: 1 addition & 1 deletion sqlx-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ path = "src/bin/cargo-sqlx.rs"
[dependencies]
dotenv = "0.15"
tokio = { version = "0.2", features = ["macros"] }
sqlx = { version = "0.4.0-beta.1", path = "..", default-features = false, features = [ "runtime-async-std", "migrate", "any", "offline" ] }
sqlx = { version = "0.4.0-beta.1", path = "..", default-features = false, features = [ "runtime-async-std-native-tls", "migrate", "any", "offline" ] }
futures = "0.3"
clap = "=3.0.0-beta.2"
chrono = "0.4"
Expand Down
13 changes: 9 additions & 4 deletions sqlx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ authors = [
features = ["all-databases", "all-types", "offline"]

[features]
default = [ "runtime-async-std", "migrate" ]
default = [ "runtime-async-std-native-tls", "migrate" ]
migrate = [ "sha2", "crc" ]

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

# runtimes
runtime-async-std = [ "sqlx-rt/runtime-async-std" ]
runtime-tokio = [ "sqlx-rt/runtime-tokio" ]
runtime-actix = [ "sqlx-rt/runtime-actix" ]
runtime-actix-native-tls = [ "sqlx-rt/runtime-actix-native-tls", "_rt-actix" ]
runtime-async-std-native-tls = [ "sqlx-rt/runtime-async-std-native-tls", "_rt-async-std" ]
runtime-tokio-native-tls = [ "sqlx-rt/runtime-tokio-native-tls", "_rt-tokio" ]

# for conditional compilation
_rt-actix = []
_rt-async-std = []
_rt-tokio = []

# support offline/decoupled building (enables serialization of `Describe`)
offline = [ "serde", "either/serde" ]
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/mysql/connection/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ async fn upgrade(stream: &mut MySqlStream, options: &MySqlConnectOptions) -> Res
}
}

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

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

stream.upgrade(&options.host, connector.into()).await?;
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/mysql/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub use ssl_mode::MySqlSslMode;
/// # use sqlx_core::mysql::{MySqlConnectOptions, MySqlConnection, MySqlSslMode};
/// #
/// # fn main() {
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
/// // URI connection string
/// let conn = MySqlConnection::connect("mysql://root:password@localhost/db").await?;
Expand Down
8 changes: 4 additions & 4 deletions sqlx-core/src/net/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl AsyncRead for Socket {
}
}

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

#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", 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),
Expand All @@ -112,7 +112,7 @@ impl AsyncWrite for Socket {
}
}

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

#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
fn poll_write_buf<B>(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand Down
16 changes: 8 additions & 8 deletions sqlx-core/src/net/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
}
}

#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", feature = "_rt-tokio"))]
fn poll_read_buf<B>(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand Down Expand Up @@ -117,7 +117,7 @@ where
}
}

#[cfg(any(feature = "runtime-actix", feature = "runtime-tokio"))]
#[cfg(any(feature = "_rt-actix", 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),
Expand All @@ -127,7 +127,7 @@ where
}
}

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

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

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

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

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

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

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

MaybeTlsStream::Upgrading => panic!(io::Error::from(io::ErrorKind::ConnectionAborted)),
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/postgres/connection/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ async fn upgrade(stream: &mut PgStream, options: &PgConnectOptions) -> Result<bo
}
}

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

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

stream.upgrade(&options.host, connector.into()).await?;
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/postgres/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl PgListener {
/// # use sqlx_core::postgres::PgListener;
/// # use sqlx_core::error::Error;
/// #
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::block_on::<_, Result<(), Error>>(async move {
/// # let mut listener = PgListener::connect("postgres:// ...").await?;
/// loop {
Expand Down Expand Up @@ -183,7 +183,7 @@ impl PgListener {
/// # use sqlx_core::postgres::PgListener;
/// # use sqlx_core::error::Error;
/// #
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::block_on::<_, Result<(), Error>>(async move {
/// # let mut listener = PgListener::connect("postgres:// ...").await?;
/// loop {
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/postgres/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub use ssl_mode::PgSslMode;
/// # use sqlx_core::postgres::{PgConnectOptions, PgConnection, PgSslMode};
/// #
/// # fn main() {
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
/// // URI connection string
/// let conn = PgConnection::connect("postgres://localhost/mydb").await?;
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/sqlite/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::{borrow::Cow, time::Duration};
/// use std::str::FromStr;
///
/// # fn main() {
/// # #[cfg(feature = "runtime-async-std")]
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
/// let conn = SqliteConnectOptions::from_str("sqlite://data.db")?
/// .journal_mode(SqliteJournalMode::Wal)
Expand Down
13 changes: 9 additions & 4 deletions sqlx-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ authors = [
proc-macro = true

[features]
default = [ "runtime-async-std", "migrate" ]
default = [ "runtime-async-std-native-tls", "migrate" ]
migrate = [ "sha2" ]

# runtimes
runtime-async-std = [ "sqlx-core/runtime-async-std", "sqlx-rt/runtime-async-std" ]
runtime-tokio = [ "sqlx-core/runtime-tokio", "sqlx-rt/runtime-tokio" ]
runtime-actix = [ "sqlx-core/runtime-actix", "sqlx-rt/runtime-actix" ]
runtime-actix-native-tls = [ "sqlx-core/runtime-actix-native-tls", "sqlx-rt/runtime-actix-native-tls", "_rt-actix" ]
runtime-async-std-native-tls = [ "sqlx-core/runtime-async-std-native-tls", "sqlx-rt/runtime-async-std-native-tls", "_rt-async-std" ]
runtime-tokio-native-tls = [ "sqlx-core/runtime-tokio-native-tls", "sqlx-rt/runtime-tokio-native-tls", "_rt-tokio" ]

# for conditional compilation
_rt-actix = []
_rt-async-std = []
_rt-tokio = []

# offline building support
offline = ["sqlx-core/offline", "serde", "serde_json", "hex", "sha2"]
Expand Down
Loading

0 comments on commit 9fb37a2

Please sign in to comment.