arcbox_hypervisor/
config.rs1use crate::types::CpuArch;
4
5#[derive(Debug, Clone)]
7pub struct VmConfig {
8 pub vcpu_count: u32,
10 pub memory_size: u64,
12 pub arch: CpuArch,
14 pub kernel_path: Option<String>,
16 pub kernel_cmdline: Option<String>,
18 pub initrd_path: Option<String>,
20 pub enable_rosetta: bool,
22}
23
24impl Default for VmConfig {
25 fn default() -> Self {
26 Self {
27 vcpu_count: 1,
28 memory_size: 512 * 1024 * 1024, arch: CpuArch::native(),
30 kernel_path: None,
31 kernel_cmdline: None,
32 initrd_path: None,
33 enable_rosetta: false,
34 }
35 }
36}
37
38impl VmConfig {
39 #[must_use]
41 pub fn builder() -> VmConfigBuilder {
42 VmConfigBuilder::default()
43 }
44}
45
46#[derive(Debug, Default)]
48pub struct VmConfigBuilder {
49 config: VmConfig,
50}
51
52impl VmConfigBuilder {
53 #[must_use]
55 pub const fn vcpu_count(mut self, count: u32) -> Self {
56 self.config.vcpu_count = count;
57 self
58 }
59
60 #[must_use]
62 pub const fn memory_size(mut self, size: u64) -> Self {
63 self.config.memory_size = size;
64 self
65 }
66
67 #[must_use]
69 pub const fn arch(mut self, arch: CpuArch) -> Self {
70 self.config.arch = arch;
71 self
72 }
73
74 #[must_use]
76 pub fn kernel_path(mut self, path: impl Into<String>) -> Self {
77 self.config.kernel_path = Some(path.into());
78 self
79 }
80
81 #[must_use]
83 pub fn kernel_cmdline(mut self, cmdline: impl Into<String>) -> Self {
84 self.config.kernel_cmdline = Some(cmdline.into());
85 self
86 }
87
88 #[must_use]
90 pub fn initrd_path(mut self, path: impl Into<String>) -> Self {
91 self.config.initrd_path = Some(path.into());
92 self
93 }
94
95 #[must_use]
97 pub const fn enable_rosetta(mut self, enable: bool) -> Self {
98 self.config.enable_rosetta = enable;
99 self
100 }
101
102 #[must_use]
104 pub fn build(self) -> VmConfig {
105 self.config
106 }
107}