Skip to content

Commit

Permalink
Remove uses of unstable feature(cfg_target_has_atomic)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed May 15, 2021
1 parent 3e83987 commit cbaad86
Show file tree
Hide file tree
Showing 25 changed files with 255 additions and 38 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -86,14 +86,27 @@ jobs:
- name: dependency tree check
run: ./ci/dependencies.sh

# When this job failed, run ci/no_atomic_cas.sh and commit result changes.
# TODO(taiki-e): Ideally, this should be automated using a bot that creates
# PR when failed, but there is no bandwidth to implement it
# right now...
codegen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: ci/no_atomic_cas.sh
- run: git diff --exit-code

# Check formatting.
rustfmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update stable && rustup default stable
run: rustup update stable
- name: rustfmt
run: ./ci/rustfmt.sh

Expand All @@ -104,7 +117,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update stable && rustup default stable
run: rustup update stable
- name: clippy
run: ./ci/clippy.sh

Expand All @@ -126,7 +139,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update stable && rustup default stable
run: rustup update stable
- name: loom
run: ./ci/crossbeam-epoch-loom.sh

Expand Down Expand Up @@ -154,6 +167,7 @@ jobs:
- test
- features
- dependencies
- codegen
- rustfmt
- clippy
- san
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Expand Up @@ -36,8 +36,9 @@ alloc = ["crossbeam-epoch/alloc", "crossbeam-queue/alloc"]

# Enable to use of unstable functionality.
# This is disabled by default and requires recent nightly compiler.
# Note that this is outside of the normal semver guarantees and minor versions
# of crossbeam may make breaking changes to them at any time.
#
# NOTE: This feature is outside of the normal semver guarantees and minor or
# patch versions of crossbeam may make breaking changes to them at any time.
nightly = ["crossbeam-epoch/nightly", "crossbeam-utils/nightly", "crossbeam-queue/nightly"]

[dependencies]
Expand Down
32 changes: 32 additions & 0 deletions build.rs
@@ -0,0 +1,32 @@
#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic_cas.rs");

// 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 target = match env::var("TARGET") {
Ok(target) => target,
Err(e) => {
println!(
"cargo:warning={}: unable to get TARGET environment variable: {}",
env!("CARGO_PKG_NAME"),
e
);
return;
}
};

// Note that this is `no_*`, not `has_*`. This allows treating
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
// run. This is needed for compatibility with non-cargo build systems that
// don't run the build script.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
4 changes: 1 addition & 3 deletions ci/check-features.sh
Expand Up @@ -22,7 +22,5 @@ else
rustup target add thumbv7m-none-eabi
rustup target add thumbv6m-none-eabi
cargo hack check --all --feature-powerset --no-dev-deps --exclude benchmarks --target thumbv7m-none-eabi --skip std,default
# * `--features nightly` is required for enable `cfg_target_has_atomic`.
# * `--ignore-unknown-features` - some crates doesn't have 'nightly' feature
cargo hack check --all --feature-powerset --no-dev-deps --exclude benchmarks --target thumbv6m-none-eabi --skip std,default --features nightly --ignore-unknown-features
cargo hack check --all --feature-powerset --no-dev-deps --exclude benchmarks --target thumbv6m-none-eabi --skip std,default
fi
28 changes: 28 additions & 0 deletions ci/no_atomic_cas.sh
@@ -0,0 +1,28 @@
#!/bin/bash

# Update the list of targets that do not support atomic CAS operations.
#
# Usage:
# ./ci/no_atomic_cas.sh

set -euo pipefail
IFS=$'\n\t'

cd "$(cd "$(dirname "$0")" && pwd)"/..

file="no_atomic_cas.rs"

{
echo "// This file is @generated by $(basename "$0")."
echo "// It is not intended for manual editing."
echo ""
echo "const NO_ATOMIC_CAS_TARGETS: &[&str] = &["
} >"$file"

for target in $(rustc --print target-list); do
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
| jq -r "select(.\"atomic-cas\" == false)")
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
done

