-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
698: Remove uses of unstable feature(cfg_target_has_atomic) r=taiki-e a=taiki-e Some no-std targets (e.g., ARMv6-M) do not support atomic CAS operations and cannot use Arc, etc. Currently, we are using an unstable feature to detect them, but it has caused breakage in the past (#435). Also, users of stable Rust are not able to compile crossbeam on those targets. Instead of depending on unstable features of the compiler, this patch detects those targets using the TARGET environment variables provided by cargo for the build script, and a list of targets that do not support atomic CAS operations. This way is the same as the way we recently adopted in [futures](rust-lang/futures-rs#2400) and [valuable](tokio-rs/valuable#12), and was originally inspired by the way [heapless](rust-embedded/heapless@44c66a7) and [defmt](https://github.com/knurling-rs/defmt/blob/963152f0fc530fca64ba4ff1492d9c4b7bf76062/build.rs#L42-L51) do, but this doesn't maintain the target list manually. (It's not really fully automated, but [it's very easy to update](https://github.com/crossbeam-rs/crossbeam/blob/a42dbed87a5739228b576f526b1e2fd80260a29b/.github/workflows/ci.yml#L89).) Also, this completely removes the dependency on unstable features from crates other than crossbeam-epoch. refs: rust-lang/rust#51953, rust-lang/futures-rs#2400, tokio-rs/valuable#12 704: Add AtomicCell::fetch_update r=taiki-e a=taiki-e Equivalent of [`std::sync::atomic::AtomicN::fetch_update`](https://doc.rust-lang.org/nightly/core/sync/atomic/struct.AtomicUsize.html#method.fetch_update) that stabilized in Rust 1.45. Co-authored-by: Taiki Endo <[email protected]>
- Loading branch information
Showing
29 changed files
with
436 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# Update the list of targets that do not support atomic/CAS operations. | ||
# | ||
# Usage: | ||
# ./ci/no_atomic.sh | ||
|
||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
cd "$(cd "$(dirname "$0")" && pwd)"/.. | ||
|
||
file="no_atomic.rs" | ||
|
||
{ | ||
echo "// This file is @generated by $(basename "$0")." | ||
echo "// It is not intended for manual editing." | ||
echo "" | ||
} >"$file" | ||
|
||
echo "const NO_ATOMIC_CAS: &[&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" | ||
|
||
{ | ||
# Only crossbeam-utils actually uses this const. | ||
echo "#[allow(dead_code)]" | ||
echo "const NO_ATOMIC_64: &[&str] = &[" | ||
} >>"$file" | ||
for target in $(rustc --print target-list); do | ||
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \ | ||
| jq -r "select(.\"max-atomic-width\" == 32)") | ||
[[ -z "$res" ]] || echo " \"$target\"," >>"$file" | ||
done | ||
# It is not clear exactly what `"max-atomic-width" == null` means, but they | ||
# actually seem to have the same max-atomic-width as the target-pointer-width. | ||
# The targets currently included in this group are "mipsel-sony-psp", | ||
# "thumbv4t-none-eabi", "thumbv6m-none-eabi", all of which are | ||
# `"target-pointer-width" == "32"`, so assuming them `"max-atomic-width" == 32` | ||
# for now. | ||
for target in $(rustc --print target-list); do | ||
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \ | ||
| jq -r "select(.\"max-atomic-width\" == null)") | ||
[[ -z "$res" ]] || echo " \"$target\"," >>"$file" | ||
done | ||
echo "];" >>"$file" | ||
|
||
# There is no `"max-atomic-width" == 16` or `"max-atomic-width" == 8` targets. | ||
|
||
# `"max-atomic-width" == 0` means that atomic is not supported at all. | ||
{ | ||
# Only crossbeam-utils actually uses this const. | ||
echo "#[allow(dead_code)]" | ||
echo "const NO_ATOMIC: &[&str] = &[" | ||
} >>"$file" | ||
for target in $(rustc --print target-list); do | ||
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \ | ||
| jq -r "select(.\"max-atomic-width\" == 0)") | ||
[[ -z "$res" ]] || echo " \"$target\"," >>"$file" | ||
done | ||
echo "];" >>"$file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![warn(rust_2018_idioms)] | ||
|
||
use std::env; | ||
|
||
include!("no_atomic.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.contains(&&*target) { | ||
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas"); | ||
} | ||
|
||
println!("cargo:rerun-if-changed=no_atomic.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../no_atomic.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![warn(rust_2018_idioms)] | ||
|
||
use std::env; | ||
|
||
include!("no_atomic.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.contains(&&*target) { | ||
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas"); | ||
} | ||
|
||
println!("cargo:rerun-if-changed=no_atomic.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../no_atomic.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.