microsoft/openvmm
Publicmirrored fromhttps://github.com/microsoft/openvmmAvailable
flowey/flowey_lib_hvlite/src/build_igvmfilegen.rs
105lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | //! Build `igvmfilegen` binaries |
| 5 | |
| 6 | use crate::common::CommonTriple; |
| 7 | use crate::run_cargo_build::BuildProfile; |
| 8 | use flowey::node::prelude::*; |
| 9 | use std::collections::BTreeMap; |
| 10 | |
| 11 | #[derive(Serialize, Deserialize)] |
| 12 | #[serde(untagged)] |
| 13 | pub enum IgvmfilegenOutput { |
| 14 | LinuxBin { |
| 15 | #[serde(rename = "igvmfilegen")] |
| 16 | bin: PathBuf, |
| 17 | #[serde(rename = "igvmfilegen.dbg")] |
| 18 | dbg: PathBuf, |
| 19 | }, |
| 20 | WindowsBin { |
| 21 | #[serde(rename = "igvmfilegen.exe")] |
| 22 | exe: PathBuf, |
| 23 | #[serde(rename = "igvmfilegen.pdb")] |
| 24 | pdb: PathBuf, |
| 25 | }, |
| 26 | } |
| 27 | |
| 28 | impl Artifact for IgvmfilegenOutput {} |
| 29 | |
| 30 | #[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] |
| 31 | pub struct IgvmfilegenBuildParams { |
| 32 | pub target: CommonTriple, |
| 33 | pub profile: BuildProfile, |
| 34 | } |
| 35 | |
| 36 | flowey_request! { |
| 37 | pub struct Request { |
| 38 | pub build_params: IgvmfilegenBuildParams, |
| 39 | pub igvmfilegen: WriteVar<IgvmfilegenOutput>, |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | new_flow_node!(struct Node); |
| 44 | |
| 45 | impl FlowNode for Node { |
| 46 | type Request = Request; |
| 47 | |
| 48 | fn imports(ctx: &mut ImportCtx<'_>) { |
| 49 | ctx.import::<crate::run_cargo_build::Node>(); |
| 50 | } |
| 51 | |
| 52 | fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> { |
| 53 | // de-dupe incoming requests |
| 54 | let requests = requests |
| 55 | .into_iter() |
| 56 | .fold(BTreeMap::<_, Vec<_>>::new(), |mut m, r| { |
| 57 | let Request { |
| 58 | build_params, |
| 59 | igvmfilegen, |
| 60 | } = r; |
| 61 | m.entry(build_params).or_default().push(igvmfilegen); |
| 62 | m |
| 63 | }); |
| 64 | |
| 65 | for (IgvmfilegenBuildParams { target, profile }, outvars) in requests { |
| 66 | let output = ctx.reqv(|v| crate::run_cargo_build::Request { |
| 67 | crate_name: "igvmfilegen".into(), |
| 68 | out_name: "igvmfilegen".into(), |
| 69 | crate_type: flowey_lib_common::run_cargo_build::CargoCrateType::Bin, |
| 70 | profile, |
| 71 | features: Default::default(), |
| 72 | target: target.as_triple(), |
| 73 | no_split_dbg_info: false, |
| 74 | extra_env: None, |
| 75 | pre_build_deps: Vec::new(), |
| 76 | output: v, |
| 77 | }); |
| 78 | |
| 79 | ctx.emit_minor_rust_step("report built igvmfilegen", |ctx| { |
| 80 | let outvars = outvars.claim(ctx); |
| 81 | let output = output.claim(ctx); |
| 82 | move |rt| { |
| 83 | let output = match rt.read(output) { |
| 84 | crate::run_cargo_build::CargoBuildOutput::WindowsBin { exe, pdb } => { |
| 85 | IgvmfilegenOutput::WindowsBin { exe, pdb } |
| 86 | } |
| 87 | crate::run_cargo_build::CargoBuildOutput::ElfBin { bin, dbg } => { |
| 88 | IgvmfilegenOutput::LinuxBin { |
| 89 | bin, |
| 90 | dbg: dbg.unwrap(), |
| 91 | } |
| 92 | } |
| 93 | _ => unreachable!(), |
| 94 | }; |
| 95 | |
| 96 | for var in outvars { |
| 97 | rt.write(var, &output); |
| 98 | } |
| 99 | } |
| 100 | }); |
| 101 | } |
| 102 | |
| 103 | Ok(()) |
| 104 | } |
| 105 | } |
| 106 | |