Skip to content

Commit 1204b85

Browse files
committed
WIP rt refactors
1 parent f9ba660 commit 1204b85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2088
-977
lines changed

.github/workflows/sqlx.yml

+21-21
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
strategy:
3434
matrix:
3535
runtime: [async-std, tokio, actix]
36-
tls: [native-tls, rustls]
36+
tls: [native, rustls, none]
3737
steps:
3838
- uses: actions/checkout@v2
3939

@@ -53,22 +53,22 @@ jobs:
5353
args: >
5454
--manifest-path sqlx-core/Cargo.toml
5555
--no-default-features
56-
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
56+
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
5757
5858
- uses: actions-rs/cargo@v1
5959
with:
6060
command: check
6161
args: >
6262
--no-default-features
63-
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }}-${{ matrix.tls }},macros
63+
--features offline,all-databases,all-types,migrate,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }},macros
6464
6565
test:
6666
name: Unit Test
6767
runs-on: ubuntu-20.04
6868
strategy:
6969
matrix:
7070
runtime: [async-std, tokio, actix]
71-
tls: [native-tls, rustls]
71+
tls: [native, rustls, none]
7272
steps:
7373
- uses: actions/checkout@v2
7474

@@ -87,7 +87,7 @@ jobs:
8787
command: test
8888
args: >
8989
--manifest-path sqlx-core/Cargo.toml
90-
--features offline,all-databases,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
90+
--features offline,all-databases,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
9191
9292
cli:
9393
name: CLI Binaries
@@ -139,7 +139,6 @@ jobs:
139139
strategy:
140140
matrix:
141141
runtime: [async-std, tokio, actix]
142-
tls: [native-tls, rustls]
143142
needs: check
144143
steps:
145144
- uses: actions/checkout@v2
@@ -161,7 +160,7 @@ jobs:
161160
command: test
162161
args: >
163162
--no-default-features
164-
--features any,macros,migrate,sqlite,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
163+
--features any,macros,migrate,sqlite,all-types,runtime-${{ matrix.runtime }}
165164
--
166165
--test-threads=1
167166
env:
@@ -176,7 +175,7 @@ jobs:
176175
matrix:
177176
postgres: [14, 10]
178177
runtime: [async-std, tokio, actix]
179-
tls: [native-tls, rustls]
178+
tls: [native, rustls, none]
180179
needs: check
181180
steps:
182181
- uses: actions/checkout@v2
@@ -199,7 +198,7 @@ jobs:
199198
with:
200199
command: build
201200
args: >
202-
--features postgres,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
201+
--features postgres,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
203202
204203
- run: |
205204
docker-compose -f tests/docker-compose.yml run -d -p 5432:5432 --name postgres_${{ matrix.postgres }} postgres_${{ matrix.postgres }}
@@ -210,19 +209,20 @@ jobs:
210209
command: test
211210
args: >
212211
--no-default-features
213-
--features any,postgres,macros,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
212+
--features any,postgres,macros,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
214213
env:
215214
DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx
216215
# FIXME: needed to disable `ltree` tests in Postgres 9.6
217216
# but `PgLTree` should just fall back to text format
218217
RUSTFLAGS: --cfg postgres_${{ matrix.postgres }}
219218

220219
- uses: actions-rs/cargo@v1
220+
if: matrix.tls != 'none'
221221
with:
222222
command: test
223223
args: >
224224
--no-default-features
225-
--features any,postgres,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
225+
--features any,postgres,macros,migrate,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
226226
env:
227227
DATABASE_URL: postgres://postgres:password@localhost:5432/sqlx?sslmode=verify-ca&sslrootcert=.%2Ftests%2Fcerts%2Fca.crt
228228
# FIXME: needed to disable `ltree` tests in Postgres 9.6
@@ -236,7 +236,7 @@ jobs:
236236
matrix:
237237
mysql: [8, 5_7]
238238
runtime: [async-std, tokio, actix]
239-
tls: [native-tls, rustls]
239+
tls: [native, rustls, none]
240240
needs: check
241241
steps:
242242
- uses: actions/checkout@v2
@@ -255,7 +255,7 @@ jobs:
255255
with:
256256
command: build
257257
args: >
258-
--features mysql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
258+
--features mysql,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
259259
260260
- run: docker-compose -f tests/docker-compose.yml run -d -p 3306:3306 mysql_${{ matrix.mysql }}
261261
- run: sleep 60
@@ -265,7 +265,7 @@ jobs:
265265
command: test
266266
args: >
267267
--no-default-features
268-
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
268+
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
269269
env:
270270
DATABASE_URL: mysql://root:password@localhost:3306/sqlx?ssl-mode=disabled
271271

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

