2 unstable releases

0.2.0 Aug 20, 2023
0.1.0 Aug 12, 2023

#2234 in Parser implementations

Download history 49/week @ 2024-02-13 35/week @ 2024-02-20 17/week @ 2024-02-27 2/week @ 2024-03-05 19/week @ 2024-03-12 31/week @ 2024-03-19 7/week @ 2024-03-26 30/week @ 2024-04-02

71 downloads per month

MIT license

165KB
4.5K SLoC


Tux, the pinguin

A Kconfig parser written in rust.

Build status code coverage Minimum supported rust version: 1.56.0 or plus crates.io Version

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 config entry: We define a config named EFI. The next lines are the attributes of this entry.
  • EFI is a boolean config.
  • EFI depends on the config MMU.
  • Its default value is y.
  • If EFI is equals to true then it enables EFI_STUB.
  • The help attribute 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 entris can be found here.
  • List of supported attributes can be found here.
  • When source is 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::{kconfig::parse_kconfig, KconfigInput, KconfigFile};

// 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 kconfig_file = KconfigFile::new(
        PathBuf::from("/tmp/linux-6.4.9"), 
        PathBuf::from("/tmp/linux-6.4.9/Kconfig")
    );
    let input = kconfig_file.read_to_string().unwrap();
    let kconfig = parse_kconfig(KconfigInput::new_extra(&input, kconfig_file));
    println!("{:?}", kconfig);
    Ok(())
}

Resources

Dependencies

~3–4.5MB
~76K SLoC