Skip to main content

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::common::CommonArch;
9use crate::resolve_openhcl_kernel_package::OpenhclKernelPackageKind;
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 DOTNET: &str = "8.0";
22pub const FUZZ: &str = "0.12.0";
23pub const GH_CLI: &str = "2.52.0";
24pub const MDBOOK: &str = "0.4.40";
25pub const MDBOOK_ADMONISH: &str = "1.18.0";
26pub const MDBOOK_MERMAID: &str = "0.14.0";
27pub const MU_MSVM: &str = "26.0.0";
28pub const NEXTEST: &str = "0.9.101";
29pub const NODEJS: &str = "24.x";
30// N.B. Kernel version numbers for dev and stable branches are not directly
31//      comparable. They originate from separate branches, and the fourth digit
32//      increases with each release from the respective branch.
33pub const OPENHCL_KERNEL_DEV_VERSION: &str = "6.12.52.12";
34pub const OPENHCL_KERNEL_STABLE_VERSION: &str = "6.12.52.11";
35pub const OPENVMM_DEPS: &str = "0.1.0-20260401.1";
36pub const PROTOC: &str = "27.1";
37
38flowey_request! {
39    pub enum Request {
40        /// Initialize the node, defaults to downloading everything
41        Init,
42        /// Override openvmm_deps with a local path for this architecture
43        LocalOpenvmmDeps(CommonArch, ReadVar<PathBuf>),
44        /// Override protoc with a local path
45        LocalProtoc(ReadVar<PathBuf>),
46        /// Override kernel with local paths (kernel binary, modules directory)
47        LocalKernel {
48            arch: CommonArch,
49            kernel: ReadVar<PathBuf>,
50            modules: ReadVar<PathBuf>,
51        },
52        /// Override UEFI mu_msvm with a local MSVM.fd path for this architecture
53        LocalUefi(CommonArch, ReadVar<PathBuf>),
54    }
55}
56
57new_flow_node!(struct Node);
58
59impl FlowNode for Node {
60    type Request = Request;
61
62    fn imports(ctx: &mut ImportCtx<'_>) {
63        ctx.import::<crate::resolve_openhcl_kernel_package::Node>();
64        ctx.import::<crate::resolve_openvmm_deps::Node>();
65        ctx.import::<crate::download_uefi_mu_msvm::Node>();
66        ctx.import::<crate::cfg_rustup_version::Node>();
67        ctx.import::<flowey_lib_common::download_azcopy::Node>();
68        ctx.import::<flowey_lib_common::download_cargo_fuzz::Node>();
69        ctx.import::<flowey_lib_common::download_cargo_nextest::Node>();
70        ctx.import::<flowey_lib_common::download_gh_cli::Node>();
71        ctx.import::<flowey_lib_common::download_mdbook_admonish::Node>();
72        ctx.import::<flowey_lib_common::download_mdbook_mermaid::Node>();
73        ctx.import::<flowey_lib_common::download_mdbook::Node>();
74        ctx.import::<flowey_lib_common::resolve_protoc::Node>();
75        ctx.import::<flowey_lib_common::install_azure_cli::Node>();
76        ctx.import::<flowey_lib_common::install_dotnet_cli::Node>();
77        ctx.import::<flowey_lib_common::install_nodejs::Node>();
78    }
79
80    #[rustfmt::skip]
81    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
82        let mut local_openvmm_deps: BTreeMap<CommonArch, ReadVar<PathBuf>> = BTreeMap::new();
83        let mut local_protoc: Option<ReadVar<PathBuf>> = None;
84        let mut local_kernel: BTreeMap<CommonArch, (ReadVar<PathBuf>, ReadVar<PathBuf>)> = BTreeMap::new();
85        let mut local_uefi: BTreeMap<CommonArch, ReadVar<PathBuf>> = BTreeMap::new();
86
87        for req in requests {
88            match req {
89                Request::Init => {
90                    // No-op, just ensures the node runs with defaults
91                }
92                Request::LocalOpenvmmDeps(arch, path) => {
93                    if local_openvmm_deps.contains_key(&arch) {
94                        anyhow::bail!(
95                            "OpenvmmDepsPath for {:?} must not be specified multiple times",
96                            arch
97                        );
98                    }
99                    local_openvmm_deps.insert(arch, path);
100                }
101                Request::LocalProtoc(path) => {
102                    if local_protoc.is_some() {
103                        anyhow::bail!("ProtocPath must not be specified multiple times");
104                    }
105                    local_protoc = Some(path);
106                }
107                Request::LocalKernel { arch, kernel, modules } => {
108                    if local_kernel.contains_key(&arch) {
109                        anyhow::bail!(
110                            "LocalKernel for {:?} must not be specified multiple times",
111                            arch
112                        );
113                    }
114                    local_kernel.insert(arch, (kernel, modules));
115                }
116                Request::LocalUefi(arch, path) => {
117                    if local_uefi.contains_key(&arch) {
118                        anyhow::bail!(
119                            "LocalUefi for {:?} must not be specified multiple times",
120                            arch
121                        );
122                    }
123                    local_uefi.insert(arch, path);
124                }
125            }
126        }
127
128        // Track whether we have local paths for openvmm_deps and protoc
129        let has_local_openvmm_deps = !local_openvmm_deps.is_empty();
130        let has_local_protoc = local_protoc.is_some();
131        let has_local_kernel = !local_kernel.is_empty();
132        let has_local_uefi = !local_uefi.is_empty();
133
134        // Set up local paths for openvmm_deps if provided
135        if !local_openvmm_deps.is_empty() {
136            let deps_local_paths = local_openvmm_deps
137                .into_iter()
138                .map(|(arch, path)| (arch, ConfigVar(path)))
139                .collect();
140            ctx.config(crate::resolve_openvmm_deps::Config {
141                local_paths: deps_local_paths,
142                ..Default::default()
143            });
144        }
145
146        // Set up local path for protoc if provided
147        if let Some(protoc_path) = local_protoc {
148            ctx.config(flowey_lib_common::resolve_protoc::Config {
149                local_path: Some(ConfigVar(protoc_path)),
150                ..Default::default()
151            });
152        }
153
154        // Set up local paths for kernel if provided
155        if !local_kernel.is_empty() {
156            let kernel_local_paths = local_kernel
157                .into_iter()
158                .map(|(arch, (kernel, modules))| {
159                    (arch, (ConfigVar(kernel), ConfigVar(modules)))
160                })
161                .collect();
162            ctx.config(crate::resolve_openhcl_kernel_package::Config {
163                local_paths: kernel_local_paths,
164                ..Default::default()
165            });
166        }
167
168        // Set up local paths for UEFI if provided
169        if !local_uefi.is_empty() {
170            let uefi_local_paths = local_uefi
171                .into_iter()
172                .map(|(arch, path)| (arch, ConfigVar(path)))
173                .collect();
174            ctx.config(crate::download_uefi_mu_msvm::Config {
175                local_paths: uefi_local_paths,
176                ..Default::default()
177            });
178        }
179
180        // Only set kernel versions if we don't have local paths
181        // (versions are only needed for downloading)
182        if !has_local_kernel {
183            ctx.config(crate::resolve_openhcl_kernel_package::Config {
184                versions: [
185                    (OpenhclKernelPackageKind::Dev, OPENHCL_KERNEL_DEV_VERSION.into()),
186                    (OpenhclKernelPackageKind::Main, OPENHCL_KERNEL_STABLE_VERSION.into()),
187                    (OpenhclKernelPackageKind::Cvm, OPENHCL_KERNEL_STABLE_VERSION.into()),
188                    (OpenhclKernelPackageKind::CvmDev, OPENHCL_KERNEL_DEV_VERSION.into()),
189                ].into(),
190                ..Default::default()
191            });
192        }
193        if !has_local_openvmm_deps {
194            ctx.config(crate::resolve_openvmm_deps::Config {
195                version: Some(OPENVMM_DEPS.into()),
196                ..Default::default()
197            });
198        }
199        if !has_local_uefi {
200            ctx.config(crate::download_uefi_mu_msvm::Config {
201                version: Some(MU_MSVM.into()),
202                ..Default::default()
203            });
204        }
205        ctx.config(flowey_lib_common::download_azcopy::Config {
206            version: Some(AZCOPY.into()),
207        });
208        ctx.config(flowey_lib_common::download_cargo_fuzz::Config {
209            version: Some(FUZZ.into()),
210        });
211        ctx.config(flowey_lib_common::download_cargo_nextest::Config {
212            version: Some(NEXTEST.into()),
213        });
214        ctx.config(flowey_lib_common::download_gh_cli::Config {
215            version: Some(GH_CLI.into()),
216        });
217        ctx.config(flowey_lib_common::download_mdbook::Config {
218            version: Some(MDBOOK.into()),
219        });
220        ctx.config(flowey_lib_common::download_mdbook_admonish::Config {
221            version: Some(MDBOOK_ADMONISH.into()),
222        });
223        ctx.config(flowey_lib_common::download_mdbook_mermaid::Config {
224            version: Some(MDBOOK_MERMAID.into()),
225        });
226        if !has_local_protoc {
227            ctx.config(flowey_lib_common::resolve_protoc::Config {
228                version: Some(PROTOC.into()),
229                ..Default::default()
230            });
231        }
232        ctx.config(flowey_lib_common::install_azure_cli::Config {
233            version: Some(AZURE_CLI.into()),
234            ..Default::default()
235        });
236        ctx.config(flowey_lib_common::install_dotnet_cli::Config {
237            version: Some(DOTNET.into()),
238            ..Default::default()
239        });
240        ctx.config(flowey_lib_common::install_nodejs::Config {
241            version: Some(NODEJS.into()),
242            ..Default::default()
243        });
244        ctx.req(crate::cfg_rustup_version::Request::Init);
245        Ok(())
246    }
247}