Skip to content

Commit

Permalink
WIP rt refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander committed Sep 15, 2022
1 parent 1379eb6 commit 7f0d1af
Show file tree
Hide file tree
Showing 71 changed files with 2,088 additions and 977 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/sqlx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
matrix:
runtime: [async-std, tokio, actix]
tls: [native-tls, rustls]
tls: [native, rustls, none]
steps:
- uses: actions/checkout@v2

Expand All @@ -53,22 +53,22 @@ jobs:
args: >
--manifest-path sqlx-core/Cargo.toml
--no-default-features
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
- uses: actions-rs/cargo@v1
with:
command: check
args: >
--no-default-features
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }},macros
test:
name: Unit Test
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: [async-std, tokio, actix]
tls: [native-tls, rustls]
tls: [native, rustls, none]
steps:
- uses: actions/checkout@v2

Expand All @@ -87,7 +87,7 @@ jobs:
command: test
args: >
--manifest-path sqlx-core/Cargo.toml
--features offline,all-databases,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features offline,all-databases,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
cli:
name: CLI Binaries
Expand Down Expand Up @@ -139,7 +139,6 @@ jobs:
strategy:
matrix:
runtime: [async-std, tokio, actix]
tls: [native-tls, rustls]
needs: check
steps:
- uses: actions/checkout@v2
Expand All @@ -161,7 +160,7 @@ jobs:
command: test
args: >
--no-default-features
--features any,macros,migrate,sqlite,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features any,macros,migrate,sqlite,all-types,runtime-${{ matrix.runtime }}
--
--test-threads=1
env:
Expand All @@ -176,7 +175,7 @@ jobs:
matrix:
postgres: [14, 10]
runtime: [async-std, tokio, actix]
tls: [native-tls, rustls]
tls: [native, rustls, none]
needs: check
steps:
- uses: actions/checkout@v2
Expand All @@ -199,7 +198,7 @@ jobs:
with:
command: build
args: >
--features postgres,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features postgres,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
- run: |
docker-compose -f tests/docker-compose.yml run -d -p 5432:5432 --name postgres_${{ matrix.postgres }} postgres_${{ matrix.postgres }}
Expand All @@ -210,19 +209,20 @@ jobs:
command: test
args: >
--no-default-features
--features any,postgres,macros,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features any,postgres,macros,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx
# FIXME: needed to disable `ltree` tests in Postgres 9.6
# but `PgLTree` should just fall back to text format
RUSTFLAGS: --cfg postgres_${{ matrix.postgres }}

- uses: actions-rs/cargo@v1
if: matrix.tls != 'none'
with:
command: test
args: >
--no-default-features
--features any,postgres,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features any,postgres,macros,migrate,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx?sslmode=verify-ca&sslrootcert=.%2Ftests%2Fcerts%2Fca.crt
# FIXME: needed to disable `ltree` tests in Postgres 9.6
Expand All @@ -236,7 +236,7 @@ jobs:
matrix:
mysql: [8, 5_7]
runtime: [async-std, tokio, actix]
tls: [native-tls, rustls]
tls: [native, rustls, none]
needs: check
steps:
- uses: actions/checkout@v2
Expand All @@ -255,7 +255,7 @@ jobs:
with:
command: build
args: >
--features mysql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features mysql,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
- run: docker-compose -f tests/docker-compose.yml run -d -p 3306:3306 mysql_${{ matrix.mysql }}
- run: sleep 60
Expand All @@ -265,7 +265,7 @@ jobs:
command: test
args: >
--no-default-features
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root:password@localhost:3306/sqlx?ssl-mode=disabled

Expand All @@ -276,7 +276,7 @@ jobs:
command: test
args: >
--no-default-features
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root:password@localhost:3306/sqlx

Expand All @@ -287,7 +287,7 @@ jobs:
matrix:
mariadb: [10_6, 10_3]
runtime: [async-std, tokio, actix]
tls: [native-tls, rustls]
tls: [native, rustls, none]
needs: check
steps:
- uses: actions/checkout@v2
Expand All @@ -306,7 +306,7 @@ jobs:
with:
command: build
args: >
--features mysql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features mysql,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
- run: docker-compose -f tests/docker-compose.yml run -d -p 3306:3306 mariadb_${{ matrix.mariadb }}
- run: sleep 30
Expand All @@ -316,7 +316,7 @@ jobs:
command: test
args: >
--no-default-features
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root:password@localhost:3306/sqlx

