Skip to content

Commit 2b5d082

Browse files
committed
Remove uses of unstable feature(cfg_target_has_atomic)
1 parent c77cd3c commit 2b5d082

File tree

29 files changed

+281
-94
lines changed

29 files changed

+281
-94
lines changed

.github/workflows/ci.yml

+24-46
Original file line numberDiff line numberDiff line change
@@ -141,59 +141,24 @@ jobs:
141141
- run: cargo update -Z minimal-versions
142142
- run: cargo build --workspace --all-features
143143

144-
thumbv6m:
145-
name: cargo build --target thumbv6m-none-eabi
146-
runs-on: ubuntu-latest
147-
steps:
148-
- uses: actions/checkout@v2
149-
- name: Install Rust
150-
run: rustup update nightly && rustup default nightly
151-
- run: rustup target add thumbv6m-none-eabi
152-
- run: cargo install cargo-hack
153-
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
154-
- run: cargo hack --remove-dev-deps --workspace
155-
- run: |
156-
cargo build --manifest-path futures/Cargo.toml \
157-
--target thumbv6m-none-eabi \
158-
--no-default-features \
159-
--features unstable,cfg-target-has-atomic
160-
- run: |
161-
cargo build --manifest-path futures/Cargo.toml \
162-
--target thumbv6m-none-eabi \
163-
--no-default-features \
164-
--features alloc,unstable,cfg-target-has-atomic
165-
- run: |
166-
cargo build --manifest-path futures/Cargo.toml \
167-
--target thumbv6m-none-eabi \
168-
--no-default-features \
169-
--features async-await,unstable,cfg-target-has-atomic
170-
171-
thumbv7m:
172-
name: cargo build --target thumbv7m-none-eabi
144+
no-std:
145+
name: cargo build --target ${{ matrix.target }}
146+
strategy:
147+
matrix:
148+
target:
149+
- thumbv6m-none-eabi
150+
- thumbv7m-none-eabi
173151
runs-on: ubuntu-latest
174152
steps:
175153
- uses: actions/checkout@v2
176154
- name: Install Rust
177155
run: rustup update nightly && rustup default nightly
178-
- run: rustup target add thumbv7m-none-eabi
156+
- run: rustup target add ${{ matrix.target }}
179157
- run: cargo install cargo-hack
180-
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
181-
- run: cargo hack --remove-dev-deps --workspace
182-
- run: |
183-
cargo build --manifest-path futures/Cargo.toml \
184-
--target thumbv7m-none-eabi \
185-
--no-default-features \
186-
--features unstable,cfg-target-has-atomic
187-
- run: |
188-
cargo build --manifest-path futures/Cargo.toml \
189-
--target thumbv7m-none-eabi \
190-
--no-default-features \
191-
--features alloc
192158
- run: |
193-
cargo build --manifest-path futures/Cargo.toml \
194-
--target thumbv7m-none-eabi \
195-
--no-default-features \
196-
--features async-await
159+
cargo hack build --manifest-path futures/tests/no-std/Cargo.toml \
160+
--each-feature --optional-deps \
161+
--target ${{ matrix.target }}
197162
198163
bench:
199164
name: cargo bench
@@ -226,6 +191,19 @@ jobs:
226191
--workspace --exclude futures-test \
227192
--features unstable --ignore-unknown-features
228193
194+
# When this job failed, run ci/no_atomic_cas.sh and commit result changes.
195+
# TODO(taiki-e): Ideally, this should be automated using a bot that creates
196+
# PR when failed, but there is no bandwidth to implement it
197+
# right now...
198+
codegen:
199+
runs-on: ubuntu-latest
200+
steps:
201+
- uses: actions/checkout@v2
202+
- name: Install Rust
203+
run: rustup update nightly && rustup default nightly
204+
- run: ci/no_atomic_cas.sh
205+
- run: git diff --exit-code
206+
229207
san:
230208
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}
231209
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

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::env;
2+
3+
include!("no_atomic_cas.rs");
4+
5+
// The rustc-cfg strings below are *not* public API. Please let us know by
6+
// opening a GitHub issue if your build environment requires some way to enable
7+
// these cfgs other than by executing our build script.
8+
fn main() {
9+
let target = match env::var("TARGET") {
10+
Ok(target) => target,
11+
Err(e) => {
12+
println!(
13+
"cargo:warning={}: unable to get TARGET environment variable: {}",
14+
env!("CARGO_PKG_NAME"),
15+
e
16+
);
17+
return;
18+
}
19+
};
20+
21+
// Note that this is `no_atomic_cas`, not `has_atomic_cas`. This allows
22+
// treating `cfg(target_has_atomic = "ptr")` as true when the build script
23+
// doesn't run. This is needed for compatibility with non-cargo build
24+
// systems that don't run build scripts.
25+
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
26+
println!("cargo:rustc-cfg=no_atomic_cas");
27+
}
28+
29+
println!("cargo:rerun-if-changed=no_atomic_cas.rs");
30+
}

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

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::env;
2+
3+
include!("no_atomic_cas.rs");
4+
5+
// The rustc-cfg strings below are *not* public API. Please let us know by
6+
// opening a GitHub issue if your build environment requires some way to enable
7+
// these cfgs other than by executing our build script.
8+
fn main() {
9+
let target = match env::var("TARGET") {
10+
Ok(target) => target,
11+
Err(e) => {
12+
println!(
13+
"cargo:warning={}: unable to get TARGET environment variable: {}",
14+
env!("CARGO_PKG_NAME"),
15+
e
16+
);
17+
return;
18+
}
19+
};
20+
21+
// Note that this is `no_atomic_cas`, not `has_atomic_cas`. This allows
22+
// treating `cfg(target_has_atomic = "ptr")` as true when the build script
23+
// doesn't run. This is needed for compatibility with non-cargo build
24+
// systems that don't run build scripts.
25+
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
26+
println!("cargo:rustc-cfg=no_atomic_cas");
27+
}
28+
29+
println!("cargo:rerun-if-changed=no_atomic_cas.rs");
30+
}

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

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

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::env;
2+
3+
include!("no_atomic_cas.rs");
4+
5+
// The rustc-cfg strings below are *not* public API. Please let us know by
6+
// opening a GitHub issue if your build environment requires some way to enable
7+
// these cfgs other than by executing our build script.
8+
fn main() {
9+
let target = match env::var("TARGET") {
10+
Ok(target) => target,
11+
Err(e) => {
12+
println!(
13+
"cargo:warning={}: unable to get TARGET environment variable: {}",
14+
env!("CARGO_PKG_NAME"),
15+
e
16+
);
17+
return;
18+
}
19+
};
20+
21+
// Note that this is `no_atomic_cas`, not `has_atomic_cas`. This allows
22+
// treating `cfg(target_has_atomic = "ptr")` as true when the build script
23+
// doesn't run. This is needed for compatibility with non-cargo build
24+
// systems that don't run build scripts.
25+
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
26+
println!("cargo:rustc-cfg=no_atomic_cas");
27+
}
28+
29+
println!("cargo:rerun-if-changed=no_atomic_cas.rs");
30+
}

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(no_atomic_cas))]
2016
$item
2117
)*};
2218
}

futures-util/Cargo.toml

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

futures-util/build.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::env;
2+
3+
include!("no_atomic_cas.rs");
4+
5+
// The rustc-cfg strings below are *not* public API. Please let us know by
6+
// opening a GitHub issue if your build environment requires some way to enable
7+
// these cfgs other than by executing our build script.
8+
fn main() {
9+
let target = match env::var("TARGET") {
10+
Ok(target) => target,
11+
Err(e) => {
12+
println!(
13+
"cargo:warning={}: unable to get TARGET environment variable: {}",
14+
env!("CARGO_PKG_NAME"),
15+
e
16+
);
17+
return;
18+
}
19+
};
20+
21+
// Note that this is `no_atomic_cas`, not `has_atomic_cas`. This allows
22+
// treating `cfg(target_has_atomic = "ptr")` as true when the build script
23+
// doesn't run. This is needed for compatibility with non-cargo build
24+
// systems that don't run build scripts.
25+
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
26+
println!("cargo:rustc-cfg=no_atomic_cas");
27+
}
28+
29+
println!("cargo:rerun-if-changed=no_atomic_cas.rs");
30+
}

futures-util/no_atomic_cas.rs

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

0 commit comments

Comments
 (0)