Skip to content

Commit 7a092cb

Browse files
committed
Remove uses of unstable feature(cfg_target_has_atomic)
1 parent cb0711e commit 7a092cb

File tree

29 files changed

+329
-94
lines changed

29 files changed

+329
-94
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -127,59 +127,24 @@ jobs:
127127
- run: cargo update -Z minimal-versions
128128
- run: cargo build --workspace --all-features
129129

130-
thumbv6m:
131-
name: cargo build --target thumbv6m-none-eabi
132-
runs-on: ubuntu-latest
133-
steps:
134-
- uses: actions/checkout@v2
135-
- name: Install Rust
136-
run: rustup update nightly && rustup default nightly
137-
- run: rustup target add thumbv6m-none-eabi
138-
- run: cargo install cargo-hack
139-
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
140-
- run: cargo hack --remove-dev-deps --workspace
141-
- run: |
142-
cargo build --manifest-path futures/Cargo.toml \
143-
--target thumbv6m-none-eabi \
144-
--no-default-features \
145-
--features unstable,cfg-target-has-atomic
146-
- run: |
147-
cargo build --manifest-path futures/Cargo.toml \
148-
--target thumbv6m-none-eabi \
149-
--no-default-features \
150-
--features alloc,unstable,cfg-target-has-atomic
151-
- run: |
152-
cargo build --manifest-path futures/Cargo.toml \
153-
--target thumbv6m-none-eabi \
154-
--no-default-features \
155-
--features async-await,unstable,cfg-target-has-atomic
156-
157-
thumbv7m:
158-
name: cargo build --target thumbv7m-none-eabi
130+
no-std:
131+
name: cargo build --target ${{ matrix.target }}
132+
strategy:
133+
matrix:
134+
target:
135+
- thumbv6m-none-eabi
136+
- thumbv7m-none-eabi
159137
runs-on: ubuntu-latest
160138
steps:
161139
- uses: actions/checkout@v2
162140
- name: Install Rust
163141
run: rustup update nightly && rustup default nightly
164-
- run: rustup target add thumbv7m-none-eabi
142+
- run: rustup target add ${{ matrix.target }}
165143
- run: cargo install cargo-hack
166-
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
167-
- run: cargo hack --remove-dev-deps --workspace
168-
- run: |
169-
cargo build --manifest-path futures/Cargo.toml \
170-
--target thumbv7m-none-eabi \
171-
--no-default-features \
172-
--features unstable,cfg-target-has-atomic
173-
- run: |
174-
cargo build --manifest-path futures/Cargo.toml \
175-
--target thumbv7m-none-eabi \
176-
--no-default-features \
177-
--features alloc
178144
- run: |
179-
cargo build --manifest-path futures/Cargo.toml \
180-
--target thumbv7m-none-eabi \
181-
--no-default-features \
182-
--features async-await
145+
cargo hack build --manifest-path futures/tests/no-std/Cargo.toml \
146+
--each-feature --optional-deps \
147+
--target ${{ matrix.target }}
183148
184149
bench:
185150
name: cargo bench
@@ -212,6 +177,19 @@ jobs:
212177
--workspace --exclude futures-test \
213178
--features unstable --ignore-unknown-features
214179
180+
# When this job failed, run ci/no_atomic_cas.sh and commit result changes.
181+
# TODO(taiki-e): Ideally, this should be automated using a bot that creates
182+
# PR when failed, but there is no bandwidth to implement it
183+
# right now...
184+
codegen:
185+
runs-on: ubuntu-latest
186+
steps:
187+
- uses: actions/checkout@v2
188+
- name: Install Rust
189+
run: rustup update nightly && rustup default nightly
190+
- run: ci/no_atomic_cas.sh
191+
- run: git diff --exit-code
192+
215193
san:
216194
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}
217195
strategy:

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313

1414
"futures/tests/macro-tests",
1515
"futures/tests/macro-reexport",
16+
"futures/tests/no-std",
1617

1718
"examples/functional",
1819
"examples/imperative",

ci/no_atomic_cas.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
cd "$(cd "$(dirname "$0")" && pwd)"/..
7+
8+
file="no_atomic_cas.rs"
9+
10+
{
11+
echo "// This file is @generated by $(basename "$0")."
12+
echo "// It is not intended for manual editing."
13+
echo ""
14+
echo "const NO_ATOMIC_CAS_TARGETS: &[&str] = &["
15+
} >"$file"
16+
17+
for target in $(rustc --print target-list); do
18+
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
19+
| jq -r "select(.\"atomic-cas\" == false)")
20+
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
21+
done
22+
23+
echo "];" >>"$file"

