flowey_lib_hvlite/
build_vmgstool.rs1use crate::common::CommonProfile;
7use crate::common::CommonTriple;
8use flowey::node::prelude::*;
9use flowey_lib_common::_util::group_by;
10use flowey_lib_common::run_cargo_build::CargoCrateType;
11use flowey_lib_common::run_cargo_build::CargoFeatureSet;
12
13#[derive(Serialize, Deserialize)]
14#[serde(untagged)]
15pub enum VmgstoolOutput {
16 LinuxBin {
17 #[serde(rename = "vmgstool")]
18 bin: PathBuf,
19 #[serde(rename = "vmgstool.dbg")]
20 dbg: Option<PathBuf>,
21 },
22 WindowsBin {
23 #[serde(rename = "vmgstool.exe")]
24 exe: PathBuf,
25 #[serde(rename = "vmgstool.pdb")]
26 #[serde(default, skip_serializing_if = "Option::is_none")]
27 pdb: Option<PathBuf>,
28 },
29}
30
31impl Artifact for VmgstoolOutput {}
32
33flowey_request! {
34 pub struct Request {
35 pub target: CommonTriple,
36 pub profile: CommonProfile,
37 pub with_crypto: bool,
38 pub with_test_helpers: bool,
39 pub vmgstool: WriteVar<VmgstoolOutput>,
40 }
41}
42
43new_flow_node!(struct Node);
44
45impl FlowNode for Node {
46 type Request = Request;
47
48 fn imports(ctx: &mut ImportCtx<'_>) {
49 ctx.import::<crate::run_cargo_build::Node>();
50 ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
51 }
52
53 fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
54 let requests = group_by(requests.into_iter().map(|r| {
55 (
56 (r.target, r.profile, r.with_crypto, r.with_test_helpers),
57 r.vmgstool,
58 )
59 }));
60 for ((target, profile, with_crypto, with_test_helpers), vmgstool) in requests {
61 let mut pre_build_deps = Vec::new();
62
63 if with_crypto {
64 let ssl_pkgs = crate::common::openssl_dev_packages(ctx.platform())?;
65 if !ssl_pkgs.is_empty() {
66 pre_build_deps.push(ctx.reqv(|v| {
67 flowey_lib_common::install_dist_pkg::Request::Install {
68 package_names: ssl_pkgs,
69 done: v,
70 }
71 }));
72 }
73 }
74
75 let mut features = Vec::new();
76 if with_crypto {
77 features.push("encryption".into());
78 }
79 if with_test_helpers {
80 features.push("test_helpers".into());
81 }
82
83 let output = ctx.reqv(|v| crate::run_cargo_build::Request {
84 crate_name: "vmgstool".into(),
85 out_name: "vmgstool".into(),
86 crate_type: CargoCrateType::Bin,
87 profile: profile.into(),
88 features: CargoFeatureSet::Specific(features),
89 target: target.as_triple(),
90 no_split_dbg_info: false,
91 extra_env: None,
92 pre_build_deps,
93 output: v,
94 });
95
96 ctx.emit_minor_rust_step("report built vmgstool", |ctx| {
97 let vmgstool = vmgstool.claim(ctx);
98 let output = output.claim(ctx);
99 move |rt| {
100 let output = match rt.read(output) {
101 crate::run_cargo_build::CargoBuildOutput::WindowsBin { exe, pdb } => {
102 VmgstoolOutput::WindowsBin { exe, pdb }
103 }
104 crate::run_cargo_build::CargoBuildOutput::ElfBin { bin, dbg } => {
105 VmgstoolOutput::LinuxBin { bin, dbg }
106 }
107 _ => unreachable!(),
108 };
109
110 rt.write_all(vmgstool, &output);
111 }
112 });
113 }
114
115 Ok(())
116 }
117}