Skip to main content

flowey_lib_hvlite/
build_tmks.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Build TMK binaries
5
6use crate::common::CommonArch;
7use crate::common::CommonProfile;
8use flowey::node::prelude::*;
9use flowey_lib_common::_util::group_by;
10
11#[derive(Serialize, Deserialize)]
12pub struct TmksOutput {
13    #[serde(rename = "simple_tmk")]
14    pub bin: PathBuf,
15    #[serde(rename = "simple_tmk.dbg")]
16    pub dbg: Option<PathBuf>,
17}
18
19impl Artifact for TmksOutput {}
20
21flowey_request! {
22    pub struct Request {
23        pub arch: CommonArch,
24        pub profile: CommonProfile,
25        pub tmks: WriteVar<TmksOutput>,
26    }
27}
28
29new_flow_node!(struct Node);
30
31impl FlowNode for Node {
32    type Request = Request;
33
34    fn imports(ctx: &mut ImportCtx<'_>) {
35        ctx.import::<crate::run_cargo_build::Node>();
36    }
37
38    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
39        let requests = group_by(requests.into_iter().map(|r| ((r.arch, r.profile), r.tmks)));
40
41        for ((arch, profile), tmks) in requests {
42            let target = arch.minimal_rt_triple();
43
44            let output = ctx.reqv(|v| crate::run_cargo_build::Request {
45                crate_name: "simple_tmk".into(),
46                out_name: "simple_tmk".into(),
47                crate_type: flowey_lib_common::run_cargo_build::CargoCrateType::Bin,
48                profile: profile.into(),
49                features: Default::default(),
50                target,
51                no_split_dbg_info: false,
52                extra_env: Some(ReadVar::from_static(
53                    [("RUSTC_BOOTSTRAP".to_string(), "1".to_string())]
54                        .into_iter()
55                        .collect(),
56                )),
57                pre_build_deps: Vec::new(),
58                output: v,
59            });
60
61            ctx.emit_minor_rust_step("report built tmks", |ctx| {
62                let tmks = tmks.claim(ctx);
63                let output = output.claim(ctx);
64                move |rt| {
65                    let output = match rt.read(output) {
66                        crate::run_cargo_build::CargoBuildOutput::ElfBin { bin, dbg } => {
67                            TmksOutput { bin, dbg }
68                        }
69                        _ => unreachable!(),
70                    };
71
72                    rt.write_all(tmks, &output);
73                }
74            });
75        }
76
77        Ok(())
78    }
79}