7 releases (breaking)
| 0.6.0 | Jan 13, 2026 |
|---|---|
| 0.5.0 | Dec 30, 2025 |
| 0.4.0 | Sep 7, 2025 |
| 0.3.0 | Apr 20, 2025 |
| 0.1.0 | Aug 12, 2023 |
#639 in Parser implementations
200KB
5.5K
SLoC
A Kconfig parser written in rust.
Kconfig is a language that describes configuration options for the Linux Kernel. The syntax looks like this:
# https://github.com/torvalds/linux/blob/master/arch/riscv/Kconfig#L771
config EFI
bool "UEFI runtime support"
depends on MMU
default y
select EFI_STUB
help
This option provides support for runtime services provided
by UEFI firmware.
- The file starts with a
configentry: We define a config namedEFI. The next lines are the attributes of this entry. EFIis a boolean config.EFIdepends on the configMMU.- Its default value is
y. - If
EFIis equals totruethen it enablesEFI_STUB. - The
helpattribute defines a help text for the end user.
There are plenty of other keywords in the Kconfig language, check out the official documentation for more details.
Features
- This is a parser, there is no semantic analysis in this library.
- This library only supports UTF-8 encoded files.
- List of supported entries can be found here.
- List of supported attributes can be found here.
- When
sourceis met, it reads and parses the specified configuration file. - This library uses
clone()a lot. Do not expect amazing performances. - This parser has been tested on the Linux kernel repository from 2.6.11 to 6.4.9 (3733 versions).
Getting started
cargo add nom-kconfig
use std::path::PathBuf;
use nom_kconfig::{parse_kconfig, KconfigInput, KconfigFile};
use std::collections::HashMap;
// curl https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.4.9.tar.xz | tar -xJ -C /tmp/
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut variables = HashMap::new();
variables.insert("SRCARCH", "x86");
let kconfig_file = KconfigFile::new_with_vars(
PathBuf::from("/tmp/linux-6.4.9"),
PathBuf::from("/tmp/linux-6.4.9/Kconfig"),
&variables
);
let input = kconfig_file.read_to_string()?;
let kconfig = parse_kconfig(KconfigInput::new_extra(&input, kconfig_file));
println!("{:?}", kconfig);
Ok(())
}
Resources
Dependencies
~2.7–4MB
~73K SLoC