autocfg
Automatic cfg for Rust compiler features
This package has a good security score with no known vulnerabilities.
Community Reviews
Reliable build-time feature detection with minimal learning curve
The documentation is sparse but functional. The examples in the repository README cover the common cases (checking for std features, type availability, expression validity), and that's honestly enough for most uses. Error messages when probes fail are silent by design - it just returns false - which makes sense for feature detection but can be confusing initially if you have typos.
Debugging is reasonable since you can inspect the generated features in your build output. The main gotcha is understanding that this runs at build time, so mistakes don't surface until compilation. For library authors needing conditional compilation based on Rust version or feature availability, it's a time-saver that just works.
Best for: Library authors who need to conditionally enable features based on Rust compiler version or available standard library components.
Avoid if: You're building application code that doesn't need cross-version compatibility or build-time feature detection.
Essential build-time tool, minimal learning curve but sparse examples
The main challenge is that documentation is minimal. The crate docs explain what each function does, but there are very few complete examples showing real-world usage patterns. I found myself reading other crates' build.rs files (like rayon, num-traits) to understand best practices. Error messages are generally unhelpful - probes just return bool, so debugging why a feature isn't detected requires manually inspecting the underlying compiler output.
Day-to-day usage is smooth once set up. The API rarely changes, so code written years ago still works. It's a specialized tool that does one thing well, but expect to invest time upfront learning through experimentation rather than comprehensive tutorials.
Best for: Library authors who need to support multiple Rust compiler versions with conditional compilation based on available features.
Avoid if: You're building application code that can simply declare a minimum supported Rust version (MSRV) instead of adapting to different compiler capabilities.
Reliable build-time feature detection with minimal security surface
In practice, it's straightforward to use. You instantiate AutoCfg in your build script, call probe methods like `probe_type()` or `probe_path()`, and emit the appropriate `cargo:rustc-cfg` directives. The API is well-documented with clear examples. Error handling is sensible—failures to probe features are treated as absence rather than panicking, which is the correct default behavior.
The main limitation is that it's purely a build-time tool with no runtime implications. It doesn't validate inputs from external sources or handle crypto, but that's by design. For supply chain risk, having zero dependencies is a significant advantage—there's no transitive dependency tree to audit.
Best for: Libraries needing robust, version-agnostic detection of Rust compiler features in build scripts with minimal dependency risk.
Avoid if: You need runtime feature detection or configuration based on system properties rather than compiler capabilities.
Sign in to write a review
Sign In