Skip to content

Commit d7ad23a

Browse files
committed
Use autocfg instead of unstable feature(cfg_target_has_atomic)
1 parent 8e9b86e commit d7ad23a

File tree

24 files changed

+240
-97
lines changed

24 files changed

+240
-97
lines changed

.github/workflows/ci.yml

+11-46
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

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",

futures-channel/Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ 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 = []
24+
25+
[build-dependencies]
26+
autocfg = "1"
2527

2628
[dependencies]
2729
futures-core = { path = "../futures-core", version = "0.3.8", default-features = false }

futures-channel/build.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use autocfg::AutoCfg;
2+
3+
// The rustc-cfg strings below are *not* public API. Please let us know by
4+
// opening a GitHub issue if your build environment requires some way to enable
5+
// these cfgs other than by executing our build script.
6+
fn main() {
7+
let cfg = match AutoCfg::new() {
8+
Ok(cfg) => cfg,
9+
Err(e) => {
10+
println!(
11+
"cargo:warning={}: unable to determine rustc version: {}",
12+
env!("CARGO_PKG_NAME"),
13+
e
14+
);
15+
return;
16+
}
17+
};
18+
19+
if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
20+
println!("cargo:rustc-cfg=has_atomic_cas");
21+
}
22+
println!("cargo:rerun-if-changed=build.rs");
23+
}

futures-channel/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
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))]
15-
1614
#![cfg_attr(not(feature = "std"), no_std)]
1715

1816
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
@@ -21,12 +19,9 @@
2119
#![warn(clippy::all)]
2220
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
2321

24-
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
25-
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
26-
2722
macro_rules! cfg_target_has_atomic {
2823
($($item:item)*) => {$(
29-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
24+
#[cfg(has_atomic_cas)]
3025
$item
3126
)*};
3227
}

futures-core/Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ 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

24+
[build-dependencies]
25+
autocfg = "1"
26+
2527
[dependencies]
2628

2729
[dev-dependencies]

futures-core/build.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use autocfg::AutoCfg;
2+
3+
// The rustc-cfg strings below are *not* public API. Please let us know by
4+
// opening a GitHub issue if your build environment requires some way to enable
5+
// these cfgs other than by executing our build script.
6+
fn main() {
7+
let cfg = match AutoCfg::new() {
8+
Ok(cfg) => cfg,
9+
Err(e) => {
10+
println!(
11+
"cargo:warning={}: unable to determine rustc version: {}",
12+
env!("CARGO_PKG_NAME"),
13+
e
14+
);
15+
return;
16+
}
17+
};
18+
19+
if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
20+
println!("cargo:rustc-cfg=has_atomic_cas");
21+
}
22+
println!("cargo:rerun-if-changed=build.rs");
23+
}

futures-core/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Core traits and types for asynchronous operations in Rust.
22
3-
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
4-
53
#![cfg_attr(not(feature = "std"), no_std)]
64

75
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
@@ -10,9 +8,6 @@
108
#![warn(clippy::all)]
119
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
1210

13-
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
14-
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
15-
1611
#[cfg(feature = "alloc")]
1712
extern crate alloc;
1813

+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(has_atomic_cas)]
22
mod atomic_waker;
3-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
3+
#[cfg(has_atomic_cas)]
44
pub use self::atomic_waker::AtomicWaker;

futures-task/Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ default = ["std"]
1616
std = ["alloc", "once_cell"]
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

24+
[build-dependencies]
25+
autocfg = "1"
26+
2527
[dependencies]
2628
once_cell = { version = "1.3.1", default-features = false, features = ["std"], optional = true }
2729

