Repository: tokio-rs/tokio
File: tokio/build.rs (Rust)

Code before:
                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;
                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-20.
                if ac.probe_expression(CONST_MUTEX_NEW_PROBE) {
                    enable_const_mutex_new = true;
                    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_addr_of {
        // To disable this feature on compilers that support it, you can
        // explicitly pass this flag with the following environment variable:

Review comment (suggestion):
This would only be correct if `AsFd` was introduced in the exact same nightly as const mutex new. Can you have it use a separate probe here?

Generally, the purpose behind these checks is that some nightlies claim to be 1.63 without supporting the feature, and we need to make sure we actually compile on those nightlies too.

Code after:
                }
            }

            // 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;