flowey_lib_hvlite/
build_incubator.rs1use crate::common::CommonProfile;
7use crate::common::CommonTriple;
8use flowey::node::prelude::*;
9
10#[derive(Serialize, Deserialize)]
11pub struct IncubatorOutput {
12 #[serde(rename = "incubator")]
13 pub bin: PathBuf,
14 #[serde(rename = "incubator.dbg")]
15 pub dbg: Option<PathBuf>,
16}
17
18impl Artifact for IncubatorOutput {}
19
20flowey_request! {
21 pub struct Request {
22 pub target: CommonTriple,
23 pub profile: CommonProfile,
24 pub incubator: WriteVar<IncubatorOutput>,
25 }
26}
27
28new_simple_flow_node!(struct Node);
29
30impl SimpleFlowNode for Node {
31 type Request = Request;
32
33 fn imports(ctx: &mut ImportCtx<'_>) {
34 ctx.import::<crate::run_cargo_build::Node>();
35 }
36
37 fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
38 let Request {
39 target,
40 profile,
41 incubator,
42 } = request;
43
44 let output = ctx.reqv(|v| crate::run_cargo_build::Request {
45 crate_name: "incubator".into(),
46 out_name: "incubator".into(),
47 crate_type: flowey_lib_common::run_cargo_build::CargoCrateType::Bin,
48 profile: profile.into(),
49 features: Default::default(),
50 target: target.as_triple(),
51 no_split_dbg_info: false,
52 extra_env: None,
53 pre_build_deps: Vec::new(),
54 output: v,
55 });
56
57 ctx.emit_minor_rust_step("report built incubator", |ctx| {
58 let incubator = incubator.claim(ctx);
59 let output = output.claim(ctx);
60 move |rt| {
61 let output = match rt.read(output) {
62 crate::run_cargo_build::CargoBuildOutput::ElfBin { bin, dbg } => {
63 IncubatorOutput { bin, dbg }
64 }
65 _ => unreachable!(),
66 };
67
68 rt.write(incubator, &output);
69 }
70 });
71
72 Ok(())
73 }
74}
75
76#[derive(Serialize, Deserialize)]
77pub enum IncubatorProfileNameOrPath {
78 Name(String),
79 Path(PathBuf),
80}
81
82impl IncubatorProfileNameOrPath {
83 pub fn resolve(self, repo_root: &Path) -> PathBuf {
84 match self {
85 IncubatorProfileNameOrPath::Name(name) => incubator_profile_path(repo_root, &name),
86 IncubatorProfileNameOrPath::Path(path) => path,
87 }
88 }
89}
90
91impl std::fmt::Display for IncubatorProfileNameOrPath {
92 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
93 match self {
94 IncubatorProfileNameOrPath::Name(name) => f.write_str(name),
95 IncubatorProfileNameOrPath::Path(path) => f.write_str(path.to_string_lossy().as_ref()),
96 }
97 }
98}
99
100pub fn incubator_profile_dir() -> PathBuf {
101 PathBuf::new()
102 .join("petri")
103 .join("incubator")
104 .join("profiles")
105}
106
107pub fn incubator_profile_path(repo_root: &Path, name: &str) -> PathBuf {
109 repo_root
110 .join(incubator_profile_dir())
111 .join(format!("{name}.toml"))
112}
113
114pub fn default_incubator_profile(target: &CommonTriple) -> Option<&'static str> {
116 match *target {
117 CommonTriple::AARCH64_LINUX_MUSL => Some("aarch64-tcg-pcie"),
118 _ => None,
119 }
120}