@@ -287,7 +287,7 @@ jobs:
287287
matrix:
288288
mariadb: [10_6, 10_3]
289289
runtime: [async-std, tokio, actix]
290-
tls: [native-tls, rustls]
290+
tls: [native, rustls, none]
291291
needs: check
292292
steps:
293293
- uses: actions/checkout@v2
@@ -306,7 +306,7 @@ jobs:
306306
with:
307307
command: build
308308
args: >
309-
--features mysql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
309+
--features mysql,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
310310
311311
- run: docker-compose -f tests/docker-compose.yml run -d -p 3306:3306 mariadb_${{ matrix.mariadb }}
312312
- run: sleep 30
@@ -316,7 +316,7 @@ jobs:
316316
command: test
317317
args: >
318318
--no-default-features
319-
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
319+
--features any,mysql,macros,migrate,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
320320
env:
321321
DATABASE_URL: mysql://root:password@localhost:3306/sqlx
322322

@@ -327,7 +327,7 @@ jobs:
327327
matrix:
328328
mssql: [2019, 2017]
329329
runtime: [async-std, tokio, actix]
330-
tls: [native-tls, rustls]
330+
tls: [native, rustls, none]
331331
needs: check
332332
steps:
333333
- uses: actions/checkout@v2
@@ -346,7 +346,7 @@ jobs:
346346
with:
347347
command: build
348348
args: >
349-
--features mssql,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
349+
--features mssql,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
350350
351351
- run: docker-compose -f tests/docker-compose.yml run -d -p 1433:1433 mssql_${{ matrix.mssql }}
352352
- run: sleep 80 # MSSQL takes a "bit" to startup
@@ -356,6 +356,6 @@ jobs:
356356
command: test
357357
args: >
358358
--no-default-features
359-
--features any,mssql,macros,migrate,all-types,runtime-${{ matrix.runtime }}-${{ matrix.tls }}
359+
--features any,mssql,macros,migrate,all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
360360
env:
361361
DATABASE_URL: mssql://sa:Password123!@localhost/sqlx

Cargo.toml

