Conditionally add crate-level feature

Hello,

I have a crate that provides fonctions that are enabled only for a specific architecture and specific feature.
For exemple, I have a function that is enabled only for aarch64 with feature crc.
In this function I use intrinsics like core::arch::aarch64::__crc32cb that is unstable and it need the crate-level feature stdsimd.
I still want to be able to compile the crate with stable rust if we don't use the feature crc. But If the user want crc feature, I want to enable the stdsimd feature only in that case.
The problem I have is that i don't know how i can add #![feature(stdsimd)] only if target_feature = "crc" is enabled.

Is there a way to do that? how can i manage this properly?

Thank you

You are probably looking for the #[cfg_attr] attribute to conditionally enable/disable other attributes when a condition is satisfied.

Here's an article which explains it in more detail:

1 Like

Thank you,
This is exactly what I need :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.