-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix build error with targets that do not support atomic CAS operations (
#12) Some no-std targets (e.g., ARMv6-M) do not support atomic CAS operations and cannot use `Arc`, etc. 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.
- Loading branch information
Showing
9 changed files
with
89 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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="valuable/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" |
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,31 @@ | ||
#![warn(rust_2018_idioms, single_use_lifetimes)] | ||
|
||
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=valuable: unable to get TARGET environment variable: {}", | ||
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=valuable_no_atomic_cas"); | ||
} | ||
|
||
println!("cargo:rerun-if-changed=no_atomic_cas.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,11 @@ | ||
// This file is @generated by no_atomic_cas.sh. | ||
// It is not intended for manual editing. | ||
|
||
const NO_ATOMIC_CAS_TARGETS: &[&str] = &[ | ||
"avr-unknown-gnu-atmega328", | ||
"msp430-none-elf", | ||
"riscv32i-unknown-none-elf", | ||
"riscv32imc-unknown-none-elf", | ||
"thumbv4t-none-eabi", | ||
"thumbv6m-none-eabi", | ||
]; |
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