Skip to main content

flowey_lib_hvlite/
build_tmk_vmm.rs

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