flowey_lib_hvlite/
build_openhcl_boot.rs1use crate::run_cargo_build::BuildProfile;
7use crate::run_cargo_build::common::CommonArch;
8use flowey::node::prelude::*;
9use std::collections::BTreeMap;
10
11#[derive(Serialize, Deserialize)]
12pub struct OpenhclBootOutput {
13 pub bin: PathBuf,
14 pub dbg: PathBuf,
15}
16
17#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
18pub enum OpenhclBootBuildProfile {
19 Debug,
20 Release,
21}
22
23#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
24pub struct OpenhclBootBuildParams {
25 pub arch: CommonArch,
26 pub profile: OpenhclBootBuildProfile,
27}
28
29flowey_request! {
30 pub struct Request {
31 pub build_params: OpenhclBootBuildParams,
32 pub openhcl_boot: WriteVar<OpenhclBootOutput>,
33 }
34}
35
36new_flow_node!(struct Node);
37
38impl FlowNode for Node {
39 type Request = Request;
40
41 fn imports(ctx: &mut ImportCtx<'_>) {
42 ctx.import::<crate::run_cargo_build::Node>();
43 }
44
45 fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
46 let requests = requests
48 .into_iter()
49 .fold(BTreeMap::<_, Vec<_>>::new(), |mut m, r| {
50 let Request {
51 build_params,
52 openhcl_boot,
53 } = r;
54 m.entry(build_params).or_default().push(openhcl_boot);
55 m
56 });
57
58 for (OpenhclBootBuildParams { arch, profile }, openhcl_boot) in requests {
59 let target = target_lexicon::Triple {
60 architecture: arch.as_arch(),
61 operating_system: target_lexicon::OperatingSystem::None_,
62 environment: target_lexicon::Environment::Unknown,
63 vendor: target_lexicon::Vendor::Custom(target_lexicon::CustomVendor::Static(
64 "minimal_rt",
65 )),
66 binary_format: target_lexicon::BinaryFormat::Unknown,
67 };
68
69 let profile = match profile {
71 OpenhclBootBuildProfile::Debug => BuildProfile::BootDev,
72 OpenhclBootBuildProfile::Release => BuildProfile::BootRelease,
73 };
74
75 let output = ctx.reqv(|v| crate::run_cargo_build::Request {
76 crate_name: "openhcl_boot".into(),
77 out_name: "openhcl_boot".into(),
78 crate_type: flowey_lib_common::run_cargo_build::CargoCrateType::Bin,
79 profile,
80 features: Default::default(),
81 target,
82 no_split_dbg_info: false,
83 extra_env: Some(ReadVar::from_static(
84 [("RUSTC_BOOTSTRAP".to_string(), "1".to_string())]
85 .into_iter()
86 .collect(),
87 )),
88 pre_build_deps: Vec::new(),
89 output: v,
90 });
91
92 ctx.emit_minor_rust_step("report built openhcl_boot", |ctx| {
93 let openhcl_boot = openhcl_boot.claim(ctx);
94 let output = output.claim(ctx);
95 move |rt| {
96 let output = match rt.read(output) {
97 crate::run_cargo_build::CargoBuildOutput::ElfBin { bin, dbg } => {
98 OpenhclBootOutput {
99 bin,
100 dbg: dbg.unwrap(),
101 }
102 }
103 _ => unreachable!(),
104 };
105
106 for var in openhcl_boot {
107 rt.write(var, &output);
108 }
109 }
110 });
111 }
112
113 Ok(())
114 }
115}