Program-wide with RUSTFLAGS
Target features can be enabled program-wide by setting RUSTFLAGS.
The following example enables avx and avx2, and disables fma:
RUSTFLAGS="-Ctarget-features=+avx,+avx2,-fma" cargo build
Instead of targeting specific features, a particular CPU can be targeted:
RUSTFLAGS="-Ctarget-cpu=skylake" cargo build
Rust can also target your specific CPU, with the special native CPU:
RUSTFLAGS="-Ctarget-cpu=native" cargo build