|
10 | 10 | * |
11 | 11 | * Vix.cpp |
12 | 12 | * |
13 | | - * Object file cache |
| 13 | + * Compatibility adapter for the engine object cache. |
14 | 14 | * |
15 | 15 | */ |
16 | 16 |
|
17 | 17 | #ifndef VIX_CLI_BUILD_OBJECT_CACHE_HPP |
18 | 18 | #define VIX_CLI_BUILD_OBJECT_CACHE_HPP |
19 | 19 |
|
20 | | -#include <cstdint> |
21 | | -#include <filesystem> |
22 | | -#include <optional> |
23 | | -#include <string> |
24 | | -#include <vector> |
25 | | - |
26 | | -#include <vix/cli/build/BuildTask.hpp> |
| 20 | +#include <vix/engine/ObjectCache.hpp> |
27 | 21 |
|
28 | 22 | namespace vix::cli::build |
29 | 23 | { |
30 | | - namespace fs = std::filesystem; |
31 | | - |
32 | | - /** |
33 | | - * @brief Metadata describing one cached object file. |
34 | | - * |
35 | | - * ObjectCache stores compiled object files using a deterministic key. |
36 | | - * The key is derived from source content, dependency content, compiler |
37 | | - * command, target triple, build mode, and relevant configuration. |
38 | | - */ |
39 | | - struct ObjectCacheEntry |
40 | | - { |
41 | | - std::string key; ///< Stable object cache key |
42 | | - |
43 | | - fs::path source; ///< Source file used to produce the object |
44 | | - fs::path object; ///< Cached object file path |
45 | | - fs::path dependencyFile; ///< Cached dependency file path |
46 | | - |
47 | | - std::string commandHash; ///< Hash of the compiler command |
48 | | - std::string inputHash; ///< Hash of source and dependency inputs |
49 | | - std::string finalHash; ///< Combined object cache hash |
50 | | - |
51 | | - std::uint64_t objectSize{0}; ///< Cached object file size |
52 | | - std::uint64_t updatedUnixMs{0}; ///< Last update timestamp in milliseconds |
53 | | - |
54 | | - /** |
55 | | - * @brief Check whether this cache entry is usable. |
56 | | - * |
57 | | - * @return true if key and object are not empty |
58 | | - */ |
59 | | - bool valid() const; |
60 | | - }; |
61 | | - |
62 | | - /** |
63 | | - * @brief Result of resolving an object file from the cache. |
64 | | - */ |
65 | | - struct ObjectCacheResult |
66 | | - { |
67 | | - bool hit{false}; ///< true when cache entry was found and materialized |
68 | | - ObjectCacheEntry entry; ///< Cache entry metadata |
69 | | - fs::path materializedObject; ///< Object path copied/restored for the build |
70 | | - fs::path materializedDependencyFile; ///< Dependency file copied/restored for the build |
71 | | - }; |
72 | | - |
73 | | - /** |
74 | | - * @brief Cache for compiled object files. |
75 | | - * |
76 | | - * This cache is the key piece for fast incremental compilation. |
77 | | - * |
78 | | - * Instead of recompiling a .cpp file every time, Vix computes a stable |
79 | | - * key from: |
80 | | - * - source file content hash |
81 | | - * - dependency/header content hashes |
82 | | - * - compiler command hash |
83 | | - * - build configuration hash |
84 | | - * |
85 | | - * If the same key exists in the cache, Vix restores the .o and .d files |
86 | | - * directly and skips the compile task. |
87 | | - */ |
88 | | - class ObjectCache |
89 | | - { |
90 | | - public: |
91 | | - /** |
92 | | - * @brief Create an object cache bound to a project build directory. |
93 | | - * |
94 | | - * Local project object cache: |
95 | | - * <build-dir>/.vix/objects |
96 | | - * |
97 | | - * @param buildDir Project build directory |
98 | | - */ |
99 | | - explicit ObjectCache(fs::path buildDir); |
100 | | - |
101 | | - /** |
102 | | - * @brief Return the local object cache root. |
103 | | - * |
104 | | - * @return Object cache root path |
105 | | - */ |
106 | | - const fs::path &root() const; |
107 | | - |
108 | | - /** |
109 | | - * @brief Return the index file path. |
110 | | - * |
111 | | - * @return Object cache index path |
112 | | - */ |
113 | | - fs::path index_path() const; |
114 | | - |
115 | | - /** |
116 | | - * @brief Return the path where a cached object should live. |
117 | | - * |
118 | | - * @param key Object cache key |
119 | | - * @return Cached object path |
120 | | - */ |
121 | | - fs::path object_path_for_key(const std::string &key) const; |
122 | | - |
123 | | - /** |
124 | | - * @brief Return the path where a cached dependency file should live. |
125 | | - * |
126 | | - * @param key Object cache key |
127 | | - * @return Cached dependency file path |
128 | | - */ |
129 | | - fs::path dependency_path_for_key(const std::string &key) const; |
130 | | - |
131 | | - /** |
132 | | - * @brief Ensure the object cache directory exists. |
133 | | - * |
134 | | - * @return true on success |
135 | | - */ |
136 | | - bool ensure_layout() const; |
137 | | - |
138 | | - /** |
139 | | - * @brief Compute an input hash from a source file and dependency files. |
140 | | - * |
141 | | - * Existing files are hashed by content. Missing files are included as |
142 | | - * explicit missing markers so the hash remains deterministic. |
143 | | - * |
144 | | - * @param source Source file path |
145 | | - * @param dependencies Header/dependency file paths |
146 | | - * @return Stable hexadecimal hash |
147 | | - */ |
148 | | - static std::string compute_input_hash( |
149 | | - const fs::path &source, |
150 | | - const std::vector<fs::path> &dependencies); |
151 | | - |
152 | | - /** |
153 | | - * @brief Compute the final object cache key. |
154 | | - * |
155 | | - * @param source Source file path |
156 | | - * @param inputHash Hash of source and dependency contents |
157 | | - * @param commandHash Hash of the compile command |
158 | | - * @param buildFingerprint Global build/config fingerprint |
159 | | - * @return Stable object cache key |
160 | | - */ |
161 | | - static std::string compute_object_key( |
162 | | - const fs::path &source, |
163 | | - const std::string &inputHash, |
164 | | - const std::string &commandHash, |
165 | | - const std::string &buildFingerprint); |
166 | | - |
167 | | - /** |
168 | | - * @brief Check whether a cache entry exists for a key. |
169 | | - * |
170 | | - * @param key Object cache key |
171 | | - * @return true if object file exists |
172 | | - */ |
173 | | - bool exists(const std::string &key) const; |
174 | | - |
175 | | - /** |
176 | | - * @brief Read an object cache entry from its manifest. |
177 | | - * |
178 | | - * @param key Object cache key |
179 | | - * @return Cache entry, or std::nullopt if missing/invalid |
180 | | - */ |
181 | | - std::optional<ObjectCacheEntry> read_entry(const std::string &key) const; |
182 | | - |
183 | | - /** |
184 | | - * @brief Store an object and dependency file in cache. |
185 | | - * |
186 | | - * This should be called after a successful compile task. |
187 | | - * |
188 | | - * @param key Object cache key |
189 | | - * @param source Source file path |
190 | | - * @param objectPath Produced object file path |
191 | | - * @param dependencyFilePath Produced dependency file path |
192 | | - * @param inputHash Hash of source and dependency inputs |
193 | | - * @param commandHash Hash of compiler command |
194 | | - * @return true on success |
195 | | - */ |
196 | | - bool store( |
197 | | - const std::string &key, |
198 | | - const fs::path &source, |
199 | | - const fs::path &objectPath, |
200 | | - const fs::path &dependencyFilePath, |
201 | | - const std::string &inputHash, |
202 | | - const std::string &commandHash) const; |
203 | | - |
204 | | - /** |
205 | | - * @brief Restore a cached object and dependency file into build outputs. |
206 | | - * |
207 | | - * @param key Object cache key |
208 | | - * @param destinationObject Object destination path |
209 | | - * @param destinationDependencyFile Dependency file destination path |
210 | | - * @return Cache result |
211 | | - */ |
212 | | - ObjectCacheResult restore( |
213 | | - const std::string &key, |
214 | | - const fs::path &destinationObject, |
215 | | - const fs::path &destinationDependencyFile) const; |
216 | | - |
217 | | - /** |
218 | | - * @brief Try to restore a compile task output from cache. |
219 | | - * |
220 | | - * The task must have: |
221 | | - * - at least one input node/source path |
222 | | - * - at least one output node/object path |
223 | | - * - a valid commandHash |
224 | | - * |
225 | | - * @param task Compile task |
226 | | - * @param source Source file path |
227 | | - * @param dependencies Dependency/header file paths |
228 | | - * @param objectPath Destination object file path |
229 | | - * @param dependencyFilePath Destination dependency file path |
230 | | - * @param buildFingerprint Global build/config fingerprint |
231 | | - * @return Cache result |
232 | | - */ |
233 | | - ObjectCacheResult resolve_compile_task( |
234 | | - const BuildTask &task, |
235 | | - const fs::path &source, |
236 | | - const std::vector<fs::path> &dependencies, |
237 | | - const fs::path &objectPath, |
238 | | - const fs::path &dependencyFilePath, |
239 | | - const std::string &buildFingerprint) const; |
240 | | - |
241 | | - private: |
242 | | - fs::path root_; |
243 | | - }; |
| 24 | + using vix::engine::ObjectCache; |
| 25 | + using vix::engine::ObjectCacheEntry; |
| 26 | + using vix::engine::ObjectCacheResult; |
244 | 27 |
|
245 | 28 | } // namespace vix::cli::build |
246 | 29 |
|
|
0 commit comments