Skip to main content

flowey_lib_hvlite/_jobs/
check_cargo_hack.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Check every OpenVMM workspace feature with `cargo-hack`.
5
6use crate::common::CommonProfile;
7use flowey::node::prelude::*;
8
9flowey_request! {
10    pub struct Request {
11        pub profile: CommonProfile,
12        pub done: WriteVar<SideEffect>,
13    }
14}
15
16new_simple_flow_node!(struct Node);
17
18impl SimpleFlowNode for Node {
19    type Request = Request;
20
21    fn imports(ctx: &mut ImportCtx<'_>) {
22        ctx.import::<crate::git_checkout_openvmm_repo::Node>();
23        ctx.import::<crate::install_openvmm_rust_build_essential::Node>();
24        ctx.import::<flowey_lib_common::install_cargo_hack::Node>();
25        ctx.import::<flowey_lib_common::install_dist_pkg::Node>();
26        ctx.import::<flowey_lib_common::install_rust::Node>();
27    }
28
29    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
30        let Request { profile, done } = request;
31
32        let mut pre_build_deps = vec![
33            ctx.reqv(crate::install_openvmm_rust_build_essential::Request),
34            ctx.reqv(flowey_lib_common::install_cargo_hack::Request),
35        ];
36
37        if matches!(
38            ctx.platform(),
39            FlowPlatform::Linux(FlowPlatformLinuxDistro::Ubuntu)
40        ) {
41            pre_build_deps.push(ctx.reqv(|done| {
42                flowey_lib_common::install_dist_pkg::Request::Install {
43                    package_names: vec!["libssl-dev".into(), "pkg-config".into()],
44                    done,
45                }
46            }));
47        }
48
49        let openvmm_repo_path = ctx.reqv(crate::git_checkout_openvmm_repo::req::GetRepoDir);
50        let rust_toolchain = ctx.reqv(flowey_lib_common::install_rust::Request::GetRustupToolchain);
51
52        ctx.emit_rust_step("run cargo hack", |ctx| {
53            done.claim(ctx);
54            pre_build_deps.claim(ctx);
55            let openvmm_repo_path = openvmm_repo_path.claim(ctx);
56            let rust_toolchain = rust_toolchain.claim(ctx);
57            move |rt| {
58                let openvmm_repo_path = rt.read(openvmm_repo_path);
59                rt.sh.change_dir(openvmm_repo_path);
60
61                let rust_toolchain = rt
62                    .read(rust_toolchain)
63                    .as_ref()
64                    .map(|toolchain| format!("+{toolchain}"));
65                let profile = match profile {
66                    CommonProfile::Release => "release",
67                    CommonProfile::Debug => "dev",
68                };
69                let workspace_rust_toolchain = rust_toolchain.clone();
70                // The crypto and TPM implementation crates have mutually exclusive
71                // backend features and are covered by targeted jobs elsewhere.
72                flowey::shell_cmd!(
73                    rt,
74                    "cargo {workspace_rust_toolchain...}
75                        hack
76                        --workspace
77                        --each-feature
78                        --locked
79                        --keep-going
80                        --exclude crypto
81                        --exclude tpm_device
82                        --exclude tpm_lib
83                        --exclude openvmm_hcl_resources
84                        --exclude openvmm_resources
85                        check
86                        --profile {profile}
87                    "
88                )
89                .run()?;
90
91                // Check the resource crates separately so that only their TPM
92                // features are excluded.
93                flowey::shell_cmd!(
94                    rt,
95                    "cargo {rust_toolchain...}
96                        hack
97                        --package openvmm_hcl_resources
98                        --package openvmm_resources
99                        --each-feature
100                        --locked
101                        --keep-going
102                        --exclude-features tpm
103                        check
104                        --profile {profile}
105                    "
106                )
107                .run()?;
108
109                Ok(())
110            }
111        });
112
113        Ok(())
114    }
115}