Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump tokio MSRV to 1.63 #5887

Merged
merged 12 commits into from
Jul 27, 2023
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ env:
# - tokio-util/Cargo.toml
# - tokio-test/Cargo.toml
# - tokio-stream/Cargo.toml
rust_min: 1.56.0
rust_min: 1.63.0

defaults:
run:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,13 @@ When updating this, also update:

Tokio will keep a rolling MSRV (minimum supported rust version) policy of **at
least** 6 months. When increasing the MSRV, the new Rust version must have been
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved
released at least six months ago. The current MSRV is 1.56.0.
released at least six months ago. The current MSRV is 1.63.0.
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved

Note that the MSRV is not increased automatically, and only as part of a minor
release. The MSRV history for past minor releases can be found below:

* 1.27 to now - Rust 1.56
* 1.30 to now - Rust 1.63
* 1.27 to 1.29.1 - Rust 1.56
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved
* 1.17 to 1.26 - Rust 1.49
* 1.15 to 1.16 - Rust 1.46
* 1.0 to 1.14 - Rust 1.45
Expand Down
5 changes: 1 addition & 4 deletions tokio/Cargo.toml
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "tokio"
# - Create "v1.x.y" git tag.
version = "1.29.1"
edition = "2021"
rust-version = "1.56"
rust-version = "1.63"
authors = ["Tokio Contributors <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand Down Expand Up @@ -93,9 +93,6 @@ time = []
# a few releases.
stats = []

[build-dependencies]
autocfg = "1.1"

[dependencies]
tokio-macros = { version = "~2.1.0", path = "../tokio-macros", optional = true }

Expand Down
185 changes: 4 additions & 181 deletions tokio/build.rs
Original file line number Diff line number Diff line change
@@ -1,192 +1,15 @@
use autocfg::AutoCfg;

const CONST_THREAD_LOCAL_PROBE: &str = r#"
{
thread_local! {
static MY_PROBE: usize = const { 10 };
}

MY_PROBE.with(|val| *val)
}
"#;

const CONST_MUTEX_NEW_PROBE: &str = r#"
{
static MY_MUTEX: ::std::sync::Mutex<i32> = ::std::sync::Mutex::new(1);
*MY_MUTEX.lock().unwrap()
}
"#;

const AS_FD_PROBE: &str = r#"
{
#[allow(unused_imports)]
#[cfg(unix)]
use std::os::unix::prelude::AsFd as _;
#[allow(unused_imports)]
#[cfg(windows)]
use std::os::windows::prelude::AsSocket as _;
#[allow(unused_imports)]
#[cfg(target_os = "wasi")]
use std::os::wasi::prelude::AsFd as _;
}
"#;

const TARGET_HAS_ATOMIC_PROBE: &str = r#"
{
#[cfg(target_has_atomic = "ptr")]
let _ = ();
}
"#;

const TARGET_ATOMIC_U64_PROBE: &str = r#"
{
#[allow(unused_imports)]
use std::sync::atomic::AtomicU64 as _;
fn emit(cfg: &str) {
println!("cargo:rustc-cfg={}", cfg);
}
"#;

fn main() {
let mut enable_const_thread_local = false;
let mut enable_target_has_atomic = false;
let mut enable_const_mutex_new = false;
let mut enable_as_fd = false;
let mut target_needs_atomic_u64_fallback = false;

match AutoCfg::new() {
Ok(ac) => {
// These checks prefer to call only `probe_rustc_version` if that is
// enough to determine whether the feature is supported. This is
// because the `probe_expression` call involves a call to rustc,
// which the `probe_rustc_version` call avoids.

// Const-initialized thread locals were stabilized in 1.59.
if ac.probe_rustc_version(1, 60) {
enable_const_thread_local = true;
} else if ac.probe_rustc_version(1, 59) {
// This compiler claims to be 1.59, but there are some nightly
// compilers that claim to be 1.59 without supporting the
// feature. Explicitly probe to check if code using them
// compiles.
//
// The oldest nightly that supports the feature is 2021-12-06.
if ac.probe_expression(CONST_THREAD_LOCAL_PROBE) {
enable_const_thread_local = true;
}
}

// The `target_has_atomic` cfg was stabilized in 1.60.
if ac.probe_rustc_version(1, 61) {
enable_target_has_atomic = true;
} else if ac.probe_rustc_version(1, 60) {
// This compiler claims to be 1.60, but there are some nightly
// compilers that claim to be 1.60 without supporting the
// feature. Explicitly probe to check if code using them
// compiles.
//
// The oldest nightly that supports the feature is 2022-02-11.
if ac.probe_expression(TARGET_HAS_ATOMIC_PROBE) {
enable_target_has_atomic = true;
}
}

// If we can't tell using `target_has_atomic`, tell if the target
// has `AtomicU64` by trying to use it.
if !enable_target_has_atomic && !ac.probe_expression(TARGET_ATOMIC_U64_PROBE) {
target_needs_atomic_u64_fallback = true;
}

// The `Mutex::new` method was made const in 1.63.
if ac.probe_rustc_version(1, 64) {
enable_const_mutex_new = true;
} else if ac.probe_rustc_version(1, 63) {
// This compiler claims to be 1.63, but there are some nightly
// compilers that claim to be 1.63 without supporting the
// feature. Explicitly probe to check if code using them
// compiles.
//
// The oldest nightly that supports the feature is 2022-06-20.
if ac.probe_expression(CONST_MUTEX_NEW_PROBE) {
enable_const_mutex_new = true;
}
}

// The `AsFd` family of traits were made stable in 1.63.
if ac.probe_rustc_version(1, 64) {
enable_as_fd = true;
} else if ac.probe_rustc_version(1, 63) {
// This compiler claims to be 1.63, but there are some nightly
// compilers that claim to be 1.63 without supporting the
// feature. Explicitly probe to check if code using them
// compiles.
//
// The oldest nightly that supports the feature is 2022-06-16.
if ac.probe_expression(AS_FD_PROBE) {
enable_as_fd = true;
}
}
}

Err(e) => {
// If we couldn't detect the compiler version and features, just
// print a warning. This isn't a fatal error: we can still build
// Tokio, we just can't enable cfgs automatically.
println!(
"cargo:warning=tokio: failed to detect compiler features: {}",
e
);
}
}

if !enable_const_thread_local {
// To disable this feature on compilers that support it, you can
// explicitly pass this flag with the following environment variable:
//
// RUSTFLAGS="--cfg tokio_no_const_thread_local"
autocfg::emit("tokio_no_const_thread_local")
}

if !enable_target_has_atomic {
// To disable this feature on compilers that support it, you can
// explicitly pass this flag with the following environment variable:
//
// RUSTFLAGS="--cfg tokio_no_target_has_atomic"
autocfg::emit("tokio_no_target_has_atomic")
}

if !enable_const_mutex_new {
// To disable this feature on compilers that support it, you can
// explicitly pass this flag with the following environment variable:
//
// RUSTFLAGS="--cfg tokio_no_const_mutex_new"
autocfg::emit("tokio_no_const_mutex_new")
}

if !enable_as_fd {
// To disable this feature on compilers that support it, you can
// explicitly pass this flag with the following environment variable:
//
// RUSTFLAGS="--cfg tokio_no_as_fd"
autocfg::emit("tokio_no_as_fd");
}

if target_needs_atomic_u64_fallback {
// To disable this feature on compilers that support it, you can
// explicitly pass this flag with the following environment variable:
//
// RUSTFLAGS="--cfg tokio_no_atomic_u64"
autocfg::emit("tokio_no_atomic_u64")
}
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved

let target = ::std::env::var("TARGET").unwrap_or_default();

// We emit cfgs instead of using `target_family = "wasm"` that requires Rust 1.54.
// Note that these cfgs are unavailable in `Cargo.toml`.
if target.starts_with("wasm") {
autocfg::emit("tokio_wasm");
if target.contains("wasi") {
autocfg::emit("tokio_wasi");
emit("tokio_wasi");
} else {
autocfg::emit("tokio_wasm_not_wasi");
emit("tokio_wasm_not_wasi");
}
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved
}
}
19 changes: 11 additions & 8 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,21 +461,24 @@ compile_error! {
// Each condition is written all(a, not(b)). This should be read as
// "if a, then we must also have b".
#[cfg(any(
all(target_arch = "wasm32", not(tokio_wasm)),
all(target_arch = "wasm64", not(tokio_wasm)),
all(target_family = "wasm", not(tokio_wasm)),
all(target_os = "wasi", not(tokio_wasm)),
all(target_arch = "wasm32", not(target_family = "wasm")),
all(target_arch = "wasm64", not(target_family = "wasm")),
all(target_family = "wasm", not(target_family = "wasm")),
all(target_os = "wasi", not(target_family = "wasm")),
all(target_os = "wasi", not(tokio_wasi)),
all(target_os = "wasi", tokio_wasm_not_wasi),
all(tokio_wasm, not(any(target_arch = "wasm32", target_arch = "wasm64"))),
all(tokio_wasm_not_wasi, not(tokio_wasm)),
all(tokio_wasi, not(tokio_wasm))
all(
target_family = "wasm",
not(any(target_arch = "wasm32", target_arch = "wasm64"))
),
all(tokio_wasm_not_wasi, not(target_family = "wasm")),
all(tokio_wasi, not(target_family = "wasm"))
))]
compile_error!("Tokio's build script has incorrectly detected wasm.");

