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

Remove uses of unstable feature(cfg_target_has_atomic) #2400

Merged
merged 1 commit into from May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 35 additions & 40 deletions .github/workflows/ci.yml
Expand Up @@ -127,59 +127,41 @@ jobs:
- run: cargo update -Z minimal-versions
- run: cargo build --workspace --all-features

thumbv6m:
name: cargo build --target thumbv6m-none-eabi
no-std:
name: cargo build --target ${{ matrix.target }}
strategy:
matrix:
target:
- thumbv6m-none-eabi
- thumbv7m-none-eabi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: rustup target add thumbv6m-none-eabi
- run: rustup target add ${{ matrix.target }}
- run: cargo install cargo-hack
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
- run: cargo hack --remove-dev-deps --workspace
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv6m-none-eabi \
--no-default-features \
--features unstable,cfg-target-has-atomic
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv6m-none-eabi \
--no-default-features \
--features alloc,unstable,cfg-target-has-atomic
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv6m-none-eabi \
--no-default-features \
--features async-await,unstable,cfg-target-has-atomic

thumbv7m:
name: cargo build --target thumbv7m-none-eabi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: rustup target add thumbv7m-none-eabi
- run: cargo install cargo-hack
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
- run: cargo hack --remove-dev-deps --workspace
cargo hack build --manifest-path futures/tests/no-std/Cargo.toml \
--each-feature --optional-deps \
--target ${{ matrix.target }}
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
cargo hack build --workspace --ignore-private \
--exclude futures-test --exclude futures-macro \
--no-default-features \
--features unstable,cfg-target-has-atomic
--target ${{ matrix.target }}
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
--no-default-features \
--features alloc
cargo hack build --workspace --ignore-private \
--exclude futures-test --exclude futures-macro \
--no-default-features --features alloc --ignore-unknown-features \
--target ${{ matrix.target }}
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
--no-default-features \
--features async-await
cargo hack build --workspace --ignore-private \
--exclude futures-test --exclude futures-macro \
--no-default-features --features async-await,alloc --ignore-unknown-features \
--target ${{ matrix.target }}

bench:
name: cargo bench
Expand Down Expand Up @@ -212,6 +194,19 @@ jobs:
--workspace --exclude futures-test \
--features unstable --ignore-unknown-features

# When this job failed, run ci/no_atomic_cas.sh and commit result changes.
# TODO(taiki-e): Ideally, this should be automated using a bot that creates
# PR when failed, but there is no bandwidth to implement it
# right now...
codegen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: ci/no_atomic_cas.sh
- run: git diff --exit-code

san:
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}
strategy:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -13,6 +13,7 @@ members = [

"futures/tests/macro-tests",
"futures/tests/macro-reexport",
"futures/tests/no-std",

"examples/functional",
"examples/imperative",
Expand Down
23 changes: 23 additions & 0 deletions ci/no_atomic_cas.sh
@@ -0,0 +1,23 @@
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

cd "$(cd "$(dirname "$0")" && pwd)"/..

file="no_atomic_cas.rs"

{
echo "// This file is @generated by $(basename "$0")."
echo "// It is not intended for manual editing."
echo ""
echo "const NO_ATOMIC_CAS_TARGETS: &[&str] = &["
} >"$file"

for target in $(rustc --print target-list); do
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
| jq -r "select(.\"atomic-cas\" == false)")
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
done

echo "];" >>"$file"
9 changes: 4 additions & 5 deletions futures-channel/Cargo.toml
Expand Up @@ -17,11 +17,10 @@ std = ["alloc", "futures-core/std"]
alloc = ["futures-core/alloc"]
sink = ["futures-sink"]

# Unstable features
# These features are outside of the normal semver guarantees and require the
# `unstable` feature as an explicit opt-in to unstable API.
unstable = ["futures-core/unstable"]
cfg-target-has-atomic = ["futures-core/cfg-target-has-atomic"]
# These features are no longer used.
# TODO: remove in the next major version.
unstable = []
cfg-target-has-atomic = []

[dependencies]
futures-core = { path = "../futures-core", version = "=1.0.0-alpha.0", default-features = false }
Expand Down
42 changes: 42 additions & 0 deletions futures-channel/build.rs
@@ -0,0 +1,42 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]

use std::env;

include!("no_atomic_cas.rs");

// The rustc-cfg listed below are considered public API, but it is *unstable*
// and outside of the normal semver guarantees:
//
// - `futures_no_atomic_cas`
// Assume the target does not have atomic CAS (compare-and-swap).
// This is usually detected automatically by the build script, but you may
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
//
// With the exceptions mentioned above, the rustc-cfg strings below are
// *not* public API. Please let us know by opening a GitHub issue if your build
// environment requires some way to enable these cfgs other than by executing
// our build script.
Comment on lines +7 to +19
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said in #2400 (comment), exposes cfg(futures_no_atomic_cas) as unstable public API (outside of the normal semver guarantees).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we probably need to set #![cfg_attr(docsrs, doc(cfg_hide(futures_no_atomic_cas)))] when rust-lang/rust#79341 merged...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be a while 😅

