5 unstable releases
| 0.3.1 | Aug 26, 2025 |
|---|---|
| 0.3.0 | Aug 26, 2025 |
| 0.2.1 | Aug 26, 2025 |
| 0.2.0 | Aug 18, 2025 |
| 0.1.0 | Aug 16, 2025 |
#492 in Configuration
112 downloads per month
10KB
162 lines
kconfig-rs
Build library for translating Kconfig into Rust cfgs.
Given a .config, the kconfig-rs library generates rustc-cfg and rustc-check-cfg directives for conditional compilation. It does so by reading the .config file and translating options into Rust cfgs. Moreover, it generates a kconfig.rs file which may be included into the user crate for accesing typed versions of the configuration options defined in the .config file.
Usage
Add this package as a build dependency to your crate in Cargo.toml.
[build-dependencies]
kconfig-rs = "*"
In your build.rs script include the following invocation.
use kconfig_rs as kconfig;
fn main() {
...
kconfig::generate();
...
}
It does not matter where in the main function, the generate function is called.
The CARGO_KCONFIG_DOTCONFIG environment variable must be set and pointing to the .config file. The path to the .config file must be absolute. Several packages might share the same .config file. One might generate .config files from Kconfig using cargo-menuconfig.
To access the typed versions of the configuration options, include the generated kconfig.rs file anywhere in your crate.
mod config {
include!(concat!(env!(OUT_DIR), "/kconfig.rs"));
}
fn main() {
do_something(config::CONFIG_FOO);
}
The cargo build system will automatically rerun when the .config file changes.
Contributing
Please send feature requests and bug reports to alexandru at onea dot ro.