feat: add compile_error! when no crypto backend is enabled - #569
Conversation
|
Is moving the bulk of lib.rs into lib_inner.rs actually required here? |
|
Initially, I tried adding a conditional I then attempted to apply a file-level Another possible approach would be to create a dedicated module that encapsulates all |
|
What about removing ring as a feature, and making that crate the default when the aws-lc-rs feature (which would still be a default feature) is disabled? This would ensure that exactly one crypto backend is available no matter the configuration. |
|
@EpicEric thank you, however I've ultimately decided to proceed with this PR to avoid having to unconditionally compile Even though features officially must be additive, multiple large crates (e.g. sqlx) simulate mutual exclusivity this way |
Summary
Restrict the library implementation so that, when no crypto backend feature is chosen, the crate halts immediately at the intended
compile_error!instead of compiling the rest of the code.Details
lib.rsbody intosrc/lib_inner.rsand gated it with#[cfg(any(feature = "ring", feature = "aws-lc-rs"))] include!("lib_inner.rs");.compile_error!inlib.rs, ensuring it is the only thing compiled when no backend feature is enabled.#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]so existing macro usage keeps working under the new layout.Why
Previously, turning off all crypto features caused a long cascade of “module not found” errors despite the guard. By preventing the remaining modules from compiling without a backend, the build now stops immediately with the clear message.
Reproduction
compile_error!reminding users to enableringoraws-lc-rs.Compatibility
aws-lc-rs(default) orring; normal builds still pass.