futures-task/build.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use autocfg::AutoCfg;
2+
3+
// The rustc-cfg strings below are *not* public API. Please let us know by
4+
// opening a GitHub issue if your build environment requires some way to enable
5+
// these cfgs other than by executing our build script.
6+
fn main() {
7+
let cfg = match AutoCfg::new() {
8+
Ok(cfg) => cfg,
9+
Err(e) => {
10+
println!(
11+
"cargo:warning={}: unable to determine rustc version: {}",
12+
env!("CARGO_PKG_NAME"),
13+
e
14+
);
15+
return;
16+
}
17+
};
18+
19+
if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
20+
println!("cargo:rustc-cfg=has_atomic_cas");
21+
}
22+
println!("cargo:rerun-if-changed=build.rs");
23+
}

futures-task/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Tools for working with tasks.
22
3-
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
4-
53
#![cfg_attr(not(feature = "std"), no_std)]
64

75
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
@@ -10,15 +8,12 @@
108
#![warn(clippy::all)]
119
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
1210

13-
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
14-
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
15-
1611
#[cfg(feature = "alloc")]
1712
extern crate alloc;
1813

1914
macro_rules! cfg_target_has_atomic {
2015
($($item:item)*) => {$(
21-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
16+
#[cfg(has_atomic_cas)]
2217
$item
2318
)*};
2419
}

futures-util/Cargo.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ 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+
38+
[build-dependencies]
39+
autocfg = "1"
40+
3541
[dependencies]
3642
futures-core = { path = "../futures-core", version = "0.3.8", default-features = false }
3743
futures-task = { path = "../futures-task", version = "0.3.8", default-features = false }

futures-util/build.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use autocfg::AutoCfg;
2+
3+
// The rustc-cfg strings below are *not* public API. Please let us know by
4+
// opening a GitHub issue if your build environment requires some way to enable
5+
// these cfgs other than by executing our build script.
6+
fn main() {
7+
let cfg = match AutoCfg::new() {
8+
Ok(cfg) => cfg,
9+
Err(e) => {
10+
println!(
11+
"cargo:warning={}: unable to determine rustc version: {}",
12+
env!("CARGO_PKG_NAME"),
13+
e
14+
);
15+
return;
16+
}
17+
};
18+
19+
if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
20+
println!("cargo:rustc-cfg=has_atomic_cas");
21+
}
22+
println!("cargo:rerun-if-changed=build.rs");
23+
}

futures-util/src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Combinators and utilities for working with `Future`s, `Stream`s, `Sink`s,
22
//! and the `AsyncRead` and `AsyncWrite` traits.
33
4-
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
54
#![cfg_attr(feature = "read-initializer", feature(read_initializer))]
65
#![cfg_attr(feature = "write-all-vectored", feature(io_slice_advance))]
76
#![cfg_attr(not(feature = "std"), no_std)]
@@ -17,9 +16,6 @@
1716
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
1817
#![cfg_attr(docsrs, feature(doc_cfg))]
1918

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

@@ -58,7 +54,7 @@ pub mod __private {
5854

5955
macro_rules! cfg_target_has_atomic {
6056
($($item:item)*) => {$(
61-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
57+
#[cfg(has_atomic_cas)]
6258
$item
6359
)*};
6460
}

futures-util/src/stream/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ pub use self::stream::ReadyChunks;
3636
#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
3737
pub use self::stream::Forward;
3838

39-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
39+
#[cfg(has_atomic_cas)]
4040
#[cfg(feature = "alloc")]
4141
pub use self::stream::{BufferUnordered, Buffered, ForEachConcurrent};
4242

43-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
43+
#[cfg(has_atomic_cas)]
4444
#[cfg(feature = "sink")]
4545
#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
4646
#[cfg(feature = "alloc")]
@@ -58,7 +58,7 @@ pub use self::try_stream::{
5858
#[cfg(feature = "std")]
5959
pub use self::try_stream::IntoAsyncRead;
6060

61-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
61+
#[cfg(has_atomic_cas)]
6262
#[cfg(feature = "alloc")]
6363
pub use self::try_stream::{TryBufferUnordered, TryBuffered, TryForEachConcurrent};
6464

0 commit comments

Comments
 (0)