Skip to main content

flowey_lib_hvlite/
build_test_igvm_agent_rpc_server.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Build `test_igvm_agent_rpc_server` binaries
5
6use crate::common::CommonProfile;
7use crate::common::CommonTriple;
8use flowey::node::prelude::*;
9use flowey_lib_common::run_cargo_build::CargoCrateType;
10use std::collections::BTreeMap;
11
12#[derive(Serialize, Deserialize)]
13pub struct TestIgvmAgentRpcServerOutput {
14    #[serde(rename = "test_igvm_agent_rpc_server.exe")]
15    pub exe: PathBuf,
16    #[serde(rename = "test_igvm_agent_rpc_server.pdb")]
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    pub pdb: Option<PathBuf>,
19}
20
21impl Artifact for TestIgvmAgentRpcServerOutput {}
22
23flowey_request! {
24    pub struct Request {
25        pub target: CommonTriple,
26        pub profile: CommonProfile,
27        pub test_igvm_agent_rpc_server: WriteVar<TestIgvmAgentRpcServerOutput>,
28    }
29}
30
31new_simple_flow_node!(struct Node);
32
33impl SimpleFlowNode for Node {
34    type Request = Request;
35
36    fn imports(ctx: &mut ImportCtx<'_>) {
37        ctx.import::<crate::run_cargo_build::Node>();
38    }
39
40    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
41        let Request {
42            target,
43            profile,
44            test_igvm_agent_rpc_server,
45        } = request;
46
47        let target_triple = target.as_triple();
48
49        // Only Windows MSVC is supported for test_igvm_agent_rpc_server
50        if target_triple.operating_system != target_lexicon::OperatingSystem::Windows
51            || target_triple.environment != target_lexicon::Environment::Msvc
52        {
53            anyhow::bail!(
54                "test_igvm_agent_rpc_server only supports Windows MSVC targets, got: {}",
55                target_triple
56            );
57        }
58
59        let env_key = format!(
60            "CARGO_TARGET_{}_RUSTFLAGS",
61            target_triple.to_string().replace('-', "_").to_uppercase()
62        );
63
64        let mut env: BTreeMap<String, String> = BTreeMap::new();
65
66        // Enable CRT static linking
67        env.insert(env_key, "-Ctarget-feature=+crt-static".to_string());
68
69        let extra_env = Some(ReadVar::from_static(env));
70
71        let output = ctx.reqv(|v| crate::run_cargo_build::Request {
72            crate_name: "test_igvm_agent_rpc_server".into(),
73            out_name: "test_igvm_agent_rpc_server".into(),
74            crate_type: CargoCrateType::Bin,
75            profile: profile.into(),
76            features: Default::default(),
77            target: target_triple,
78            no_split_dbg_info: false,
79            extra_env,
80            pre_build_deps: Vec::new(),
81            output: v,
82        });
83
84        ctx.emit_minor_rust_step("report built test_igvm_agent_rpc_server", |ctx| {
85            let test_igvm_agent_rpc_server = test_igvm_agent_rpc_server.claim(ctx);
86            let output = output.claim(ctx);
87            move |rt| {
88                let output = match rt.read(output) {
89                    crate::run_cargo_build::CargoBuildOutput::WindowsBin { exe, pdb } => {
90                        TestIgvmAgentRpcServerOutput { exe, pdb }
91                    }
92                    _ => unreachable!(
93                        "unsupported build output variant for test_igvm_agent_rpc_server"
94                    ),
95                };
96
97                rt.write(test_igvm_agent_rpc_server, &output);
98            }
99        });
100
101        Ok(())
102    }
103}