flowey_lib_hvlite/
init_openvmm_magicpath_protoc.rs1use flowey::node::prelude::*;
8
9flowey_request! {
10 pub struct Request(pub WriteVar<SideEffect>);
11}
12
13new_flow_node!(struct Node);
14
15impl FlowNode for Node {
16 type Request = Request;
17
18 fn imports(ctx: &mut ImportCtx<'_>) {
19 ctx.import::<crate::cfg_openvmm_magicpath::Node>();
20 ctx.import::<flowey_lib_common::download_protoc::Node>();
21 }
22
23 fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
24 let protoc_pkg = ctx.reqv(flowey_lib_common::download_protoc::Request::Get);
25 let openvmm_magicpath = ctx.reqv(crate::cfg_openvmm_magicpath::Request);
26
27 ctx.emit_rust_step("symlink protoc", move |ctx| {
28 requests.into_iter().for_each(|x| {
29 x.0.claim(ctx);
30 });
31 let protoc_pkg = protoc_pkg.claim(ctx);
32 let openvmm_magicpath = openvmm_magicpath.claim(ctx);
33 move |rt| {
34 let expected_protoc_bin = {
35 match rt.platform() {
36 FlowPlatform::Windows => "protoc.exe",
37 FlowPlatform::MacOs | FlowPlatform::Linux(_) => "protoc",
38 _ => unreachable!("unknown host os"),
39 }
40 };
41
42 let openvmm_magicpath = rt.read(openvmm_magicpath);
43 let dst_folder = openvmm_magicpath.join("Google.Protobuf.Tools/tools");
44 fs_err::create_dir_all(&dst_folder)?;
45
46 let protoc_pkg = rt.read(protoc_pkg);
47
48 flowey_lib_common::_util::copy_dir_all(
49 protoc_pkg.include_dir,
50 openvmm_magicpath.join("Google.Protobuf.Tools/tools/include"),
51 )?;
52
53 let src = protoc_pkg.protoc_bin;
54 let dst = dst_folder.join(expected_protoc_bin);
55
56 let _ = fs_err::remove_file(&dst);
57
58 if !dst.exists() {
59 fs_err::hard_link(src.clone(), &dst)?;
60 dst.make_executable()?;
61 }
62
63 Ok(())
64 }
65 });
66
67 Ok(())
68 }
69}