Skip to main content

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::common::CommonTriple;
7use crate::run_cargo_build::BuildProfile;
8use flowey::node::prelude::*;
9use flowey_lib_common::_util::group_by;
10use flowey_lib_common::run_cargo_build::CargoCrateType;
11
12#[derive(Serialize, Deserialize)]
13pub enum XtaskOutput {
14    LinuxBin { bin: PathBuf, dbg: PathBuf },
15    WindowsBin { exe: PathBuf, pdb: Option<PathBuf> },
16}
17
18flowey_request! {
19    pub struct Request {
20        pub target: CommonTriple,
21        pub xtask: WriteVar<XtaskOutput>,
22    }
23}
24
25new_flow_node!(struct Node);
26
27impl FlowNode for Node {
28    type Request = Request;
29
30    fn imports(ctx: &mut ImportCtx<'_>) {
31        ctx.import::<crate::run_cargo_build::Node>();
32    }
33
34    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
35        let requests = group_by(requests.into_iter().map(|r| (r.target, r.xtask)));
36        for (target, xtask) in requests {
37            let output = ctx.reqv(|v| crate::run_cargo_build::Request {
38                crate_name: "xtask".into(),
39                out_name: "xtask".into(),
40                crate_type: CargoCrateType::Bin,
41                profile: BuildProfile::Light,
42                features: Default::default(),
43                target: target.as_triple(),
44                no_split_dbg_info: false,
45                extra_env: None,
46                pre_build_deps: Vec::new(),
47                output: v,
48            });
49
50            ctx.emit_minor_rust_step("report built xtask", |ctx| {
51                let xtask = xtask.claim(ctx);
52                let output = output.claim(ctx);
53                move |rt| {
54                    let output = match rt.read(output) {
55                        crate::run_cargo_build::CargoBuildOutput::WindowsBin { exe, pdb } => {
56                            XtaskOutput::WindowsBin { exe, pdb }
57                        }
58                        crate::run_cargo_build::CargoBuildOutput::ElfBin { bin, dbg } => {
59                            XtaskOutput::LinuxBin {
60                                bin,
61                                dbg: dbg.unwrap(),
62                            }
63                        }
64                        _ => unreachable!(),
65                    };
66
67                    rt.write_all(xtask, &output);
68                }
69            });
70        }
71
72        Ok(())
73    }
74}