futures-channel/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ std = ["alloc", "futures-core/std"]
1717
alloc = ["futures-core/alloc"]
1818
sink = ["futures-sink"]
1919

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

2625
[dependencies]
2726
futures-core = { path = "../futures-core", version = "=1.0.0-alpha.0", default-features = false }

futures-channel/build.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![warn(rust_2018_idioms, single_use_lifetimes)]
2+
3+
use std::env;
4+
5+
include!("no_atomic_cas.rs");
6+
7+
// The rustc-cfg listed below are considered public API, but it is *unstable*
8+
// and outside of the normal semver guarantees:
9+
//
10+
// - `futures_no_atomic_cas`
11+
// Assume the target does not have atomic CAS (compare-and-swap).
12+
// This is usually detected automatically by the build script, but you may
13+
// need to enable it manually when building for custom targets or using
14+
// non-cargo build systems that don't run the build script.
15+
//
16+
// With the exceptions mentioned above, the rustc-cfg strings below are
17+
// *not* public API. Please let us know by opening a GitHub issue if your build
18+
// environment requires some way to enable these cfgs other than by executing
19+
// our build script.
20+
fn main() {
21+
let target = match env::var("TARGET") {
22+
Ok(target) => target,
23+
Err(e) => {
24+
println!(
25+
"cargo:warning={}: unable to get TARGET environment variable: {}",
26+
env!("CARGO_PKG_NAME"),
27+
e
28+
);
29+
return;
30+
}
31+
};
32+
33+
// Note that this is `no_*`, not `has_*`. This allows treating
34+
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
35+
// run. This is needed for compatibility with non-cargo build systems that
36+
// don't run the build script.
37+
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
38+
println!("cargo:rustc-cfg=futures_no_atomic_cas");
39+
}
40+
41+
println!("cargo:rerun-if-changed=no_atomic_cas.rs");
42+
}

futures-channel/no_atomic_cas.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../no_atomic_cas.rs

futures-channel/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,16 @@
1111
//! All items are only available when the `std` or `alloc` feature of this
1212
//! library is activated, and it is activated by default.
1313
14-
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
1514
#![cfg_attr(not(feature = "std"), no_std)]
1615
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
1716
// It cannot be included in the published code because this lints have false positives in the minimum required version.
1817
#![cfg_attr(test, warn(single_use_lifetimes))]
1918
#![warn(clippy::all)]
2019
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
2120

22-
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
23-
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
24-
2521
macro_rules! cfg_target_has_atomic {
2622
($($item:item)*) => {$(
27-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
23+
#[cfg(not(futures_no_atomic_cas))]
2824
$item
2925
)*};
3026
}

futures-core/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ default = ["std"]
1616
std = ["alloc"]
1717
alloc = []
1818

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

futures-core/build.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![warn(rust_2018_idioms, single_use_lifetimes)]
2+
3+
use std::env;
4+
5+
include!("no_atomic_cas.rs");
6+
7+
// The rustc-cfg listed below are considered public API, but it is *unstable*
8+
// and outside of the normal semver guarantees:
9+
//
10+
// - `futures_no_atomic_cas`
11+
// Assume the target does not have atomic CAS (compare-and-swap).
12+
// This is usually detected automatically by the build script, but you may
13+
// need to enable it manually when building for custom targets or using
14+
// non-cargo build systems that don't run the build script.
15+
//
16+
// With the exceptions mentioned above, the rustc-cfg strings below are
17+
// *not* public API. Please let us know by opening a GitHub issue if your build
18+
// environment requires some way to enable these cfgs other than by executing
19+
// our build script.
20+
fn main() {
21+
let target = match env::var("TARGET") {
22+
Ok(target) => target,
23+
Err(e) => {
24+
println!(
25+
"cargo:warning={}: unable to get TARGET environment variable: {}",
26+
env!("CARGO_PKG_NAME"),
27+
e
28+
);
29+
return;
30+
}
31+
};
32+
33+
// Note that this is `no_*`, not `has_*`. This allows treating
34+
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
35+
// run. This is needed for compatibility with non-cargo build systems that
36+
// don't run the build script.
37+
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
38+
println!("cargo:rustc-cfg=futures_no_atomic_cas");
39+
}
40+
41+
println!("cargo:rerun-if-changed=no_atomic_cas.rs");
42+
}

