Skip to main content

flowey_lib_hvlite/
build_ohcldiag_dev.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Build `ohcldiag_dev` 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 OhcldiagDevOutput {
14    LinuxBin {
15        #[serde(rename = "ohcldiag-dev")]
16        bin: PathBuf,
17        #[serde(rename = "ohcldiag-dev.dbg")]
18        dbg: PathBuf,
19    },
20    WindowsBin {
21        #[serde(rename = "ohcldiag-dev.exe")]
22        exe: PathBuf,
23        #[serde(rename = "ohcldiag-dev.pdb")]
24        #[serde(default, skip_serializing_if = "Option::is_none")]
25        pdb: Option<PathBuf>,
26    },
27}
28
29impl Artifact for OhcldiagDevOutput {}
30
31flowey_request! {
32    pub struct Request {
33        pub target: CommonTriple,
34        pub profile: CommonProfile,
35        pub ohcldiag_dev: WriteVar<OhcldiagDevOutput>,
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.ohcldiag_dev)),
53        );
54        for ((target, profile), ohcldiag_dev) in requests {
55            let output = ctx.reqv(|v| crate::run_cargo_build::Request {
56                crate_name: "ohcldiag-dev".into(),
57                out_name: "ohcldiag-dev".into(),
58                crate_type: flowey_lib_common::run_cargo_build::CargoCrateType::Bin,
59                profile: profile.into(),
60                features: Default::default(),
61                target: target.as_triple(),
62                no_split_dbg_info: false,
63                extra_env: None,
64                pre_build_deps: Vec::new(),
65                output: v,
66            });
67
68            ctx.emit_minor_rust_step("report built ohcldiag_dev", |ctx| {
69                let ohcldiag_dev = ohcldiag_dev.claim(ctx);
70                let output = output.claim(ctx);
71                move |rt| {
72                    let output = match rt.read(output) {
73                        crate::run_cargo_build::CargoBuildOutput::WindowsBin { exe, pdb } => {
74                            OhcldiagDevOutput::WindowsBin { exe, pdb }
75                        }
76                        crate::run_cargo_build::CargoBuildOutput::ElfBin { bin, dbg } => {
77                            OhcldiagDevOutput::LinuxBin {
78                                bin,
79                                dbg: dbg.unwrap(),
80                            }
81                        }
82                        _ => unreachable!(),
83                    };
84
85                    rt.write_all(ohcldiag_dev, &output);
86                }
87            });
88        }
89
90        Ok(())
91    }
92}