list-features 0.1.2

Extracts the list of enabled feature flags during compilation.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented1 out of 5 items with examples
  • Size
  • Source code size: 19.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.24 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ddernon

list-features

crates.io license minimum suppported rust version docs.rs pipeline status

Extracts the list of enabled feature flags during compilation. These flags can then be saved and displayed at run-time.

Highlights

  • Zero dependencies: This crate has no dependency and won’t, in its typical use case, be a run-time dependency.
  • Low Rust version requirement: Compatible with Rust version 1.58 (see also Windows 7 compatibility).
  • Tiny: It does one thing and there’s no plan to add more. Excluding tests/docs, the library is currently under 80 lines of code.

If these characteristics are not important for your use case, the built or toml crates might be more appropriate for your needs. Otherwise, stick around :)

Usage

Add list-features as a build dependency.
Use it in your build.rs script to obtain the list of enabled features for the current build.
Include that list where you need it, for instance in main.rs.

Example

// In build.rs
let out_dir = std::env::var("OUT_DIR").unwrap();
let build_info_path = format!("{out_dir}/build_info.rs");
let features = list_features::list_enabled_as_string("ENABLED_FEATURES");
std::fs::write(build_info_path, features).unwrap();

// In main.rs
include!(concat!(env!("OUT_DIR"), "/build_info.rs"));
println!("Features: {:?}", ENABLED_FEATURES);

See also the example crate and the docs.

Windows 7 compatibility

The minimum required Rust version is 1.58. While this is unlikely to change in the foreseeable future, the main objective is to remain at or below Rust 1.77, so as to preserve Windows 7 compatibility.

To test with Rust 1.77:

  • Change version = 4 to version = 3 in Cargo.lock.
  • Install the 1.77 target: rustup install 1.77.0-x86_64-pc-windows-gnu.
  • Then run clippy and the tests as follows:
cargo +1.77 clippy
cargo +1.77 test --features test