Skip to content

Commit

Permalink
Use autocfg instead of unstable feature(cfg_target_has_atomic)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 22, 2020
1 parent 8a04b51 commit 0a07109
Show file tree
Hide file tree
Showing 24 changed files with 242 additions and 104 deletions.
57 changes: 11 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,59 +127,24 @@ jobs:
- run: cargo update -Z minimal-versions
- run: cargo build --workspace --all-features

thumbv6m:
name: cargo build --target thumbv6m-none-eabi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: rustup target add thumbv6m-none-eabi
- run: cargo install cargo-hack
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
- run: cargo hack --remove-dev-deps --workspace
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv6m-none-eabi \
--no-default-features \
--features unstable,cfg-target-has-atomic
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv6m-none-eabi \
--no-default-features \
--features alloc,unstable,cfg-target-has-atomic
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv6m-none-eabi \
--no-default-features \
--features async-await,unstable,cfg-target-has-atomic
thumbv7m:
name: cargo build --target thumbv7m-none-eabi
no-std:
name: cargo build --target ${{ matrix.rust }}
strategy:
matrix:
target:
- thumbv6m-none-eabi
- thumbv7m-none-eabi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: rustup target add thumbv7m-none-eabi
- run: rustup target add ${{ matrix.target }}
- run: cargo install cargo-hack
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
- run: cargo hack --remove-dev-deps --workspace
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
--no-default-features \
--features unstable,cfg-target-has-atomic
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
--no-default-features \
--features alloc
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
--no-default-features \
--features async-await
cargo hack build --manifest-path futures/tests/no-std/Cargo.toml \
--each-feature --optional-deps \
--target ${{ matrix.target }}
bench:
name: cargo bench
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [

"futures/tests/macro-tests",
"futures/tests/macro-reexport",
"futures/tests/no-std",

"examples/functional",
"examples/imperative",
Expand Down
12 changes: 7 additions & 5 deletions futures-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ std = ["alloc", "futures-core/std"]
alloc = ["futures-core/alloc"]
sink = ["futures-sink"]

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

[build-dependencies]
autocfg = "1"

[dependencies]
futures-core = { path = "../futures-core", version = "0.3.8", default-features = false }
Expand Down
22 changes: 22 additions & 0 deletions futures-channel/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use autocfg::AutoCfg;

// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script.
fn main() {
let cfg = match AutoCfg::new() {
Ok(cfg) => cfg,
Err(e) => {
println!(
"cargo:warning=futures-core: unable to determine rustc version: {}",
e
);
return;
}
};

if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=has_atomic_cas");
}
println!("cargo:rerun-if-changed=build.rs");
}
7 changes: 1 addition & 6 deletions futures-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//! All items of this library are only available when the `std` or `alloc` feature of this
//! library is activated, and it is activated by default.

#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]

#![cfg_attr(not(feature = "std"), no_std)]

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

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

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

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(has_atomic_cas)]
$item
)*};
}
Expand Down
8 changes: 5 additions & 3 deletions futures-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ default = ["std"]
std = ["alloc"]
alloc = []

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

[build-dependencies]
autocfg = "1"

[dependencies]

[dev-dependencies]
Expand Down
22 changes: 22 additions & 0 deletions futures-core/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use autocfg::AutoCfg;

// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script.
fn main() {
let cfg = match AutoCfg::new() {
Ok(cfg) => cfg,
Err(e) => {
println!(
"cargo:warning=futures-core: unable to determine rustc version: {}",
e
);
return;
}
};

if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=has_atomic_cas");
}
println!("cargo:rerun-if-changed=build.rs");
}
5 changes: 0 additions & 5 deletions futures-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Core traits and types for asynchronous operations in Rust.

#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]

#![cfg_attr(not(feature = "std"), no_std)]

#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
Expand All @@ -16,9 +14,6 @@

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

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

#[cfg(feature = "alloc")]
extern crate alloc;

