- axconfig-gen: A TOML-based configuration generation tool for ArceOS.
- axconfig-gen-macros: Procedural macros for converting TOML format configurations to Rust constant definitions.
Usage: axconfig-gen [OPTIONS] <SPEC>...
Arguments:
<SPEC>... Paths to the config specification files
Options:
-c, --oldconfig <OLDCONFIG> Path to the old config file
-o, --output <OUTPUT> Path to the output config file
-f, --fmt <FMT> The output format [default: toml] [possible values: toml, rust]
-r, --read <RD_CONFIG> Getting a config item with format `table.key`
-w, --write <WR_CONFIG> Setting a config item with format `table.key=value`
-v, --verbose Verbose mode
-h, --help Print help
-V, --version Print version
For example, to generate a config file .axconfig.toml
from the config specifications distributed in a.toml
and b.toml
, you can run:
$ axconfig-gen a.toml b.toml -o .axconfig.toml -f toml
See defconfig.toml for an example of a config specification file.
Value types are necessary for generating Rust constant definitions. Types can be specified by the comment following the config item. Currently supported types are bool
, int
, uint
, str
, (type1, type2, ...)
for tuples, and [type]
for arrays. If no type is specified, it will try to infer the type from the value.
use axconfig_gen::{Config, OutputFormat};
let config_toml = r#"
are-you-ok = true
one-two-three = 123
[hello]
"one-two-three" = "456" # int
array = [1, 2, 3] # [uint]
tuple = [1, "abc", 3]
"#;
let config = Config::from_toml(config_toml).unwrap();
let rust_code = config.dump(OutputFormat::Rust).unwrap();
assert_eq!(rust_code,
r#"pub const ARE_YOU_OK: bool = true;
pub const ONE_TWO_THREE: usize = 123;
pub mod hello {
pub const ARRAY: &[usize] = &[1, 2, 3];
pub const ONE_TWO_THREE: isize = 456;
pub const TUPLE: (usize, &str, usize) = (1, "abc", 3);
}
"#);
axconfig_gen_macros::parse_configs!(r#"
are-you-ok = true
one-two-three = 123
[hello]
"one-two-three" = "456" # int
array = [1, 2, 3] # [uint]
tuple = [1, "abc", 3]
"#);
assert_eq!(ARE_YOU_OK, true);
assert_eq!(ONE_TWO_THREE, 123usize);
assert_eq!(hello::ONE_TWO_THREE, 456isize);
assert_eq!(hello::ARRAY, [1, 2, 3]);
assert_eq!(hello::TUPLE, (1, "abc", 3));
The above example will generate the following constants:
pub const ARE_YOU_OK: bool = true;
pub const ONE_TWO_THREE: usize = 123;
pub mod hello {
pub const ARRAY: &[usize] = &[1, 2, 3];
pub const ONE_TWO_THREE: isize = 456;
pub const TUPLE: (usize, &str, usize) = (1, "abc", 3);
}
You can also include the configuration file directly:
axconfig_gen_macros::include_configs!("/path/to/config.toml");