I found myself refactoring a Rust crate in which I had two non-default features but at least one would need to be set in order for cargo build to function. Cargo allows a default feature set, or allows different targets to have required-features defined. My use-case is different unfortunately, I wanted slightly different semantics to support either s3 or azure features. I stopped by ##rust on libera.chat and as usually happens, got a nudge in the right direction: build.rs:

By adding the following to build.rs I was able to forcefully halt the build operation before it even really got started.

#[cfg(not(any(feature = "s3", feature = "azure")))]
compile_error!(
    "Either the \"s3\" or the \"azure\" feature must be enabled to compile"
);
fn main() {}

Using the compile_error! macro in build.rs ensures that users will only see the following compilation error message, rather than a long list of other errors which may come from missing feature definitions.

Quick and easy trick to get required non-default features enabled!