#[cfg(all(
not(tokio_unstable),
tokio_wasm,
target_family = "wasm",
any(
feature = "fs",
feature = "io-std",
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(any(not(feature = "full"), tokio_wasm), allow(dead_code))]
#![cfg_attr(any(not(feature = "full"), target_family = "wasm"), allow(dead_code))]
use crate::runtime::Callback;
use crate::util::RngSeedGenerator;

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

// At the top due to macros
#[cfg(test)]
#[cfg(not(tokio_wasm))]
#[cfg(not(target_family = "wasm"))]
#[macro_use]
mod tests;

Expand Down
4 changes: 2 additions & 2 deletions tokio/src/runtime/park.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ impl ParkThread {
CURRENT_THREAD_PARK_COUNT.with(|count| count.fetch_add(1, SeqCst));

// Wasm doesn't have threads, so just sleep.
#[cfg(not(tokio_wasm))]
#[cfg(not(target_family = "wasm"))]
self.inner.park_timeout(duration);
#[cfg(tokio_wasm)]
#[cfg(target_family = "wasm")]
std::thread::sleep(duration);
}

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl<S: Schedule> LocalNotified<S> {
impl<S: Schedule> UnownedTask<S> {
// Used in test of the inject queue.
#[cfg(test)]
#[cfg_attr(tokio_wasm, allow(dead_code))]
#[cfg_attr(target_family = "wasm", allow(dead_code))]
pub(super) fn into_notified(self) -> Notified<S> {
Notified(self.into_task())
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/sync/tests/atomic_waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn wake_without_register() {
}

#[test]
#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding
#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding
fn atomic_waker_panic_safe() {
use std::panic;
use std::ptr;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/sync/tests/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn notify_simple() {
}

#[test]
#[cfg(not(tokio_wasm))]
#[cfg(not(target_family = "wasm"))]
fn watch_test() {
let rt = crate::runtime::Builder::new_current_thread()
.build()
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/sync/tests/semaphore_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn max_permits_doesnt_panic() {

#[test]
#[should_panic]
#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding
#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding
fn validates_max_permits() {
Semaphore::new(MAX_PERMITS + 1);
}
Expand Down