|
| 1 | +// Copyright (c) 2025 Hermit contributors |
| 2 | +// SPDX-License-Identifier: MIT OR Apache-2.0 |
| 3 | + |
| 4 | +use alloc::{collections::btree_map as btm, string::String, vec::Vec}; |
| 5 | + |
| 6 | +pub const DEFAULT_CONFIG_NAME: &'static str = "hermit_config.toml"; |
| 7 | +pub type ParserError = toml::de::Error; |
| 8 | + |
| 9 | +#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)] |
| 10 | +/// The image `hermit_config.toml` config file format. |
| 11 | +/// |
| 12 | +/// All file paths are relative to the iamge root. |
| 13 | +pub struct Config { |
| 14 | + pub input: Input, |
| 15 | + pub requirements: Requirements, |
| 16 | + |
| 17 | + pub kernel: String, |
| 18 | + pub file_mapping: btm::BTreeMap<String, String>, |
| 19 | +} |
| 20 | + |
| 21 | +#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)] |
| 22 | +pub struct Input { |
| 23 | + /// Arguments to be passed to the kernel |
| 24 | + pub kernel_args: Vec<String>, |
| 25 | + |
| 26 | + /// Arguments to be passed to the application |
| 27 | + pub app_args: Vec<String>, |
| 28 | + |
| 29 | + /// Environment variables |
| 30 | + pub env_vars: Vec<String>, |
| 31 | +} |
| 32 | + |
| 33 | +#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)] |
| 34 | +pub struct Requirements { |
| 35 | + pub memory: Option<byte_unit::Byte>, |
| 36 | + |
| 37 | + #[serde(default)] |
| 38 | + pub cpus: u32, |
| 39 | +} |
| 40 | + |
| 41 | +#[inline] |
| 42 | +pub fn parse(data: &[u8]) -> Result<Config, ParserError> { |
| 43 | + toml::from_slice(data) |
| 44 | +} |
0 commit comments