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, we need the `build-essential` package to ensure that
40        // the system has a working linker.
41        if matches!(
42            ctx.platform(),
43            FlowPlatform::Linux(FlowPlatformLinuxDistro::Ubuntu)
44        ) {
45            side_effects.push(ctx.reqv(|v| {
46                flowey_lib_common::install_dist_pkg::Request::Install {
47                    package_names: vec!["build-essential".into()],
48                    done: v,
49                }
50            }));
51        }
52
53        ctx.emit_side_effect_step(side_effects, requests.into_iter().map(|x| x.0));
54
55        Ok(())
56    }
57}