+21-32
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
members = [
33
".",
44
"sqlx-core",
5-
"sqlx-rt",
65
"sqlx-macros",
76
"sqlx-test",
87
"sqlx-cli",
@@ -45,8 +44,7 @@ default = ["macros", "migrate"]
4544
macros = ["sqlx-macros"]
4645
migrate = ["sqlx-macros/migrate", "sqlx-core/migrate"]
4746

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

5250
# offline building support in `sqlx-macros`
@@ -69,36 +67,28 @@ all-types = [
6967
"git2",
7068
]
7169

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

78-
# actual runtimes
79-
runtime-actix-native-tls = ["runtime-tokio-native-tls"]
80-
runtime-async-std-native-tls = [
81-
"sqlx-core/runtime-async-std-native-tls",
82-
"sqlx-macros/runtime-async-std-native-tls",
83-
"_rt-async-std",
84-
]
85-
runtime-tokio-native-tls = [
86-
"sqlx-core/runtime-tokio-native-tls",
87-
"sqlx-macros/runtime-tokio-native-tls",
88-
"_rt-tokio",
89-
]
75+
# TLS features
76+
# didn't call this `tls-native-tls` because of the annoying tautology
77+
tls-native = ["sqlx-core/tls-native", "sqlx-macros/tls-native"]
78+
tls-rustls = ["sqlx-core/tls-rustls", "sqlx-macros/tls-rustls"]
9079

80+
# No-op feature used by the workflows to compile without TLS enabled. Not meant for general use.
81+
tls-none = []
82+
83+
# Legacy Runtime + TLS features
84+
runtime-actix-native-tls = ["runtime-tokio-native-tls"]
9185
runtime-actix-rustls = ["runtime-tokio-rustls"]
92-
runtime-async-std-rustls = [
93-
"sqlx-core/runtime-async-std-rustls",
94-
"sqlx-macros/runtime-async-std-rustls",
95-
"_rt-async-std",
96-
]
97-
runtime-tokio-rustls = [
98-
"sqlx-core/runtime-tokio-rustls",
99-
"sqlx-macros/runtime-tokio-rustls",
100-
"_rt-tokio",
101-
]
86+
87+
runtime-async-std-native-tls = ["runtime-async-std", "tls-native"]
88+
runtime-async-std-rustls = ["runtime-async-std", "tls-rustls"]
89+
90+
runtime-tokio-native-tls = ["runtime-tokio", "tls-native"]
91+
runtime-tokio-rustls = ["runtime-tokio", "tls-rustls"]
10292

10393
# for conditional compilation
10494
_rt-async-std = []
@@ -137,7 +127,6 @@ async-std = { version = "1.10.0", features = ["attributes"] }
137127
tokio = { version = "1.15.0", features = ["full"] }
138128
dotenvy = "0.15.0"
139129
trybuild = "1.0.53"
140-
sqlx-rt = { path = "./sqlx-rt" }
141130
sqlx-test = { path = "./sqlx-test" }
142131
paste = "1.0.6"
143132
serde = { version = "1.0.132", features = ["derive"] }
@@ -203,7 +192,7 @@ path = "tests/sqlite/derives.rs"
203192
required-features = ["sqlite", "macros"]
204193

205194
[[test]]
206-
name = "sqlcipher"
195+
name = "sqlite-sqlcipher"
207196
path = "tests/sqlite/sqlcipher.rs"
208197
required-features = ["sqlite"]
209198

README.md

+33-6
Original file line numberDiff line numberDiff line change
@@ -123,28 +123,57 @@ SQLx is compatible with the [`async-std`], [`tokio`] and [`actix`] runtimes; and
123123
```toml
124124
# Cargo.toml
125125
[dependencies]
126+
# PICK ONE OF THE FOLLOWING:
127+
128+
# tokio (no TLS)
129+
sqlx = { version = "0.6", features = [ "runtime-tokio" ] }
130+
# tokio + native-tls
131+
sqlx = { version = "0.6", features = [ "runtime-tokio", "tls-native" ] }
126132
# tokio + rustls
127-
sqlx = { version = "0.6", features = [ "runtime-tokio-rustls" ] }
133+
sqlx = { version = "0.6", features = [ "runtime-tokio", "tls-rustls" ] }
134+
135+
# async-std (no TLS)
136+
sqlx = { version = "0.6", features = [ "runtime-async-std" ] }
128137
# async-std + native-tls
129-
sqlx = { version = "0.6", features = [ "runtime-async-std-native-tls" ] }
138+
sqlx = { version = "0.6", features = [ "runtime-async-std", "tls-native" ] }
139+
# async-std + rustls
140+
sqlx = { version = "0.6", features = [ "runtime-async-std", "tls-rustls" ] }
130141
```
131142

132-
<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>
133-
134143
#### Cargo Feature Flags
135144

145+
For backwards-compatibility reasons, the runtime and TLS features can either be chosen together as a single feature,
146+
or separately.
147+
148+
For forward-compatibility, you should use the separate runtime and TLS features as the combination features may
149+
be removed in the future.
150+
151+
- `runtime-async-std`: Use the `async-std` runtime without enabling a TLS backend.
152+
136153
- `runtime-async-std-native-tls`: Use the `async-std` runtime and `native-tls` TLS backend.
137154

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

157+
- `runtime-tokio`: Use the `tokio` runtime without enabling a TLS backend.
158+
140159
- `runtime-tokio-native-tls`: Use the `tokio` runtime and `native-tls` TLS backend.
141160

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

163+
- `runtime-actix`: Use the `actix` runtime without enabling a TLS backend.
164+
144165
- `runtime-actix-native-tls`: Use the `actix` runtime and `native-tls` TLS backend.
145166

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

169+
- Actix-web is fully compatible with Tokio and so a separate runtime feature is no longer needed.
170+
The above three features exist only for backwards compatibility, and are in fact merely aliases to their
171+
`runtime-tokio` counterparts.
172+
173+
- `tls-native`: Use the `native-tls` TLS backend (OpenSSL on *nix, SChannel on Windows, Secure Transport on macOS).
174+
175+
- `tls-rustls`: Use the `rustls` TLS backend (crossplatform backend, only supports TLS 1.2 and 1.3).
176+
148177
- `postgres`: Add support for the Postgres database server.
149178

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

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

180-
- `tls`: Add support for TLS connections.
181-
182209
- `offline`: Enables building the macros in offline mode when a live database is not available (such as CI).
183210
- Requires `sqlx-cli` installed to use. See [sqlx-cli/README.md][readme-offline].
184211

sqlx-bench/Cargo.toml

-5
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@ publish = false
99
runtime-actix-native-tls = ["runtime-tokio-native-tls"]
1010
runtime-async-std-native-tls = [
1111
"sqlx/runtime-async-std-native-tls",
12-
"sqlx-rt/runtime-async-std-native-tls",
1312
]
1413
runtime-tokio-native-tls = [
1514
"sqlx/runtime-tokio-native-tls",
16-
"sqlx-rt/runtime-tokio-native-tls",
1715
]
1816

1917
runtime-actix-rustls = ["runtime-tokio-rustls"]
2018
runtime-async-std-rustls = [
2119
"sqlx/runtime-async-std-rustls",
22-
"sqlx-rt/runtime-async-std-rustls",
2320
]
2421
runtime-tokio-rustls = [
2522
"sqlx/runtime-tokio-rustls",
26-
"sqlx-rt/runtime-tokio-rustls",
2723
]
2824

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

3934
chrono = "0.4.19"
4035

0 commit comments

Comments
 (0)