Skip to content

Commit 46f8400

Browse files
Merge with upstream
2 parents 5d6d698 + 6c324b1 commit 46f8400

File tree

15 files changed

+352
-34
lines changed

15 files changed

+352
-34
lines changed

.github/workflows/sqlx.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-22.04
2222
strategy:
2323
matrix:
24-
runtime: [async-std, tokio]
24+
runtime: [async-global-executor, async-std, tokio]
2525
tls: [native-tls, rustls, none]
2626
steps:
2727
- uses: actions/checkout@v4
@@ -116,7 +116,7 @@ jobs:
116116
runs-on: ubuntu-22.04
117117
strategy:
118118
matrix:
119-
runtime: [async-std, tokio]
119+
runtime: [async-global-executor, async-std, tokio]
120120
linking: [sqlite, sqlite-unbundled]
121121
needs: check
122122
steps:
@@ -183,7 +183,7 @@ jobs:
183183
strategy:
184184
matrix:
185185
postgres: [17, 13]
186-
runtime: [async-std, tokio]
186+
runtime: [async-global-executor, async-std, tokio]
187187
tls: [native-tls, rustls-aws-lc-rs, rustls-ring, none]
188188
needs: check
189189
steps:
@@ -283,7 +283,7 @@ jobs:
283283
strategy:
284284
matrix:
285285
mysql: [8]
286-
runtime: [async-std, tokio]
286+
runtime: [async-global-executor, async-std, tokio]
287287
tls: [native-tls, rustls-aws-lc-rs, rustls-ring, none]
288288
needs: check
289289
steps:
@@ -371,7 +371,7 @@ jobs:
371371
strategy:
372372
matrix:
373373
mariadb: [verylatest, 11_4, 10_11, 10_4]
374-
runtime: [async-std, tokio]
374+
runtime: [async-global-executor, async-std, tokio]
375375
tls: [native-tls, rustls-aws-lc-rs, rustls-ring, none]
376376
needs: check
377377
steps:

Cargo.lock

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ _unstable-all-types = [
7676
]
7777

7878
# Base runtime features without TLS
79+
runtime-async-global-executor = ["_rt-async-global-executor", "sqlx-core/_rt-async-global-executor", "sqlx-macros?/_rt-async-global-executor"]
7980
runtime-async-std = ["_rt-async-std", "sqlx-core/_rt-async-std", "sqlx-macros?/_rt-async-std"]
8081
runtime-tokio = ["_rt-tokio", "sqlx-core/_rt-tokio", "sqlx-macros?/_rt-tokio"]
8182

@@ -92,13 +93,17 @@ tls-none = []
9293

9394
# Legacy Runtime + TLS features
9495

96+
runtime-async-global-executor-native-tls = ["runtime-async-global-executor", "tls-native-tls"]
97+
runtime-async-global-executor-rustls = ["runtime-async-global-executor", "tls-rustls-ring"]
98+
9599
runtime-async-std-native-tls = ["runtime-async-std", "tls-native-tls"]
96100
runtime-async-std-rustls = ["runtime-async-std", "tls-rustls-ring"]
97101

98102
runtime-tokio-native-tls = ["runtime-tokio", "tls-native-tls"]
99103
runtime-tokio-rustls = ["runtime-tokio", "tls-rustls-ring"]
100104

101105
# for conditional compilation
106+
_rt-async-global-executor = []
102107
_rt-async-std = []
103108
_rt-tokio = []
104109
_sqlite = []
@@ -154,6 +159,11 @@ uuid = "1.1.2"
154159
dotenvy = { version = "0.15.0", default-features = false }
155160

156161
# Runtimes
162+
[workspace.dependencies.async-global-executor]
163+
version = "3.1"
164+
default-features = false
165+
features = ["async-io"]
166+
157167
[workspace.dependencies.async-std]
158168
version = "1.12"
159169

sqlx-core/Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ any = []
1919
json = ["serde", "serde_json"]
2020

2121
# for conditional compilation
22-
_rt-async-std = ["async-std", "async-io"]
22+
_rt-async-global-executor = [
23+
"async-global-executor",
24+
"async-io-global-executor",
25+
"async-net",
26+
]
27+
_rt-async-std = ["async-std", "async-io-std"]
2328
_rt-tokio = ["tokio", "tokio-stream"]
2429
_tls-native-tls = ["native-tls"]
2530
_tls-rustls-aws-lc-rs = ["_tls-rustls", "rustls/aws-lc-rs", "webpki-roots"]
@@ -33,6 +38,7 @@ offline = ["serde", "either/serde"]
3338

3439
[dependencies]
3540
# Runtimes
41+
async-global-executor = { workspace = true, optional = true }
3642
async-std = { workspace = true, optional = true }
3743
tokio = { workspace = true, optional = true }
3844

