Skip to content

Commit

Permalink
Remove uses of unstable feature(cfg_target_has_atomic)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Apr 20, 2021
1 parent c77cd3c commit ba8cc00
Show file tree
Hide file tree
Showing 29 changed files with 279 additions and 94 deletions.
68 changes: 22 additions & 46 deletions .github/workflows/ci.yml
Expand Up @@ -141,59 +141,24 @@ jobs:
- run: cargo update -Z minimal-versions
- run: cargo build --workspace --all-features

thumbv6m:
name: cargo build --target thumbv6m-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: 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
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 thumbv7m-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 thumbv7m-none-eabi \
--no-default-features \
--features unstable,cfg-target-has-atomic
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
--no-default-features \
--features alloc
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
--no-default-features \
--features async-await
cargo hack build --manifest-path futures/tests/no-std/Cargo.toml \
--each-feature --optional-deps \
--target ${{ matrix.target }}
bench:
name: cargo bench
Expand Down Expand Up @@ -226,6 +191,17 @@ 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
- 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
30 changes: 30 additions & 0 deletions futures-channel/build.rs
@@ -0,0 +1,30 @@
use std::env;

include!("no_atomic_cas.rs");

// 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_atomic_cas`, not `has_atomic_cas`. 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 build scripts.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=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(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
30 changes: 30 additions & 0 deletions futures-core/build.rs
@@ -0,0 +1,30 @@
use std::env;

include!("no_atomic_cas.rs");

// 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_atomic_cas`, not `has_atomic_cas`. 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 build scripts.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=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(no_atomic_cas))]
mod atomic_waker;
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(not(no_atomic_cas))]
pub use self::atomic_waker::AtomicWaker;
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
30 changes: 30 additions & 0 deletions futures-task/build.rs
@@ -0,0 +1,30 @@
use std::env;

include!("no_atomic_cas.rs");

// 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_atomic_cas`, not `has_atomic_cas`. 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 build scripts.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=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(no_atomic_cas))]
$item
)*};
}
Expand Down
5 changes: 4 additions & 1 deletion futures-util/Cargo.toml
Expand Up @@ -27,11 +27,14 @@ channel = ["std", "futures-channel"]
# 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", "futures-task/unstable"]
cfg-target-has-atomic = ["futures-core/cfg-target-has-atomic", "futures-task/cfg-target-has-atomic"]
bilock = []
read-initializer = ["io", "futures-io/read-initializer", "futures-io/unstable"]
write-all-vectored = ["io"]

# These features are no longer used.
# TODO: remove in the next major version.
cfg-target-has-atomic = []

[dependencies]
futures-core = { path = "../futures-core", version = "=1.0.0-alpha.0", default-features = false }
futures-task = { path = "../futures-task", version = "=0.4.0-alpha.0", default-features = false }
Expand Down
30 changes: 30 additions & 0 deletions futures-util/build.rs
@@ -0,0 +1,30 @@
use std::env;

include!("no_atomic_cas.rs");

// 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_atomic_cas`, not `has_atomic_cas`. 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 build scripts.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
1 change: 1 addition & 0 deletions futures-util/no_atomic_cas.rs

0 comments on commit ba8cc00

Please sign in to comment.