sim_run_core/boot.rs
1use std::{ffi::OsString, path::PathBuf};
2
3use crate::{
4 ConfigLoadOptions, ConfigReportRequest, LibSourceSpec, boot_codec_name, codec_lib_symbol,
5};
6
7/// Parsed bootloader controls and payload data.
8#[derive(Clone, Debug, Default, PartialEq, Eq)]
9pub struct CliBoot {
10 /// Codec name selected with `--codec`, or `None` for the default.
11 pub codec: Option<String>,
12 /// Library sources to load, in `--load` order.
13 pub loads: Vec<LibSourceSpec>,
14 /// Optional native audio provider source requested by the operator.
15 pub native_audio_provider: Option<Box<LibSourceSpec>>,
16 /// Runtime configuration source options.
17 pub config: ConfigLoadOptions,
18 /// Whether `--list` requested a loaded-lib listing.
19 pub list: bool,
20 /// Symbol passed to `--inspect`, if any.
21 pub inspect: Option<String>,
22 /// Loaded-state or effective-config report requested by `sim config ...`.
23 pub config_report: Option<ConfigReportRequest>,
24 /// Payload data preserved for the loaded-lib handoff.
25 pub payload: Payload,
26}
27
28impl CliBoot {
29 /// Builds the data envelope handed to loaded libraries.
30 pub fn envelope(&self) -> CliEnvelope {
31 let codec_name = boot_codec_name(self);
32 CliEnvelope {
33 codec: codec_lib_symbol(codec_name),
34 verb: self
35 .payload
36 .args
37 .first()
38 .and_then(|arg| arg.as_os_str().to_str().map(str::to_owned)),
39 args: self.payload.args.clone(),
40 eval: self.payload.eval.clone(),
41 script: self.payload.script.clone(),
42 stdin: self.payload.stdin.clone(),
43 }
44 }
45}
46
47/// Payload preserved for loaded-lib behavior.
48#[derive(Clone, Debug, Default, PartialEq, Eq)]
49pub struct Payload {
50 /// Trailing positional arguments handed to the loaded entrypoint.
51 pub args: Vec<OsString>,
52 /// Eval text carried from `--eval`.
53 pub eval: Option<String>,
54 /// Script path carried from `--script`.
55 pub script: Option<PathBuf>,
56 /// Stdin text carried from `--stdin`.
57 pub stdin: Option<String>,
58}
59
60/// Data envelope supplied to the selected loaded-lib entrypoint.
61#[derive(Clone, Debug, PartialEq, Eq)]
62pub struct CliEnvelope {
63 /// Codec library symbol selected for the boot session.
64 pub codec: String,
65 /// First payload argument, exposed as the loaded-lib verb.
66 pub verb: Option<String>,
67 /// Full payload argument list.
68 pub args: Vec<OsString>,
69 /// Eval text carried from `--eval`.
70 pub eval: Option<String>,
71 /// Script path carried from `--script`.
72 pub script: Option<PathBuf>,
73 /// Stdin text carried from `--stdin`.
74 pub stdin: Option<String>,
75}