futures-core/no_atomic_cas.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../no_atomic_cas.rs

futures-core/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
//! Core traits and types for asynchronous operations in Rust.
22
3-
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
43
#![cfg_attr(not(feature = "std"), no_std)]
54
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
65
// It cannot be included in the published code because this lints have false positives in the minimum required version.
76
#![cfg_attr(test, warn(single_use_lifetimes))]
87
#![warn(clippy::all)]
98
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
109

11-
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
12-
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
13-
1410
#[cfg(feature = "alloc")]
1511
extern crate alloc;
1612

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
1+
#[cfg(not(futures_no_atomic_cas))]
22
mod atomic_waker;
3-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
3+
#[cfg(not(futures_no_atomic_cas))]
44
pub use self::atomic_waker::AtomicWaker;

futures-task/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ default = ["std"]
1616
std = ["alloc"]
1717
alloc = []
1818

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

futures-task/build.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![warn(rust_2018_idioms, single_use_lifetimes)]
2+
3+
use std::env;
4+
5+
include!("no_atomic_cas.rs");
6+
7+
// The rustc-cfg listed below are considered public API, but it is *unstable*
8+
// and outside of the normal semver guarantees:
9+
//
10+
// - `futures_no_atomic_cas`
11+
// Assume the target does not have atomic CAS (compare-and-swap).
12+
// This is usually detected automatically by the build script, but you may
13+
// need to enable it manually when building for custom targets or using
14+
// non-cargo build systems that don't run the build script.
15+
//
16+
// With the exceptions mentioned above, the rustc-cfg strings below are
17+
// *not* public API. Please let us know by opening a GitHub issue if your build
18+
// environment requires some way to enable these cfgs other than by executing
19+
// our build script.
20+
fn main() {
21+
let target = match env::var("TARGET") {
22+
Ok(target) => target,
23+
Err(e) => {
24+
println!(
25+
"cargo:warning={}: unable to get TARGET environment variable: {}",
26+
env!("CARGO_PKG_NAME"),
27+
e
28+
);
29+
return;
30+
}
31+
};
32+
33+
// Note that this is `no_*`, not `has_*`. This allows treating
34+
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
35+
// run. This is needed for compatibility with non-cargo build systems that
36+
// don't run the build script.
37+
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
38+
println!("cargo:rustc-cfg=futures_no_atomic_cas");
39+
}
40+
41+
println!("cargo:rerun-if-changed=no_atomic_cas.rs");
42+
}

futures-task/no_atomic_cas.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../no_atomic_cas.rs

futures-task/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
//! Tools for working with tasks.
22
3-
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
43
#![cfg_attr(not(feature = "std"), no_std)]
54
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
65
// It cannot be included in the published code because this lints have false positives in the minimum required version.
76
#![cfg_attr(test, warn(single_use_lifetimes))]
87
#![warn(clippy::all)]
98
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
109

11-
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
12-
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
13-
1410
#[cfg(feature = "alloc")]
1511
extern crate alloc;
1612

1713
macro_rules! cfg_target_has_atomic {
1814
($($item:item)*) => {$(
19-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
15+
#[cfg(not(futures_no_atomic_cas))]
2016
$item
2117
)*};
2218
}

futures-util/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ channel = ["std", "futures-channel"]
2727
# These features are outside of the normal semver guarantees and require the
2828
# `unstable` feature as an explicit opt-in to unstable API.
2929
unstable = ["futures-core/unstable", "futures-task/unstable"]
30-
cfg-target-has-atomic = ["futures-core/cfg-target-has-atomic", "futures-task/cfg-target-has-atomic"]
3130
bilock = []
3231
read-initializer = ["io", "futures-io/read-initializer", "futures-io/unstable"]
3332
write-all-vectored = ["io"]
3433

34+
# These features are no longer used.
35+
# TODO: remove in the next major version.
36+
cfg-target-has-atomic = []
37+
3538
[dependencies]
3639
futures-core = { path = "../futures-core", version = "=1.0.0-alpha.0", default-features = false }
3740
futures-task = { path = "../futures-task", version = "=0.4.0-alpha.0", default-features = false }

0 commit comments

Comments
 (0)