Crate nom_kconfig

Crate nom_kconfig 

Source
Expand description

§nom-kconfig

A parser for kconfig files. The parsing is done with nom.

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().unwrap();
    let kconfig = parse_kconfig(KconfigInput::new_extra(&input, kconfig_file));
    println!("{:?}", kconfig);
    Ok(())
}

Re-exports§

pub use self::attribute::Attribute;
pub use self::entry::Entry;
pub use self::kconfig::parse_kconfig;
pub use self::kconfig::Kconfig;
pub use self::symbol::Symbol;

Modules§

attribute
Module defining the different attributes. A entry can have a number of attributes: https://www.kernel.org/doc/html/next/kbuild/kconfig-language.html#menu-attributes
entry
Module defining the different Kconfig entries. Most entries define a config option; all other entries help to organize them. https://www.kernel.org/doc/html/next/kbuild/kconfig-language.html#menu-entries
kconfig
symbol
util

Macros§

assert_parsing_eq
generic_config_parser

Structs§

KconfigFile
Represents a Kconfig file. It stores the kernel root directory because we need this information when a source keyword is met.

Type Aliases§

KconfigInput
KconfigInput is a struct gathering a KconfigFile and its associated content.