flowey_lib_hvlite/_jobs/
cfg_versions.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! An amalgamated configuration node that streamlines the process of resolving
5//! version configuration requests required by various dependencies in OpenVMM
6//! pipelines.
7
8use crate::resolve_openhcl_kernel_package::OpenhclKernelPackageKind;
9use crate::run_cargo_build::common::CommonArch;
10use flowey::node::prelude::*;
11use std::collections::BTreeMap;
12
13// FUTURE: instead of hard-coding these values in-code, we might want to make
14// our own nuget-esque `packages.config` file, that we can read at runtime to
15// resolve all Version requests.
16//
17// This would require nodes that currently accept a `Version(String)` to accept
18// a `Version(ReadVar<String>)`, but that shouldn't be a serious blocker.
19pub const AZCOPY: &str = "10.27.1";
20pub const AZURE_CLI: &str = "2.56.0";
21pub const FUZZ: &str = "0.12.0";
22pub const GH_CLI: &str = "2.52.0";
23pub const MDBOOK: &str = "0.4.40";
24pub const MDBOOK_ADMONISH: &str = "1.18.0";
25pub const MDBOOK_MERMAID: &str = "0.14.0";
26pub const MU_MSVM: &str = "25.1.11";
27pub const NEXTEST: &str = "0.9.101";
28pub const NODEJS: &str = "24.x";
29// N.B. Kernel version numbers for dev and stable branches are not directly
30//      comparable. They originate from separate branches, and the fourth digit
31//      increases with each release from the respective branch.
32pub const OPENHCL_KERNEL_DEV_VERSION: &str = "6.12.52.5";
33pub const OPENHCL_KERNEL_STABLE_VERSION: &str = "6.12.52.5";
34pub const OPENVMM_DEPS: &str = "0.1.0-20250403.3";
35pub const PROTOC: &str = "27.1";
36
37flowey_request! {
38    pub enum Request {
39        /// Initialize the node, defaults to downloading everything
40        Init,
41        /// Override openvmm_deps with a local path for this architecture
42        LocalOpenvmmDeps(CommonArch, PathBuf),
43        /// Override protoc with a local path
44        LocalProtoc(PathBuf),
45        /// Override kernel with local paths (kernel binary, modules directory)
46        LocalKernel {
47            arch: CommonArch,
48            kernel: PathBuf,
49            modules: PathBuf,
50        },
51        /// Override UEFI mu_msvm with a local MSVM.fd path for this architecture
52        LocalUefi(CommonArch, PathBuf),
53    }
54}
55
56new_flow_node!(struct Node);
57
58impl FlowNode for Node {
59    type Request = Request;
60
61    fn imports(ctx: &mut ImportCtx<'_>) {
62        ctx.import::<crate::resolve_openhcl_kernel_package::Node>();
63        ctx.import::<crate::resolve_openvmm_deps::Node>();
64        ctx.import::<crate::download_uefi_mu_msvm::Node>();
65        ctx.import::<crate::cfg_rustup_version::Node>();
66        ctx.import::<flowey_lib_common::download_azcopy::Node>();
67        ctx.import::<flowey_lib_common::download_cargo_fuzz::Node>();
68        ctx.import::<flowey_lib_common::download_cargo_nextest::Node>();
69        ctx.import::<flowey_lib_common::download_gh_cli::Node>();
70        ctx.import::<flowey_lib_common::download_mdbook_admonish::Node>();
71        ctx.import::<flowey_lib_common::download_mdbook_mermaid::Node>();
72        ctx.import::<flowey_lib_common::download_mdbook::Node>();
73        ctx.import::<flowey_lib_common::resolve_protoc::Node>();
74        ctx.import::<flowey_lib_common::install_azure_cli::Node>();
75        ctx.import::<flowey_lib_common::install_nodejs::Node>();
76    }
77
78    #[rustfmt::skip]
79    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
80        let mut local_openvmm_deps: BTreeMap<CommonArch, PathBuf> = BTreeMap::new();
81        let mut local_protoc: Option<PathBuf> = None;
82        let mut local_kernel: BTreeMap<CommonArch, (PathBuf, PathBuf)> = BTreeMap::new();
83        let mut local_uefi: BTreeMap<CommonArch, PathBuf> = BTreeMap::new();
84
85        for req in requests {
86            match req {
87                Request::Init => {
88                    // No-op, just ensures the node runs with defaults
89                }
90                Request::LocalOpenvmmDeps(arch, path) => {
91                    // Check that for every arch that shows up, the path is always the same
92                    if let Some(existing_path) = local_openvmm_deps.get(&arch) {
93                        if existing_path != &path {
94                            anyhow::bail!(
95                                "OpenvmmDepsPath for {:?} must be consistent across requests",
96                                arch
97                            );
98                        }
99                    } else {
100                        local_openvmm_deps.insert(arch, path);
101                    }
102                }
103                Request::LocalProtoc(path) => {
104                    same_across_all_reqs("ProtocPath", &mut local_protoc, path)?;
105                }
106                Request::LocalKernel { arch, kernel, modules } => {
107                    let paths = (kernel, modules);
108                    if let Some(existing) = local_kernel.get(&arch) {
109                        if existing != &paths {
110                            anyhow::bail!(
111                                "LocalKernel for {:?} must be consistent across requests",
112                                arch
113                            );
114                        }
115                    } else {
116                        local_kernel.insert(arch, paths);
117                    }
118                }
119                Request::LocalUefi(arch, path) => {
120                    if let Some(existing) = local_uefi.get(&arch) {
121                        if existing != &path {
122                            anyhow::bail!(
123                                "LocalUefi for {:?} must be consistent across requests",
124                                arch
125                            );
126                        }
127                    } else {
128                        local_uefi.insert(arch, path);
129                    }
130                }
131            }
132        }
133
134        // Track whether we have local paths for openvmm_deps and protoc
135        let has_local_openvmm_deps = !local_openvmm_deps.is_empty();
136        let has_local_protoc = local_protoc.is_some();
137        let has_local_kernel = !local_kernel.is_empty();
138        let has_local_uefi = !local_uefi.is_empty();
139
140        // Set up local paths for openvmm_deps if provided
141        for (arch, path) in local_openvmm_deps {
142            let openvmm_deps_arch = match arch {
143                CommonArch::X86_64 => crate::resolve_openvmm_deps::OpenvmmDepsArch::X86_64,
144                CommonArch::Aarch64 => crate::resolve_openvmm_deps::OpenvmmDepsArch::Aarch64,
145            };
146
147            ctx.req(crate::resolve_openvmm_deps::Request::LocalPath(
148                openvmm_deps_arch,
149                path,
150            ));
151        }
152
153        // Set up local path for protoc if provided
154        if let Some(protoc_path) = local_protoc {
155            ctx.req(flowey_lib_common::resolve_protoc::Request::LocalPath(
156                protoc_path,
157            ));
158        }
159
160        // Set up local paths for kernel if provided
161        for (arch, (kernel, modules)) in local_kernel {
162            let kernel_arch = match arch {
163                CommonArch::X86_64 => crate::resolve_openhcl_kernel_package::OpenhclKernelPackageArch::X86_64,
164                CommonArch::Aarch64 => crate::resolve_openhcl_kernel_package::OpenhclKernelPackageArch::Aarch64,
165            };
166            ctx.req(crate::resolve_openhcl_kernel_package::Request::SetLocal {
167                arch: kernel_arch,
168                kernel,
169                modules,
170            });
171        }
172
173        // Set up local paths for UEFI if provided
174        for (arch, path) in local_uefi {
175            let uefi_arch = match arch {
176                CommonArch::X86_64 => crate::download_uefi_mu_msvm::MuMsvmArch::X86_64,
177                CommonArch::Aarch64 => crate::download_uefi_mu_msvm::MuMsvmArch::Aarch64,
178            };
179            ctx.req(crate::download_uefi_mu_msvm::Request::LocalPath(uefi_arch, path));
180        }
181
182        // Only set kernel versions if we don't have local paths
183        // (versions are only needed for downloading)
184        if !has_local_kernel {
185            ctx.req(crate::resolve_openhcl_kernel_package::Request::SetVersion(OpenhclKernelPackageKind::Dev, OPENHCL_KERNEL_DEV_VERSION.into()));
186            ctx.req(crate::resolve_openhcl_kernel_package::Request::SetVersion(OpenhclKernelPackageKind::Main, OPENHCL_KERNEL_STABLE_VERSION.into()));
187            ctx.req(crate::resolve_openhcl_kernel_package::Request::SetVersion(OpenhclKernelPackageKind::Cvm, OPENHCL_KERNEL_STABLE_VERSION.into()));
188            ctx.req(crate::resolve_openhcl_kernel_package::Request::SetVersion(OpenhclKernelPackageKind::CvmDev, OPENHCL_KERNEL_DEV_VERSION.into()));
189        }
190        if !has_local_openvmm_deps {
191            ctx.req(crate::resolve_openvmm_deps::Request::Version(OPENVMM_DEPS.into()));
192        }
193        if !has_local_uefi {
194            ctx.req(crate::download_uefi_mu_msvm::Request::Version(MU_MSVM.into()));
195        }
196        ctx.req(flowey_lib_common::download_azcopy::Request::Version(AZCOPY.into()));
197        ctx.req(flowey_lib_common::download_cargo_fuzz::Request::Version(FUZZ.into()));
198        ctx.req(flowey_lib_common::download_cargo_nextest::Request::Version(NEXTEST.into()));
199        ctx.req(flowey_lib_common::download_gh_cli::Request::Version(GH_CLI.into()));
200        ctx.req(flowey_lib_common::download_mdbook::Request::Version(MDBOOK.into()));
201        ctx.req(flowey_lib_common::download_mdbook_admonish::Request::Version(MDBOOK_ADMONISH.into()));
202        ctx.req(flowey_lib_common::download_mdbook_mermaid::Request::Version(MDBOOK_MERMAID.into()));
203        if !has_local_protoc {
204            ctx.req(flowey_lib_common::resolve_protoc::Request::Version(PROTOC.into()));
205        }
206        ctx.req(flowey_lib_common::install_azure_cli::Request::Version(AZURE_CLI.into()));
207        ctx.req(flowey_lib_common::install_nodejs::Request::Version(NODEJS.into()));
208        ctx.req(crate::cfg_rustup_version::Request::Init);
209        Ok(())
210    }
211}