Skip to main content

flowey_lib_hvlite/
install_openvmm_rust_build_essential.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Globally install a set of dependencies required to build Rust code in the
5//! OpenVMM repo.
6//!
7//! Notably - this node installs both the required Rust toolchain, as well as a
8//! protobuf compiler (which is transitively required by most OpenVMM crates).
9
10use flowey::node::prelude::*;
11
12flowey_request! {
13    pub struct Request(pub WriteVar<SideEffect>);
14}
15
16new_flow_node!(struct Node);
17
18impl FlowNode for Node {
19    type Request = Request;
20
21    fn imports(ctx: &mut ImportCtx<'_>) {
22        ctx.import::<crate::init_openvmm_magicpath_protoc::Node>();
23        ctx.import::<crate::init_openvmm_cargo_config_deny_warnings::Node>();
24        ctx.import::<flowey_lib_common::install_rust::Node>();
25        ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
26    }
27
28    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
29        if requests.is_empty() {
30            return Ok(());
31        }
32
33        let mut side_effects = vec![
34            ctx.reqv(crate::init_openvmm_cargo_config_deny_warnings::Request::Done),
35            ctx.reqv(crate::init_openvmm_magicpath_protoc::Request),
36            ctx.reqv(flowey_lib_common::install_rust::Request::EnsureInstalled),
37        ];
38
39        // On Ubuntu, install the native build tools required by Rust crates.
40        if matches!(
41            ctx.platform(),
42            FlowPlatform::Linux(FlowPlatformLinuxDistro::Ubuntu)
43        ) {
44            side_effects.push(ctx.reqv(|v| {
45                flowey_lib_common::install_dist_pkg::Request::Install {
46                    package_names: vec!["build-essential".into(), "cmake".into()],
47                    done: v,
48                }
49            }));
50        }
51
52        ctx.emit_side_effect_step(side_effects, requests.into_iter().map(|x| x.0));
53
54        Ok(())
55    }
56}