Skip to content

Commit 665c32e

Browse files
committed
Use autocfg instead of unstable feature(cfg_target_has_atomic)
1 parent 5559680 commit 665c32e

File tree

24 files changed

+247
-104
lines changed

24 files changed

+247
-104
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
@@ -6,8 +6,6 @@
66
//! All items of this library are only available when the `std` or `alloc` feature of this
77
//! library is activated, and it is activated by default.
88
9-
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
10-
119
#![cfg_attr(not(feature = "std"), no_std)]
1210

1311
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
@@ -22,12 +20,9 @@
2220

2321
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
2422

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

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)]
@@ -16,9 +14,6 @@
1614

1715
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
1816

19-
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
20-
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
21-
2217
#[cfg(feature = "alloc")]
2318
extern crate alloc;
2419

+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)]
@@ -16,15 +14,12 @@
1614

1715
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
1816

19-
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
20-
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
21-
2217
#[cfg(feature = "alloc")]
2318
extern crate alloc;
2419

2520
macro_rules! cfg_target_has_atomic {
2621
($($item:item)*) => {$(
27-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
22+
#[cfg(has_atomic_cas)]
2823
$item
2924
)*};
3025
}

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

@@ -20,9 +19,6 @@
2019

2120
#![cfg_attr(docsrs, feature(doc_cfg))]
2221

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

@@ -61,7 +57,7 @@ pub mod __private {
6157

6258
macro_rules! cfg_target_has_atomic {
6359
($($item:item)*) => {$(
64-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
60+
#[cfg(has_atomic_cas)]
6561
$item
6662
)*};
6763
}

futures-util/src/stream/mod.rs

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

34-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
34+
#[cfg(has_atomic_cas)]
3535
#[cfg(feature = "alloc")]
3636
pub use self::stream::{BufferUnordered, Buffered, ForEachConcurrent};
3737

38-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
38+
#[cfg(has_atomic_cas)]
3939
#[cfg(feature = "sink")]
4040
#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
4141
#[cfg(feature = "alloc")]
@@ -53,7 +53,7 @@ pub use self::try_stream::{
5353
#[cfg(feature = "std")]
5454
pub use self::try_stream::IntoAsyncRead;
5555

56-
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
56+
#[cfg(has_atomic_cas)]
5757
#[cfg(feature = "alloc")]
5858
pub use self::try_stream::{TryBufferUnordered, TryBuffered, TryForEachConcurrent};
5959

0 commit comments

Comments
 (0)