echo "];" >>"$file"
2 changes: 2 additions & 0 deletions crossbeam-channel/Cargo.toml
Expand Up @@ -20,6 +20,8 @@ default = ["std"]

# Enable to use APIs that require `std`.
# This is enabled by default.
#
# NOTE: Disabling `std` feature is not supported yet.
std = ["crossbeam-utils/std"]

[dependencies]
Expand Down
2 changes: 2 additions & 0 deletions crossbeam-deque/Cargo.toml
Expand Up @@ -20,6 +20,8 @@ default = ["std"]

# Enable to use APIs that require `std`.
# This is enabled by default.
#
# NOTE: Disabling `std` feature is not supported yet.
std = ["crossbeam-epoch/std", "crossbeam-utils/std"]

[dependencies]
Expand Down
15 changes: 9 additions & 6 deletions crossbeam-epoch/Cargo.toml
Expand Up @@ -24,18 +24,21 @@ std = ["alloc", "crossbeam-utils/std", "lazy_static"]

# Enable to use APIs that require `alloc`.
# This is enabled by default and also enabled if the `std` feature is enabled.
#
# NOTE: Disabling both `std` *and* `alloc` features is not supported yet.
alloc = []

# Enable to use of unstable functionality.
# This is disabled by default and requires recent nightly compiler.
# Note that this is outside of the normal semver guarantees and minor versions
# of crossbeam may make breaking changes to them at any time.
#
# NOTE: This feature is outside of the normal semver guarantees and minor or
# patch versions of crossbeam may make breaking changes to them at any time.
nightly = ["crossbeam-utils/nightly", "const_fn"]

# Enable the use of loom for concurrency testing.
#
# This configuration option is outside of the normal semver guarantees: minor
# versions of crossbeam may make breaking changes to it at any time.
# NOTE: This feature is outside of the normal semver guarantees and minor or
# patch versions of crossbeam may make breaking changes to them at any time.
loom = ["loom-crate", "crossbeam-utils/loom"]

[dependencies]
Expand All @@ -45,8 +48,8 @@ memoffset = "0.6"

# Enable the use of loom for concurrency testing.
#
# This configuration option is outside of the normal semver guarantees: minor
# versions of crossbeam may make breaking changes to it at any time.
# NOTE: This feature is outside of the normal semver guarantees and minor or
# patch versions of crossbeam may make breaking changes to them at any time.
[target.'cfg(crossbeam_loom)'.dependencies]
loom-crate = { package = "loom", version = "0.5", optional = true }

Expand Down
32 changes: 32 additions & 0 deletions crossbeam-epoch/build.rs
@@ -0,0 +1,32 @@
#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic_cas.rs");

// 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 target = match env::var("TARGET") {
Ok(target) => target,
Err(e) => {
println!(
"cargo:warning={}: unable to get TARGET environment variable: {}",
env!("CARGO_PKG_NAME"),
e
);
return;
}
};

// Note that this is `no_*`, not `has_*`. This allows treating
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
// run. This is needed for compatibility with non-cargo build systems that
// don't run the build script.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
1 change: 1 addition & 0 deletions crossbeam-epoch/no_atomic_cas.rs
5 changes: 2 additions & 3 deletions crossbeam-epoch/src/lib.rs
Expand Up @@ -62,7 +62,6 @@
unreachable_pub
)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))]
#![cfg_attr(feature = "nightly", feature(const_fn_trait_bound))]

#[cfg(crossbeam_loom)]
Expand Down Expand Up @@ -143,7 +142,7 @@ mod primitive {
pub(crate) use core::sync::atomic::fence;
pub(crate) use core::sync::atomic::AtomicUsize;
}
#[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))]
#[cfg(not(crossbeam_no_atomic_cas))]
pub(crate) use alloc::sync::Arc;
}

Expand All @@ -154,7 +153,7 @@ mod primitive {
pub(crate) use lazy_static::lazy_static;
}

