kconfig-rs

Crates.iokconfig-rs
lib.rskconfig-rs
version0.3.1
created_at2025-08-16 19:44:49.817137+00
updated_at2025-08-26 09:37:37.638477+00
descriptionBuild library for translating Kconfig into Rust cfgs
homepagehttps://git.onea.ro/cococeapa/cococeapa/tools/kconfig-rs
repositoryhttps://git.onea.ro/cococeapa/cococeapa/tools/kconfig-rs
max_upload_size
id1798802
size9,891
Alexandru N. Onea (alexonea)

documentation

https://docs.rs/kconfig-rs

README

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.

Commit count: 0

cargo fmt