#pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace vls::modules { // Identity of one private module artifact. Compatibility covers frontend, // target ABI, stdlib and flags; context names the producer; inputs binds the // exact command, source and textual closure; kind distinguishes CMI/object. struct ArtifactKey { std::string compatibility, context, inputs, kind; auto operator<=>(const ArtifactKey &) const = default; [[nodiscard]] std::string identity() const; }; struct ArtifactEntry { ArtifactKey key; std::filesystem::path path; std::string sha256; }; // An immutable, completely published generation. Readers retain it while // eviction removes only generations no reader references. class ArtifactGeneration { public: [[nodiscard]] const std::string &id() const noexcept { return id_; } [[nodiscard]] const std::filesystem::path &root() const noexcept { return root_; } [[nodiscard]] std::optional find(const ArtifactKey &key) const; private: friend class ArtifactCache; ArtifactGeneration(std::string id, std::filesystem::path root, std::map entries) : id_(std::move(id)), root_(std::move(root)), entries_(std::move(entries)) {} std::string id_; std::filesystem::path root_; std::map entries_; }; // Private artifact cache. Publication is all-or-nothing and content addressed; // a failed publication leaves no generation behind. class ArtifactCache { public: explicit ArtifactCache(std::filesystem::path root, std::size_t retained = 2); ~ArtifactCache(); ArtifactCache(const ArtifactCache &) = delete; ArtifactCache &operator=(const ArtifactCache &) = delete; [[nodiscard]] std::expected, std::string> publish(const std::map &artifacts); [[nodiscard]] std::shared_ptr current() const; // Removes unreferenced generations beyond the retained limit. std::size_t collect(); [[nodiscard]] std::size_t generations() const; private: struct State; std::shared_ptr state_; }; // Produces one artifact per planned unit in dependency order. Any failure or // cancellation removes the staging directory and publishes nothing. using ArtifactWork = std::function( std::stop_token, const Build::ContextKey &, const std::filesystem::path &output)>; [[nodiscard]] std::expected, std::string> produce_module_artifacts(const ModulePlan &plan, ArtifactCache &cache, const std::filesystem::path &staging, ArtifactWork work, std::stop_token stop = std::stop_token{}); } // namespace vls::modules