#[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))]
#[cfg(not(crossbeam_no_atomic_cas))]
cfg_if! {
if #[cfg(feature = "alloc")] {
extern crate alloc;
Expand Down
9 changes: 7 additions & 2 deletions crossbeam-queue/Cargo.toml
Expand Up @@ -24,12 +24,17 @@ std = ["alloc", "crossbeam-utils/std"]

# Enable to use APIs that require `alloc`.
# This is enabled by default and also enabled if the `std` feature is enabled.
#
# NOTE: Disabling both `std` *and* `alloc` features is not supported yet.
alloc = []

# These features are no longer used.
# TODO: remove in the next major version.
# Enable to use of unstable functionality.
# This is disabled by default and requires recent nightly compiler.
# Note that this is outside of the normal semver guarantees and minor versions
# of crossbeam may make breaking changes to them at any time.
#
# NOTE: This feature is outside of the normal semver guarantees and minor or
# patch versions of crossbeam may make breaking changes to them at any time.
nightly = ["crossbeam-utils/nightly"]

[dependencies]
Expand Down
32 changes: 32 additions & 0 deletions crossbeam-queue/build.rs
@@ -0,0 +1,32 @@
#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic_cas.rs");

// 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 target = match env::var("TARGET") {
Ok(target) => target,
Err(e) => {
println!(
"cargo:warning={}: unable to get TARGET environment variable: {}",
env!("CARGO_PKG_NAME"),
e
);
return;
}
};

// Note that this is `no_*`, not `has_*`. This allows treating
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
// run. This is needed for compatibility with non-cargo build systems that
// don't run the build script.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
1 change: 1 addition & 0 deletions crossbeam-queue/no_atomic_cas.rs
3 changes: 1 addition & 2 deletions crossbeam-queue/src/lib.rs
Expand Up @@ -19,9 +19,8 @@
unreachable_pub
)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))]

#[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))]
#[cfg(not(crossbeam_no_atomic_cas))]
cfg_if::cfg_if! {
if #[cfg(feature = "alloc")] {
extern crate alloc;
Expand Down
8 changes: 2 additions & 6 deletions crossbeam-skiplist/Cargo.toml
Expand Up @@ -24,14 +24,10 @@ std = ["alloc", "crossbeam-epoch/std", "crossbeam-utils/std"]

# Enable to use APIs that require `alloc`.
# This is enabled by default and also enabled if the `std` feature is enabled.
#
# NOTE: Disabling both `std` *and* `alloc` features is not supported yet.
alloc = ["crossbeam-epoch/alloc"]

# Enable to use of unstable functionality.
# This is disabled by default and requires recent nightly compiler.
# Note that this is outside of the normal semver guarantees and minor versions
# of crossbeam may make breaking changes to them at any time.
nightly = ["crossbeam-epoch/nightly", "crossbeam-utils/nightly"]

[dependencies]
cfg-if = "1"

Expand Down
32 changes: 32 additions & 0 deletions crossbeam-skiplist/build.rs
@@ -0,0 +1,32 @@
#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic_cas.rs");

// 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 target = match env::var("TARGET") {
Ok(target) => target,
Err(e) => {
println!(
"cargo:warning={}: unable to get TARGET environment variable: {}",
env!("CARGO_PKG_NAME"),
e
);
return;
}
};

// Note that this is `no_*`, not `has_*`. This allows treating
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
// run. This is needed for compatibility with non-cargo build systems that
// don't run the build script.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
1 change: 1 addition & 0 deletions crossbeam-skiplist/no_atomic_cas.rs
3 changes: 1 addition & 2 deletions crossbeam-skiplist/src/lib.rs
Expand Up @@ -242,11 +242,10 @@
unreachable_pub
)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))]

use cfg_if::cfg_if;

#[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))]
#[cfg(not(crossbeam_no_atomic_cas))]
cfg_if! {
if #[cfg(feature = "alloc")] {
extern crate alloc;
Expand Down

0 comments on commit cbaad86

Please sign in to comment.