fn main() {
let target = match env::var("TARGET") {
Ok(target) => target,
Err(e) => {
println!(
"cargo:warning={}: unable to get TARGET environment variable: {}",
env!("CARGO_PKG_NAME"),
e
);
return;
}
};

// Note that this is `no_*`, not `has_*`. This allows treating
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
// run. This is needed for compatibility with non-cargo build systems that
// don't run the build script.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=futures_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
1 change: 1 addition & 0 deletions futures-channel/no_atomic_cas.rs
6 changes: 1 addition & 5 deletions futures-channel/src/lib.rs
Expand Up @@ -11,20 +11,16 @@
//! All items are only available when the `std` or `alloc` feature of this
//! library is activated, and it is activated by default.

#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
// It cannot be included in the published code because this lints have false positives in the minimum required version.
#![cfg_attr(test, warn(single_use_lifetimes))]
#![warn(clippy::all)]
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]

#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(not(futures_no_atomic_cas))]
$item
)*};
}
Expand Down
5 changes: 2 additions & 3 deletions futures-core/Cargo.toml
Expand Up @@ -16,9 +16,8 @@ default = ["std"]
std = ["alloc"]
alloc = []

# Unstable features
# These features are outside of the normal semver guarantees and require the
# `unstable` feature as an explicit opt-in to unstable API.
# These features are no longer used.
# TODO: remove in the next major version.
unstable = []
cfg-target-has-atomic = []

Expand Down
42 changes: 42 additions & 0 deletions futures-core/build.rs
@@ -0,0 +1,42 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]

use std::env;

include!("no_atomic_cas.rs");

// The rustc-cfg listed below are considered public API, but it is *unstable*
// and outside of the normal semver guarantees:
//
// - `futures_no_atomic_cas`
// Assume the target does not have atomic CAS (compare-and-swap).
// This is usually detected automatically by the build script, but you may
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
//
// With the exceptions mentioned above, the rustc-cfg strings below are
// *not* public API. Please let us know by opening a GitHub issue if your build
// environment requires some way to enable these cfgs other than by executing
// our build script.
fn main() {
let target = match env::var("TARGET") {
Ok(target) => target,
Err(e) => {
println!(
"cargo:warning={}: unable to get TARGET environment variable: {}",
env!("CARGO_PKG_NAME"),
e
);
return;
}
};

// Note that this is `no_*`, not `has_*`. This allows treating
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
// run. This is needed for compatibility with non-cargo build systems that
// don't run the build script.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=futures_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
1 change: 1 addition & 0 deletions futures-core/no_atomic_cas.rs
4 changes: 0 additions & 4 deletions futures-core/src/lib.rs
@@ -1,16 +1,12 @@
//! Core traits and types for asynchronous operations in Rust.

#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
// It cannot be included in the published code because this lints have false positives in the minimum required version.
#![cfg_attr(test, warn(single_use_lifetimes))]
#![warn(clippy::all)]
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]

#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");

#[cfg(feature = "alloc")]
extern crate alloc;

Expand Down
4 changes: 2 additions & 2 deletions futures-core/src/task/__internal/mod.rs
@@ -1,4 +1,4 @@
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(not(futures_no_atomic_cas))]
mod atomic_waker;
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(not(futures_no_atomic_cas))]
pub use self::atomic_waker::AtomicWaker;
2 changes: 2 additions & 0 deletions futures-macro/build.rs
Expand Up @@ -23,4 +23,6 @@ fn main() {
if cfg.probe_rustc_version(1, 45) {
println!("cargo:rustc-cfg=fn_like_proc_macro");
}

println!("cargo:rerun-if-changed=build.rs");
}
5 changes: 2 additions & 3 deletions futures-task/Cargo.toml
Expand Up @@ -16,9 +16,8 @@ default = ["std"]
std = ["alloc"]
alloc = []

# Unstable features
# These features are outside of the normal semver guarantees and require the
# `unstable` feature as an explicit opt-in to unstable API.
# These features are no longer used.
# TODO: remove in the next major version.
unstable = []
cfg-target-has-atomic = []

Expand Down
42 changes: 42 additions & 0 deletions futures-task/build.rs
@@ -0,0 +1,42 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]

use std::env;

include!("no_atomic_cas.rs");

// The rustc-cfg listed below are considered public API, but it is *unstable*
// and outside of the normal semver guarantees:
//
// - `futures_no_atomic_cas`
// Assume the target does not have atomic CAS (compare-and-swap).
// This is usually detected automatically by the build script, but you may
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
//
// With the exceptions mentioned above, the rustc-cfg strings below are
// *not* public API. Please let us know by opening a GitHub issue if your build
// environment requires some way to enable these cfgs other than by executing
// our build script.
fn main() {
let target = match env::var("TARGET") {
Ok(target) => target,
Err(e) => {
println!(
"cargo:warning={}: unable to get TARGET environment variable: {}",
env!("CARGO_PKG_NAME"),
e
);
return;
}
};

// Note that this is `no_*`, not `has_*`. This allows treating
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
// run. This is needed for compatibility with non-cargo build systems that
// don't run the build script.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=futures_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
1 change: 1 addition & 0 deletions futures-task/no_atomic_cas.rs
6 changes: 1 addition & 5 deletions futures-task/src/lib.rs
@@ -1,22 +1,18 @@
//! Tools for working with tasks.

#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
// It cannot be included in the published code because this lints have false positives in the minimum required version.
#![cfg_attr(test, warn(single_use_lifetimes))]
#![warn(clippy::all)]
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]

#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");

#[cfg(feature = "alloc")]
extern crate alloc;

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(not(futures_no_atomic_cas))]
$item
)*};
}
Expand Down