openvm_build/
config.rs
1use std::path::{Path, PathBuf};
4
5use cargo_metadata::Package;
6use serde::{Deserialize, Serialize};
7
8#[derive(Default, Clone)]
10pub struct GuestOptions {
11 pub features: Vec<String>,
13 pub rustc_flags: Vec<String>,
15 pub profile: Option<String>,
17 pub target_dir: Option<PathBuf>,
19 pub(crate) options: Vec<String>,
21}
22
23impl GuestOptions {
24 pub fn with_options<S: AsRef<str>>(mut self, options: impl IntoIterator<Item = S>) -> Self {
26 self.options
27 .extend(options.into_iter().map(|s| s.as_ref().to_string()));
28 self
29 }
30
31 pub fn with_features<S: AsRef<str>>(mut self, features: impl IntoIterator<Item = S>) -> Self {
33 self.features
34 .extend(features.into_iter().map(|s| s.as_ref().to_string()));
35 self
36 }
37
38 pub fn with_rustc_flags<S: AsRef<str>>(mut self, flags: impl IntoIterator<Item = S>) -> Self {
40 self.rustc_flags
41 .extend(flags.into_iter().map(|s| s.as_ref().to_string()));
42 self
43 }
44
45 pub fn with_profile(mut self, profile: String) -> Self {
47 self.profile = Some(profile);
48 self
49 }
50
51 pub fn with_target_dir<P: AsRef<Path>>(mut self, target_dir: P) -> Self {
53 self.target_dir = Some(target_dir.as_ref().to_path_buf());
54 self
55 }
56
57 #[allow(dead_code)]
58 pub(crate) fn with_metadata(mut self, metadata: GuestMetadata) -> Self {
59 self.rustc_flags = metadata.rustc_flags.unwrap_or_default();
60 self
61 }
62}
63
64#[derive(Serialize, Deserialize, Clone, Default)]
66pub(crate) struct GuestMetadata {
67 #[serde(rename = "rustc-flags")]
69 pub(crate) rustc_flags: Option<Vec<String>>,
70}
71
72impl From<&Package> for GuestMetadata {
73 fn from(value: &Package) -> Self {
74 let Some(obj) = value.metadata.get("openvm") else {
75 return Default::default();
76 };
77 serde_json::from_value(obj.clone()).unwrap()
78 }
79}