flowey_lib_common/
cfg_persistent_dir_cargo_install.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! A node which returns a PathBuf to a single shared persistent-dir that can be
5//! used by any nodes invoking `cargo install` in order to share a single cargo
6//! build cache.
7
8use flowey::node::prelude::*;
9
10flowey_request! {
11    pub struct Request(pub WriteVar<Option<PathBuf>>);
12}
13
14new_flow_node!(struct Node);
15
16impl FlowNode for Node {
17    type Request = Request;
18
19    fn imports(_ctx: &mut ImportCtx<'_>) {}
20
21    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
22        let persistent_dir = ctx.persistent_dir();
23        ctx.emit_minor_rust_step("report cargo install persistent dir", |ctx| {
24            let persistent_dir = persistent_dir.claim(ctx);
25            let requests = requests
26                .into_iter()
27                .map(|x| x.0.claim(ctx))
28                .collect::<Vec<_>>();
29            |rt| {
30                let persistent_dir = rt.read(persistent_dir);
31                for var in requests {
32                    rt.write(var, &persistent_dir)
33                }
34            }
35        });
36
37        Ok(())
38    }
39}