Skip to main content

flowey_hvlite/pipelines/
build_opentmk.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! See [`BuildOpentmkCli`]
5
6use crate::pipelines::build_igvm::bail_if_running_in_ci;
7use crate::pipelines_shared::cfg_common_params::CommonArchCli;
8use flowey::node::prelude::ReadVar;
9use flowey::pipeline::prelude::*;
10use flowey_lib_hvlite::common::CommonArch;
11use std::path::PathBuf;
12
13/// Build OpenTMK and package it into a bootable VHD.
14#[derive(clap::Args)]
15pub struct BuildOpentmkCli {
16    /// Target architecture for the OpenTMK build. Defaults to x86-64.
17    #[clap(default_value = "x86-64")]
18    pub arch: CommonArchCli,
19
20    /// Custom name for the output `.efi`, `.vhd`, and `.pdb` (default `opentmk`).
21    #[clap(long)]
22    pub name: Option<String>,
23
24    /// Path to a JSON test-selection config to embed in the built VHD. If
25    /// omitted, the VHD boots the unconfigured `opentmk.efi`.
26    #[clap(long)]
27    pub config: Option<PathBuf>,
28
29    /// Build using release profile.
30    #[clap(long)]
31    pub release: bool,
32
33    /// Directory for the output artifacts.
34    #[clap(long, default_value = "flowey-out/build-opentmk")]
35    pub dir: PathBuf,
36
37    /// pass `--verbose` to cargo
38    #[clap(long)]
39    pub verbose: bool,
40
41    /// pass `--locked` to cargo
42    #[clap(long)]
43    pub locked: bool,
44
45    /// Automatically install any missing required dependencies.
46    #[clap(long)]
47    pub install_missing_deps: bool,
48}
49
50impl IntoPipeline for BuildOpentmkCli {
51    fn into_pipeline(self, backend_hint: PipelineBackendHint) -> anyhow::Result<Pipeline> {
52        if !matches!(backend_hint, PipelineBackendHint::Local) {
53            anyhow::bail!("build-opentmk is for local use only")
54        }
55
56        bail_if_running_in_ci()?;
57
58        let openvmm_repo = flowey_lib_common::git_checkout::RepoSource::ExistingClone(
59            ReadVar::from_static(crate::repo_root()),
60        );
61
62        let Self {
63            arch,
64            name,
65            config,
66            release,
67            dir,
68            verbose,
69            locked,
70            install_missing_deps,
71        } = self;
72
73        let arch: CommonArch = arch.into();
74
75        std::fs::create_dir_all(&dir)?;
76
77        let mut pipeline = Pipeline::new();
78
79        pipeline
80            .new_job(
81                FlowPlatform::host(backend_hint),
82                FlowArch::host(backend_hint),
83                "build-opentmk",
84            )
85            .dep_on(|_| flowey_lib_hvlite::_jobs::cfg_versions::Request::Init)
86            .dep_on(
87                |_| flowey_lib_hvlite::_jobs::cfg_hvlite_reposource::Params {
88                    hvlite_repo_source: openvmm_repo,
89                },
90            )
91            .dep_on(|_| flowey_lib_hvlite::_jobs::cfg_common::Params {
92                local_only: Some(flowey_lib_hvlite::_jobs::cfg_common::LocalOnlyParams {
93                    interactive: true,
94                    auto_install: install_missing_deps,
95                    ignore_rust_version: true,
96                }),
97                verbose: ReadVar::from_static(verbose),
98                locked,
99                deny_warnings: false,
100                no_incremental: false,
101            })
102            .dep_on(
103                |ctx| flowey_lib_hvlite::_jobs::local_build_opentmk::Params {
104                    artifact_dir: ReadVar::from_static(dir),
105                    done: ctx.new_done_handle(),
106                    arch,
107                    release,
108                    name,
109                    config,
110                },
111            )
112            .finish();
113
114        Ok(pipeline)
115    }
116}