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

Add require-cas feature #100

merged 1 commit into from
Apr 28, 2023

Conversation

taiki-e
Copy link
Owner

@taiki-e taiki-e commented Apr 25, 2023

Provide better error message if dependents require atomic CAS but the end user forgets to use single-core cfg or critical-section feature.

Context: mvdnes/spin-rs#151

cc @zesterer

Example (with spin-rs)

Enable require-cas feature on spin (taiki-e/spin-rs@990fa92)

- portable-atomic = { version = "1", optional = true, default-features = false }
+ # Enable require-cas feature to provide a better error message if the end user forgets to use cfg.
+ portable-atomic = { version = "1", optional = true, default-features = false, features = ["require-cas"] }

Then, when building spin without single-core cfg or CS feature, the following error message will be displayed.

# without cfg
$ cargo build --target thumbv6m-none-eabi --no-default-features --features spin_mutex,portable_atomic
error: dependents require atomic CAS but not available on this target by default;
       consider using portable_atomic_unsafe_assume_single_core cfg or critical-section feature.
       see <https://docs.rs/portable-atomic/latest/portable_atomic/#optional-cfg> for more.
   --> /Users/taiki/.cargo/git/checkouts/portable-atomic-1ec81f4f47ac5a29/dd55758/src/lib.rs:426:1
    |
426 | / compile_error!(
427 | |     "dependents require atomic CAS but not available on this target by default;\n\
428 | |     consider using portable_atomic_unsafe_assume_single_core cfg or critical-section feature.\n\
429 | |     see <https://docs.rs/portable-atomic/latest/portable_atomic/#optional-cfg> for more."
430 | | );
    | |_^

error: could not compile `portable-atomic` (lib) due to previous error

# with cfg
$ RUSTFLAGS='--cfg portable_atomic_unsafe_assume_single_core' cargo build --target thumbv6m-none-eabi --no-default-features --features spin_mutex,portable_atomic
    Finished dev [unoptimized + debuginfo] target(s) in 0.96s

Maybe we can improve more on the error messages.

Provide better error message if the end user forgets to use single-core
cfg or CS feature.
@taiki-e taiki-e merged commit 2d2027a into main Apr 28, 2023
@taiki-e taiki-e deleted the require-cas branch April 28, 2023 16:51
@taiki-e
Copy link
Owner Author

taiki-e commented May 6, 2023

Published in 1.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant