flowey_lib_hvlite/
build_xtask.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Build `xtask` binary
5
6use crate::run_cargo_build::BuildProfile;
7use crate::run_cargo_build::common::CommonTriple;
8use flowey::node::prelude::*;
9use flowey_lib_common::run_cargo_build::CargoCrateType;
10
11#[derive(Serialize, Deserialize)]
12pub enum XtaskOutput {
13    LinuxBin { bin: PathBuf, dbg: PathBuf },
14    WindowsBin { exe: PathBuf, pdb: PathBuf },
15}
16
17flowey_request! {
18    pub struct Request {
19        pub target: CommonTriple,
20        pub xtask: WriteVar<XtaskOutput>,
21    }
22}
23
24new_simple_flow_node!(struct Node);
25
26impl SimpleFlowNode for Node {
27    type Request = Request;
28
29    fn imports(ctx: &mut ImportCtx<'_>) {
30        ctx.import::<crate::run_cargo_build::Node>();
31    }
32
33    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
34        let Request { target, xtask } = request;
35
36        let output = ctx.reqv(|v| crate::run_cargo_build::Request {
37            crate_name: "xtask".into(),
38            out_name: "xtask".into(),
39            crate_type: CargoCrateType::Bin,
40            profile: BuildProfile::Light,
41            features: [].into(),
42            target: target.as_triple(),
43            no_split_dbg_info: false,
44            extra_env: None,
45            pre_build_deps: Vec::new(),
46            output: v,
47        });
48
49        ctx.emit_minor_rust_step("report built xtask", |ctx| {
50            let xtask = xtask.claim(ctx);
51            let output = output.claim(ctx);
52            move |rt| {
53                let output = match rt.read(output) {
54                    crate::run_cargo_build::CargoBuildOutput::WindowsBin { exe, pdb } => {
55                        XtaskOutput::WindowsBin { exe, pdb }
56                    }
57                    crate::run_cargo_build::CargoBuildOutput::ElfBin { bin, dbg } => {
58                        XtaskOutput::LinuxBin {
59                            bin,
60                            dbg: dbg.unwrap(),
61                        }
62                    }
63                    _ => unreachable!(),
64                };
65
66                rt.write(xtask, &output);
67            }
68        });
69
70        Ok(())
71    }
72}