1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use crate::cache::{CacheMode, GetPathResult};
use crate::compiler::ColorMode;
use crate::config::PreprocessorCacheModeConfig;
use crate::server::{DistInfo, ServerInfo, ServerStats};
use serde::{Deserialize, Serialize};
use std::ffi::OsString;
/// A client request.
#[derive(Serialize, Deserialize, Debug)]
pub enum Request {
/// Zero the server's statistics.
ZeroStats,
/// Get server statistics.
GetStats,
/// Get dist status.
DistStatus,
/// Shut the server down gracefully.
Shutdown,
/// Execute a compile or fetch a cached compilation result.
Compile(Compile),
// --- Storage RPCs (client-side mode) ---
/// One-shot handshake: client requests cache metadata from the daemon.
StorageHandshake,
/// Fetch the filesystem path of the cached entry for `key`.
/// Returns `None` if the backend does not support direct file access or the key is absent.
StorageGetPath { key: String },
/// Fetch raw (zip) bytes for `key`; returns `None` on a miss.
StorageGetRaw { key: String },
/// Store raw (zip) bytes under `key`.
StoragePutRaw { key: String, data: Vec<u8> },
/// Retrieve the preprocessor cache entry for `key`.
StorageGetPreprocessorEntry { key: String },
/// Store or overwrite the preprocessor cache entry for `key`.
StoragePutPreprocessorEntry { key: String, entry_bytes: Vec<u8> },
/// Merge per-invocation stats into the daemon's running totals.
RecordStats(Box<ServerStats>),
}
/// A server response.
#[derive(Serialize, Deserialize, Debug)]
pub enum Response {
/// Response for `Request::Compile`.
Compile(CompileResponse),
/// Response for `Request::ZeroStats`.
ZeroStats,
/// Response for `Request::GetStats`, containing server statistics.
Stats(Box<ServerInfo>),
/// Response for `Request::DistStatus`, containing client info.
DistStatus(DistInfo),
/// Response for `Request::Shutdown`, containing server statistics.
ShuttingDown(Box<ServerInfo>),
/// Second response for `Request::Compile`, containing the results of the compilation.
CompileFinished(CompileFinished),
// --- Storage RPC responses (client-side mode) ---
/// Response for `Request::StorageHandshake`.
StorageHandshake(StorageHandshakeInfo),
/// Response for `Request::StorageGetPath`.
StorageGetPath(GetPathResult),
/// Response for `Request::StorageGetRaw`: zip bytes on hit, `None` on miss.
StorageGetRaw(Option<Vec<u8>>),
/// Response for `Request::StoragePutRaw`.
StoragePutRaw(Result<(), String>),
/// Response for `Request::StorageGetPreprocessorEntry`.
StorageGetPreprocessorEntry(Result<Option<Vec<u8>>, String>),
/// Response for `Request::StoragePutPreprocessorEntry`.
StoragePutPreprocessorEntry(Result<(), String>),
/// Response for `Request::RecordStats`.
RecordStats,
}
/// Possible responses from the server for a `Compile` request.
#[derive(Serialize, Deserialize, Debug)]
pub enum CompileResponse {
/// The compilation was started.
CompileStarted,
/// The server could not handle this compilation request.
UnhandledCompile,
/// The compiler was not supported.
UnsupportedCompiler(OsString),
}
/// Information about a finished compile, either from cache or executed locally.
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct CompileFinished {
/// The return code of the compile process, if available.
pub retcode: Option<i32>,
/// The signal that terminated the compile process, if available.
pub signal: Option<i32>,
/// The compiler's stdout.
pub stdout: Vec<u8>,
/// The compiler's stderr.
pub stderr: Vec<u8>,
/// The state of any compiler options passed to control color output.
pub color_mode: ColorMode,
}
/// The contents of a compile request from a client.
#[derive(Serialize, Deserialize, Debug)]
pub struct Compile {
/// The full path to the compiler executable.
pub exe: OsString,
/// The current working directory in which to execute the compile.
pub cwd: OsString,
/// The commandline arguments passed to the compiler.
pub args: Vec<OsString>,
/// The environment variables present when the compiler was executed, as (var, val).
pub env_vars: Vec<(OsString, OsString)>,
}
/// Cache metadata returned by the daemon on `StorageHandshake`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct StorageHandshakeInfo {
pub location: String,
pub cache_type_name: String,
pub basedirs: Vec<Vec<u8>>,
pub preprocessor_cache_mode_config: PreprocessorCacheModeConfig,
pub cache_mode: CacheMode,
pub max_size: Option<u64>,
}