A couple options come to mind to me:
- Only have default features that every platform will support. This way you don't need to opt-out, instead you always opt-in per platform.
- Use other conditions in
cfg
more. If your features are conditional based on OS, architecture, CPU features, etc then you probably are better off using conditions other thanfeature
. See the reference for more information. - Use a separate build script. Cargo doesn't scale well by itself for larger projects, so separate scripts which run cargo are common. You could use Makefile, shell scripts, or even look into tools like
cargo-make
andjust
. From there, you can do platform-specific build logic or even read variables from a.env
like you mentioned you wanted.