I recently added some SIMD code paths to a library. I put the code paths behind some #[cfg(all( target_cpu = "x86_64", target_feature = "avx", target_feature = "sse4.1" ))] gates, which my development computer supports, but I'm finding that I have to jump through some hoops to get those code paths recognized when I run tests. I wonder what is the expected or documented behavior for tests/benchmarks that depend on conditional compilation.
Some details:
cargo test runs test without the SIMD code paths compiled
RUSTFLAGS='-C target-cpu=native' cargo test runs tests with the SIMD code paths compiled
cargo bench runs benchmarks with the SIMD code paths compiled, without needing the RUSTFLAGS env var
cargo bench on Windows runs benchmarks with the SIMD code paths compiled, but the avx/sse intrinsic functions panic
RUSTFLAGS='-C target-cpu=native' cargo bench on Windows (that's not the windows syntax for env vars though) runs benchmarks with SIMD code paths compiled, and functioning correctly
cargo test and cargo check behave the same; the #[cfg] attributes never turn on compilation unless compiled with target-cpu=native
The tests are in their own test modules with #[cfg(test)] followed by the cpu feature #[cfg]s. Removing them lets them get run in tests without forcing target-cpu=native, but I figure that would make it impossible for a person on a computer without those CPU features to run tests.
It's especially frustrating because my editor cargo checks on save, as many do, and it does so without any RUSTFLAGS env var, so modifying a file immediately after running a test, or vice versa, results in a lot of time spent recompiling criterion and the rest of my dev dependencies for a different target.