@@ -52,7 +58,9 @@ ipnetwork = { workspace = true, optional = true }
5258
mac_address = { workspace = true, optional = true }
5359
uuid = { workspace = true, optional = true }
5460

55-
async-io = { version = "1.9.0", optional = true }
61+
async-io-global-executor = { package = "async-io", version = "2.2", optional = true }
62+
async-io-std = { package = "async-io", version = "1.9.0", optional = true }
63+
async-net = { package = "async-net", version = "2.0.0", optional = true }
5664
base64 = { version = "0.22.0", default-features = false, features = ["std"] }
5765
bytes = "1.1.0"
5866
chrono = { version = "0.4.34", default-features = false, features = ["clock"], optional = true }

sqlx-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#![allow(clippy::needless_doctest_main, clippy::type_complexity)]
1818
// The only unsafe code in SQLx is that necessary to interact with native APIs like with SQLite,
1919
// and that can live in its own separate driver crate.
20-
#![forbid(unsafe_code)]
20+
// #![forbid(unsafe_code)]
2121
// Allows an API be documented as only available in some specific platforms.
2222
// <https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html>
2323
#![cfg_attr(docsrs, feature(doc_cfg))]

sqlx-core/src/net/socket/mod.rs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,43 @@ pub async fn connect_tcp<Ws: WithSocket>(
202202
return Ok(with_socket.with_socket(stream).await);
203203
}
204204

205+
#[cfg(feature = "_rt-async-global-executor")]
206+
{
207+
use async_io_global_executor::Async;
208+
use async_net::resolve;
209+
use std::net::TcpStream;
210+
211+
let mut last_err = None;
212+
213+
// Loop through all the Socket Addresses that the hostname resolves to
214+
for socket_addr in resolve((host, port)).await? {
215+
let stream = Async::<TcpStream>::connect(socket_addr)
216+
.await
217+
.and_then(|s| {
218+
s.get_ref().set_nodelay(true)?;
219+
Ok(s)
220+
});
221+
match stream {
222+
Ok(stream) => return Ok(with_socket.with_socket(stream).await),
223+
Err(e) => last_err = Some(e),
224+
}
225+
}
226+
227+
// If we reach this point, it means we failed to connect to any of the addresses.
228+
// Return the last error we encountered, or a custom error if the hostname didn't resolve to any address.
229+
return match last_err {
230+
Some(err) => Err(err.into()),
231+
None => Err(io::Error::new(
232+
io::ErrorKind::AddrNotAvailable,
233+
"Hostname did not resolve to any addresses",
234+
)
235+
.into()),
236+
};
237+
}
238+
205239
#[cfg(feature = "_rt-async-std")]
206240
{
207-
use async_io::Async;
241+
use async_io_std::Async;
208242
use async_std::net::ToSocketAddrs;
209243
use std::net::TcpStream;
210244

@@ -226,17 +260,18 @@ pub async fn connect_tcp<Ws: WithSocket>(
226260

227261
// If we reach this point, it means we failed to connect to any of the addresses.
228262
// Return the last error we encountered, or a custom error if the hostname didn't resolve to any address.
229-
match last_err {
263+
return match last_err {
230264
Some(err) => Err(err.into()),
231265
None => Err(io::Error::new(
232266
io::ErrorKind::AddrNotAvailable,
233267
"Hostname did not resolve to any addresses",
234268
)
235269
.into()),
236-
}
270+
};
237271
}
238272

239-
#[cfg(not(feature = "_rt-async-std"))]
273+
#[cfg(not(all(feature = "_rt-async-global-executor", feature = "_rt-async-std")))]
274+
#[allow(unreachable_code)]
240275
{
241276
crate::rt::missing_rt((host, port, with_socket))
242277
}
@@ -260,17 +295,27 @@ pub async fn connect_uds<P: AsRef<Path>, Ws: WithSocket>(
260295
return Ok(with_socket.with_socket(stream).await);
261296
}
262297

298+
#[cfg(feature = "_rt-async-global-executor")]
299+
{
300+
use async_io_global_executor::Async;
301+
use std::os::unix::net::UnixStream;
302+
303+
let stream = Async::<UnixStream>::connect(path).await?;
304+
305+
Ok(with_socket.with_socket(stream).await)
306+
}
307+
263308
#[cfg(feature = "_rt-async-std")]
264309
{
265-
use async_io::Async;
310+
use async_io_std::Async;
266311
use std::os::unix::net::UnixStream;
267312

268313
let stream = Async::<UnixStream>::connect(path).await?;
269314

270315
Ok(with_socket.with_socket(stream).await)
271316
}
272317

273-
#[cfg(not(feature = "_rt-async-std"))]
318+
#[cfg(not(all(feature = "_rt-async-global-executor", feature = "_rt-async-std")))]
274319
{
275320
crate::rt::missing_rt((path, with_socket))
276321
}

0 commit comments

Comments
 (0)