Skip to main content

flowey_lib_hvlite/
build_hypestv.rs

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