Expand All @@ -327,7 +327,7 @@ jobs:
matrix:
mssql: [2019, 2017]
runtime: [async-std, tokio, actix]
tls: [native-tls, rustls]
tls: [native, rustls, none]
needs: check
steps:
- uses: actions/checkout@v2
Expand All @@ -346,7 +346,7 @@ jobs:
with:
command: build
args: >
--features mssql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features mssql,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
- run: docker-compose -f tests/docker-compose.yml run -d -p 1433:1433 mssql_${{ matrix.mssql }}
- run: sleep 80 # MSSQL takes a "bit" to startup
Expand All @@ -356,6 +356,6 @@ jobs:
command: test
args: >
--no-default-features
--features any,mssql,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
--features any,mssql,macros,migrate,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mssql://sa:Password123!@localhost/sqlx
53 changes: 21 additions & 32 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = [
".",
"sqlx-core",
"sqlx-rt",
"sqlx-macros",
"sqlx-test",
"sqlx-cli",
Expand Down Expand Up @@ -45,8 +44,7 @@ default = ["macros", "migrate"]
macros = ["sqlx-macros"]
migrate = ["sqlx-macros/migrate", "sqlx-core/migrate"]

# [deprecated] TLS is not possible to disable due to it being conditional on multiple features
# Hopefully Cargo can handle this in the future
# [deprecated] enabling TLS requires choosing a specific backend
tls = []

# offline building support in `sqlx-macros`
Expand All @@ -69,36 +67,28 @@ all-types = [
"git2",
]

# previous runtimes, available as features for error messages better than just
# "feature doesn't exist"
runtime-actix = []
runtime-async-std = []
runtime-tokio = []
# Base runtime features without TLS
runtime-actix = ["_rt-tokio", "sqlx-core/runtime-tokio", "sqlx-macros/runtime-tokio"]
runtime-async-std = ["_rt-async-std", "sqlx-core/runtime-async-std", "sqlx-macros/runtime-async-std"]
runtime-tokio = ["_rt-tokio", "sqlx-core/runtime-tokio", "sqlx-macros/runtime-tokio"]

# actual runtimes
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",
"_rt-async-std",
]
runtime-tokio-native-tls = [
"sqlx-core/runtime-tokio-native-tls",
"sqlx-macros/runtime-tokio-native-tls",
"_rt-tokio",
]
# TLS features
# didn't call this `tls-native-tls` because of the annoying tautology
tls-native = ["sqlx-core/tls-native", "sqlx-macros/tls-native"]
tls-rustls = ["sqlx-core/tls-rustls", "sqlx-macros/tls-rustls"]

# No-op feature used by the workflows to compile without TLS enabled. Not meant for general use.
tls-none = []

# Legacy Runtime + TLS features
runtime-actix-native-tls = ["runtime-tokio-native-tls"]
runtime-actix-rustls = ["runtime-tokio-rustls"]
runtime-async-std-rustls = [
"sqlx-core/runtime-async-std-rustls",
"sqlx-macros/runtime-async-std-rustls",
"_rt-async-std",
]
runtime-tokio-rustls = [
"sqlx-core/runtime-tokio-rustls",
"sqlx-macros/runtime-tokio-rustls",
"_rt-tokio",
]

runtime-async-std-native-tls = ["runtime-async-std", "tls-native"]
runtime-async-std-rustls = ["runtime-async-std", "tls-rustls"]

runtime-tokio-native-tls = ["runtime-tokio", "tls-native"]
runtime-tokio-rustls = ["runtime-tokio", "tls-rustls"]

# for conditional compilation
_rt-async-std = []
Expand Down Expand Up @@ -137,7 +127,6 @@ async-std = { version = "1.10.0", features = ["attributes"] }
tokio = { version = "1.15.0", features = ["full"] }
dotenvy = "0.15.0"
trybuild = "1.0.53"
sqlx-rt = { path = "./sqlx-rt" }
sqlx-test = { path = "./sqlx-test" }
paste = "1.0.6"
serde = { version = "1.0.132", features = ["derive"] }
Expand Down Expand Up @@ -203,7 +192,7 @@ path = "tests/sqlite/derives.rs"
required-features = ["sqlite", "macros"]

