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