Expand Down
4 changes: 2 additions & 2 deletions futures-core/src/task/__internal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(has_atomic_cas)]
mod atomic_waker;
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(has_atomic_cas)]
pub use self::atomic_waker::AtomicWaker;
8 changes: 5 additions & 3 deletions futures-task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ default = ["std"]
std = ["alloc", "once_cell"]
alloc = []

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

[build-dependencies]
autocfg = "1"

[dependencies]
once_cell = { version = "1.3.1", default-features = false, features = ["std"], optional = true }

Expand Down
22 changes: 22 additions & 0 deletions futures-task/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use autocfg::AutoCfg;

// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script.
fn main() {
let cfg = match AutoCfg::new() {
Ok(cfg) => cfg,
Err(e) => {
println!(
"cargo:warning=futures-core: unable to determine rustc version: {}",
e
);
return;
}
};

if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=has_atomic_cas");
}
println!("cargo:rerun-if-changed=build.rs");
}
7 changes: 1 addition & 6 deletions futures-task/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Tools for working with tasks.

#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]

#![cfg_attr(not(feature = "std"), no_std)]

#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
Expand All @@ -16,15 +14,12 @@

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

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

#[cfg(feature = "alloc")]
extern crate alloc;

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(has_atomic_cas)]
$item
)*};
}
Expand Down
8 changes: 7 additions & 1 deletion futures-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ channel = ["std", "futures-channel"]
# These features are outside of the normal semver guarantees and require the
# `unstable` feature as an explicit opt-in to unstable API.
unstable = ["futures-core/unstable", "futures-task/unstable"]
cfg-target-has-atomic = ["futures-core/cfg-target-has-atomic", "futures-task/cfg-target-has-atomic"]
bilock = []
read-initializer = ["io", "futures-io/read-initializer", "futures-io/unstable"]
write-all-vectored = ["io"]

# These features are no longer used.
# TODO: remove in the next major version.
cfg-target-has-atomic = []

[build-dependencies]
autocfg = "1"

[dependencies]
futures-core = { path = "../futures-core", version = "0.3.8", default-features = false }
futures-task = { path = "../futures-task", version = "0.3.8", default-features = false }
Expand Down
22 changes: 22 additions & 0 deletions futures-util/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use autocfg::AutoCfg;

// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script.
fn main() {
let cfg = match AutoCfg::new() {
Ok(cfg) => cfg,
Err(e) => {
println!(
"cargo:warning=futures-core: unable to determine rustc version: {}",
e
);
return;
}
};

if cfg.probe_expression("core::sync::atomic::AtomicPtr::<()>::compare_exchange") {
println!("cargo:rustc-cfg=has_atomic_cas");
}
println!("cargo:rerun-if-changed=build.rs");
}
6 changes: 1 addition & 5 deletions futures-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Combinators and utilities for working with `Future`s, `Stream`s, `Sink`s,
//! and the `AsyncRead` and `AsyncWrite` traits.

#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
#![cfg_attr(feature = "read-initializer", feature(read_initializer))]
#![cfg_attr(feature = "write-all-vectored", feature(io_slice_advance))]

Expand All @@ -20,9 +19,6 @@

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

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

#[cfg(all(feature = "bilock", not(feature = "unstable")))]
compile_error!("The `bilock` feature requires the `unstable` feature as an explicit opt-in to unstable features");

Expand Down Expand Up @@ -61,7 +57,7 @@ pub mod __private {

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(has_atomic_cas)]
$item
)*};
}
Expand Down
6 changes: 3 additions & 3 deletions futures-util/src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ pub use self::stream::ReadyChunks;
#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
pub use self::stream::Forward;

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

#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(has_atomic_cas)]
#[cfg(feature = "sink")]
#[cfg_attr(docsrs, doc(cfg(feature = "sink")))]
#[cfg(feature = "alloc")]
Expand All @@ -53,7 +53,7 @@ pub use self::try_stream::{
#[cfg(feature = "std")]
pub use self::try_stream::IntoAsyncRead;

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

Expand Down
Loading

0 comments on commit 0a07109

Please sign in to comment.