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