[[test]]
name = "sqlcipher"
name = "sqlite-sqlcipher"
path = "tests/sqlite/sqlcipher.rs"
required-features = ["sqlite"]

Expand Down
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,57 @@ SQLx is compatible with the [`async-std`], [`tokio`] and [`actix`] runtimes; and
```toml
# Cargo.toml
[dependencies]
# PICK ONE OF THE FOLLOWING:

# tokio (no TLS)
sqlx = { version = "0.6", features = [ "runtime-tokio" ] }
# tokio + native-tls
sqlx = { version = "0.6", features = [ "runtime-tokio", "tls-native" ] }
# tokio + rustls
sqlx = { version = "0.6", features = [ "runtime-tokio-rustls" ] }
sqlx = { version = "0.6", features = [ "runtime-tokio", "tls-rustls" ] }

# async-std (no TLS)
sqlx = { version = "0.6", features = [ "runtime-async-std" ] }
# async-std + native-tls
sqlx = { version = "0.6", features = [ "runtime-async-std-native-tls" ] }
sqlx = { version = "0.6", features = [ "runtime-async-std", "tls-native" ] }
# async-std + rustls
sqlx = { version = "0.6", features = [ "runtime-async-std", "tls-rustls" ] }
```

<small><small>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).</small></small>

#### Cargo Feature Flags

For backwards-compatibility reasons, the runtime and TLS features can either be chosen together as a single feature,
or separately.

For forward-compatibility, you should use the separate runtime and TLS features as the combination features may
be removed in the future.

- `runtime-async-std`: Use the `async-std` runtime without enabling a TLS backend.

- `runtime-async-std-native-tls`: Use the `async-std` runtime and `native-tls` TLS backend.

- `runtime-async-std-rustls`: Use the `async-std` runtime and `rustls` TLS backend.

- `runtime-tokio`: Use the `tokio` runtime without enabling a TLS backend.

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

- `runtime-tokio-rustls`: Use the `tokio` runtime and `rustls` TLS backend.

- `runtime-actix`: Use the `actix` runtime without enabling a TLS backend.

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

- `runtime-actix-rustls`: Use the `actix` runtime and `rustls` TLS backend.

- Actix-web is fully compatible with Tokio and so a separate runtime feature is no longer needed.
The above three features exist only for backwards compatibility, and are in fact merely aliases to their
`runtime-tokio` counterparts.

- `tls-native`: Use the `native-tls` TLS backend (OpenSSL on *nix, SChannel on Windows, Secure Transport on macOS).

- `tls-rustls`: Use the `rustls` TLS backend (crossplatform backend, only supports TLS 1.2 and 1.3).

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

- `mysql`: Add support for the MySQL/MariaDB database server.
Expand Down Expand Up @@ -177,8 +206,6 @@ sqlx = { version = "0.6", features = [ "runtime-async-std-native-tls" ] }

- `json`: Add support for `JSON` and `JSONB` (in postgres) using the `serde_json` crate.

- `tls`: Add support for TLS connections.

- `offline`: Enables building the macros in offline mode when a live database is not available (such as CI).
- Requires `sqlx-cli` installed to use. See [sqlx-cli/README.md][readme-offline].

Expand Down
5 changes: 0 additions & 5 deletions sqlx-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ publish = false
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",
]
runtime-tokio-native-tls = [
"sqlx/runtime-tokio-native-tls",
"sqlx-rt/runtime-tokio-native-tls",
]

runtime-actix-rustls = ["runtime-tokio-rustls"]
runtime-async-std-rustls = [
"sqlx/runtime-async-std-rustls",
"sqlx-rt/runtime-async-std-rustls",
]
runtime-tokio-rustls = [
"sqlx/runtime-tokio-rustls",
"sqlx-rt/runtime-tokio-rustls",
]

postgres = ["sqlx/postgres"]
Expand All @@ -34,7 +30,6 @@ criterion = "0.3.3"
dotenvy = "0.15.0"
once_cell = "1.4"
sqlx = { version = "0.6", path = "../", default-features = false, features = ["macros"] }
sqlx-rt = { version = "0.6", path = "../sqlx-rt", default-features = false }

chrono = "0.4.19"

Expand Down
Loading

0 comments on commit 7f0d1af

Please sign in to comment.