Skip to main content

flowey_lib_hvlite/
build_openvmm_vhost.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Build the `openvmm_vhost` binary (vhost-user backend).
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, PartialEq, Eq, PartialOrd, Ord)]
12pub struct OpenvmmVhostBuildParams {
13    pub profile: CommonProfile,
14    pub target: CommonTriple,
15}
16
17#[derive(Serialize, Deserialize)]
18pub struct OpenvmmVhostOutput {
19    pub bin: PathBuf,
20    pub dbg: Option<PathBuf>,
21}
22
23impl Artifact for OpenvmmVhostOutput {}
24
25flowey_request! {
26    pub struct Request {
27        pub params: OpenvmmVhostBuildParams,
28        pub openvmm_vhost: WriteVar<OpenvmmVhostOutput>,
29    }
30}
31
32new_flow_node!(struct Node);
33
34impl FlowNode for Node {
35    type Request = Request;
36
37    fn imports(ctx: &mut ImportCtx<'_>) {
38        ctx.import::<crate::run_cargo_build::Node>();
39    }
40
41    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
42        let requests = group_by(requests.into_iter().map(|r| (r.params, r.openvmm_vhost)));
43        for (OpenvmmVhostBuildParams { profile, target }, openvmm_vhost_bin) in requests {
44            let output = ctx.reqv(|v| crate::run_cargo_build::Request {
45                crate_name: "openvmm_vhost".into(),
46                out_name: "openvmm_vhost".into(),
47                crate_type: flowey_lib_common::run_cargo_build::CargoCrateType::Bin,
48                profile: profile.into(),
49                features: flowey_lib_common::run_cargo_build::CargoFeatureSet::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 openvmm_vhost", |ctx| {
58                let openvmm_vhost_bin = openvmm_vhost_bin.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                            OpenvmmVhostOutput { bin, dbg }
64                        }
65                        _ => unreachable!("openvmm_vhost is Linux-only"),
66                    };
67
68                    rt.write_all(openvmm_vhost_bin, &output);
69                }
70            });
71        }
72
73        Ok(())
74    }
75}