flowey_lib_hvlite/
build_vmgstool.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Build `vmgstool` binaries
5
6use crate::run_cargo_build::common::CommonProfile;
7use crate::run_cargo_build::common::CommonTriple;
8use flowey::node::prelude::*;
9use flowey_lib_common::run_cargo_build::CargoCrateType;
10
11#[derive(Serialize, Deserialize)]
12#[serde(untagged)]
13pub enum VmgstoolOutput {
14    LinuxBin {
15        #[serde(rename = "vmgstool")]
16        bin: PathBuf,
17        #[serde(rename = "vmgstool.dbg")]
18        dbg: PathBuf,
19    },
20    WindowsBin {
21        #[serde(rename = "vmgstool.exe")]
22        exe: PathBuf,
23        #[serde(rename = "vmgstool.pdb")]
24        pdb: PathBuf,
25    },
26}
27
28impl Artifact for VmgstoolOutput {}
29
30flowey_request! {
31    pub struct Request {
32        pub target: CommonTriple,
33        pub profile: CommonProfile,
34        pub with_crypto: bool,
35        pub vmgstool: WriteVar<VmgstoolOutput>,
36    }
37}
38
39new_simple_flow_node!(struct Node);
40
41impl SimpleFlowNode for Node {
42    type Request = Request;
43
44    fn imports(ctx: &mut ImportCtx<'_>) {
45        ctx.import::<crate::run_cargo_build::Node>();
46        ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
47    }
48
49    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
50        let Request {
51            target,
52            profile,
53            with_crypto,
54            vmgstool,
55        } = request;
56
57        let mut pre_build_deps = Vec::new();
58
59        if with_crypto {
60            pre_build_deps.push(ctx.reqv(|v| {
61                flowey_lib_common::install_dist_pkg::Request::Install {
62                    package_names: vec!["libssl-dev".into()],
63                    done: v,
64                }
65            }));
66        }
67
68        let output = ctx.reqv(|v| crate::run_cargo_build::Request {
69            crate_name: "vmgstool".into(),
70            out_name: "vmgstool".into(),
71            crate_type: CargoCrateType::Bin,
72            profile: profile.into(),
73            features: if with_crypto {
74                match target.as_triple().operating_system {
75                    target_lexicon::OperatingSystem::Windows => ["encryption_win".into()].into(),
76                    target_lexicon::OperatingSystem::Linux => ["encryption_ossl".into()].into(),
77                    _ => unreachable!(),
78                }
79            } else {
80                [].into()
81            },
82            target: target.as_triple(),
83            no_split_dbg_info: false,
84            extra_env: None,
85            pre_build_deps,
86            output: v,
87        });
88
89        ctx.emit_minor_rust_step("report built vmgstool", |ctx| {
90            let vmgstool = vmgstool.claim(ctx);
91            let output = output.claim(ctx);
92            move |rt| {
93                let output = match rt.read(output) {
94                    crate::run_cargo_build::CargoBuildOutput::WindowsBin { exe, pdb } => {
95                        VmgstoolOutput::WindowsBin { exe, pdb }
96                    }
97                    crate::run_cargo_build::CargoBuildOutput::ElfBin { bin, dbg } => {
98                        VmgstoolOutput::LinuxBin {
99                            bin,
100                            dbg: dbg.unwrap(),
101                        }
102                    }
103                    _ => unreachable!(),
104                };
105
106                rt.write(vmgstool, &output);
107            }
108        });
109
110        Ok(())
111    }
112}