Question about conditional compilation


The bitpacking crate uses simd instructions if available.

stdsimd is not available in stable at the moment.
I would like projects that depend on this crate to compile in stable (and not benefit from SIMD) and in nightly (and benefit from the better performance SIMD).

Is there a way to detect that a rust feature gate is available? and if so, enable it?

I have seen packages using a nightly crate feature to do that. I am unhappy about this solution for various reasons : it assumes something about rustc version, it is not transparent for the user etc.

In my case, the package is expected to deliver the same result in nightly and stable. The only difference is performance.


No, but you can use the rustc_version crate in a build script to detect a version in which the feature exists, then define a cfg or feature flag which is then used in the code.

That said, as a user: please don’t go automatically enabling unstable features in nightly by default. I want to be able to use a nightly compiler for things like unstable compiler flags and other features in my code without dependencies changing behaviour behind my back.


Yes I was hacking something with rustc_version. Your point makes sense though. I’ll use just put that as a feature then.