Skip to content
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

Add require-cas feature #100

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ float = []
# Use `std`.
std = []

# Emit compile error if atomic CAS is not available.
require-cas = []

# Note: serde and critical-section are public dependencies.
[dependencies]
# Implements serde::{Serialize,Deserialize} for atomic types.
Expand Down
3 changes: 2 additions & 1 deletion portable-atomic-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ alloc = []
# generic = []

[dependencies]
portable-atomic = { version = "1", path = "..", default-features = false }
# TODO: use version 1.3 once portable-atomic with require-cas feature released.
portable-atomic = { version = "1", path = "..", default-features = false, features = ["require-cas"] }
31 changes: 29 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ compile_error!(
))
)]
compile_error!(
"cfg(portable_atomic_unsafe_assume_single_core) does not compatible with this target; \
if you need cfg(portable_atomic_unsafe_assume_single_core) support for this target, \
"cfg(portable_atomic_unsafe_assume_single_core) does not compatible with this target;\n\
if you need cfg(portable_atomic_unsafe_assume_single_core) support for this target,\n\
please submit an issue at <https://github.com/taiki-e/portable-atomic>"
);

Expand Down Expand Up @@ -402,6 +402,33 @@ compile_error!(
"you may not enable feature `critical-section` and cfg(portable_atomic_unsafe_assume_single_core) at the same time"
);

#[cfg(feature = "require-cas")]
#[cfg_attr(
portable_atomic_no_cfg_target_has_atomic,
cfg(not(any(
not(portable_atomic_no_atomic_cas),
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
)))
)]
#[cfg_attr(
not(portable_atomic_no_cfg_target_has_atomic),
cfg(not(any(
target_has_atomic = "ptr",
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
)))
)]
compile_error!(
"dependents require atomic CAS but not available on this target by default;\n\
consider using portable_atomic_unsafe_assume_single_core cfg or critical-section feature.\n\
see <https://docs.rs/portable-atomic/latest/portable_atomic/#optional-cfg> for more."
);

#[cfg(any(test, feature = "std"))]
extern crate std;

Expand Down
10 changes: 7 additions & 3 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,13 @@ build() {
else
echo "target '${target}' requires asm to implement atomic CAS (skipped build with --cfg portable_atomic_unsafe_assume_single_core)"
fi
# portable-atomic-util uses atomic CAS, so doesn't work on
# this target without portable_atomic_unsafe_assume_single_core cfg.
args+=(--exclude portable-atomic-util)
# portable-atomic-util crate and portable-atomic's require-cas feature require atomic CAS,
# so doesn't work on this target without portable_atomic_unsafe_assume_single_core cfg
# or critical-section feature.
args+=(
--exclude portable-atomic-util
--exclude-features require-cas
)
fi
fi
fi
Expand Down