-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix build error with targets that do not support atomic CAS operations #12
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,41 @@ | ||
#![warn(rust_2018_idioms, single_use_lifetimes)] | ||
|
||
use std::env; | ||
|
||
include!("no_atomic_cas.rs"); | ||
|
||
// The rustc-cfg listed below are considered public API, but it is *unstable* | ||
// and outside of the normal semver guarantees: | ||
// | ||
// - `valuable_no_atomic_cas` | ||
// Assume the target does *not* support atomic CAS operations. | ||
// This is usually detected automatically by the build script, but you may | ||
// need to enable it manually when building for custom targets or using | ||
// non-cargo build systems that don't run the build script. | ||
// | ||
// With the exceptions mentioned above, 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
futures
, there was a question about compatibility with custom targets, so we exposed a similar cfg as an unstable public API.We can also treat it as a private API until there is an actual request, but this cfg is unstable and we can change/remove it at any time, so I think it is also ok as-is. (Whether this cfg is considered private or public depends on how the comments describe about it, so either way, it is a very simple change.)
Btw, one reason for the instability is that this cfg can eventually be replaced by
cfg(accessible)
. So I believe this cfg will never be a stable API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to implement similar detection logic for atomic integers later, so it's probably better to make this private for now. I'll update PR...
UPDATE: done in f7f1b95