Skip to content

Commit d0ca511

Browse files
committed
Remove uses of unstable feature(cfg_target_has_atomic)
1 parent 8666a25 commit d0ca511

File tree

30 files changed

+338
-91
lines changed

30 files changed

+338
-91
lines changed

.github/workflows/ci.yml

+35-40
Original file line numberDiff line numberDiff line change
@@ -127,59 +127,41 @@ 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
130+
no-std:
131+
name: cargo build --target ${{ matrix.target }}
132+
strategy:
133+
matrix:
134+
target:
135+
- thumbv6m-none-eabi
136+
- thumbv7m-none-eabi
132137
runs-on: ubuntu-latest
133138
steps:
134139
- uses: actions/checkout@v2
135140
- name: Install Rust
136141
run: rustup update nightly && rustup default nightly
137-
- run: rustup target add thumbv6m-none-eabi
142+
- run: rustup target add ${{ matrix.target }}
138143
- run: cargo install cargo-hack
139144
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
140145
- run: cargo hack --remove-dev-deps --workspace
141146
- 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
159-
runs-on: ubuntu-latest
160-
steps:
161-
- uses: actions/checkout@v2
162-
- name: Install Rust
163-
run: rustup update nightly && rustup default nightly
164-
- run: rustup target add thumbv7m-none-eabi
165-
- 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
147+
cargo hack build --manifest-path futures/tests/no-std/Cargo.toml \
148+
--each-feature --optional-deps \
149+
--target ${{ matrix.target }}
168150
- run: |
169-
cargo build --manifest-path futures/Cargo.toml \
170-
--target thumbv7m-none-eabi \
151+
cargo hack build --workspace --ignore-private \
152+
--exclude futures-test --exclude futures-macro \
171153
--no-default-features \
172-
--features unstable,cfg-target-has-atomic
154+
--target ${{ matrix.target }}
173155
- run: |
174-
cargo build --manifest-path futures/Cargo.toml \
175-
--target thumbv7m-none-eabi \
176-
--no-default-features \
177-
--features alloc
156+
cargo hack build --workspace --ignore-private \
157+
--exclude futures-test --exclude futures-macro \
158+
--no-default-features --features alloc --ignore-unknown-features \
159+
--target ${{ matrix.target }}
178160
- run: |
179-
cargo build --manifest-path futures/Cargo.toml \
180-
--target thumbv7m-none-eabi \
181-
--no-default-features \
182-
--features async-await
161+
cargo hack build --workspace --ignore-private \
162+
--exclude futures-test --exclude futures-macro \
163+
--no-default-features --features async-await,alloc --ignore-unknown-features \
164+
--target ${{ matrix.target }}
183165
184166
bench:
185167
name: cargo bench
@@ -212,6 +194,19 @@ jobs:
212194
--workspace --exclude futures-test \
213195
--features unstable --ignore-unknown-features
214196
197+
# When this job failed, run ci/no_atomic_cas.sh and commit result changes.
198+
# TODO(taiki-e): Ideally, this should be automated using a bot that creates
199+
# PR when failed, but there is no bandwidth to implement it
200+
# right now...
201+
codegen:
202+
runs-on: ubuntu-latest
203+
steps:
204+
- uses: actions/checkout@v2
205+
- name: Install Rust
206+
run: rustup update nightly && rustup default nightly
207+
- run: ci/no_atomic_cas.sh
208+
- run: git diff --exit-code
209+
215210
san:
216211
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}
217212
strategy:

Cargo.toml

+1
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

+23
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

+4-5
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

+42
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

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../no_atomic_cas.rs

futures-channel/src/lib.rs

+1-5
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

+2-3
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

+42
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

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../no_atomic_cas.rs

futures-core/src/lib.rs

-4
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

+2-2
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-macro/build.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ fn main() {
2323
if cfg.probe_rustc_version(1, 45) {
2424
println!("cargo:rustc-cfg=fn_like_proc_macro");
2525
}
26+
27+
println!("cargo:rerun-if-changed=build.rs");
2628
}

futures-task/Cargo.toml

+2-3
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

+42
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

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../no_atomic_cas.rs

futures-task/src/lib.rs

+1-5
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
}

0 commit comments

Comments
 (0)