Implement VoidBuildSystem v1 (Plans 01-19) with VoidLibrary integration
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s

This commit is contained in:
faumaray committed 2026-11-26 20:45:54 +03:00
1 parent 3cac890ce9
commit ab64147f9d
114 files changed
+23777 -1392

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <filesystem>
namespace Void::Build::Bridge {
// Executes a structured CMake-bridge request (`vbs bridge --request <json> --output <cmake>`)
// resolving/fetching/building requested dependencies (native, CMake, Meson, Conan) and emitting
// imported CMake targets with full transitive usage requirements and reentry-cycle detection (Plan
// 14).
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
execute_cmake_bridge(const std::filesystem::path &request_json_path,
const std::filesystem::path &output_cmake_path);
} // namespace Void::Build::Bridge
+60
View File
@@ -0,0 +1,60 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <chrono>
#include <filesystem>
#include <optional>
#include <string>
#include <vector>
namespace Void::Build::Config {
inline constexpr int kFrontendProtocolVersion = 1;
struct FrontendOptions {
std::filesystem::path project_root;
std::filesystem::path build_root;
std::filesystem::path sdk_include_dir;
std::filesystem::path sdk_library_path; // Optional prebuilt libVoidBuild_Sdk.a
std::filesystem::path sdk_source_dir; // Fallback source dir if sdk_library_path absent
std::vector<std::filesystem::path> extra_build_sources; // Explicit --build-source inputs
std::optional<std::filesystem::path> host_compiler;
std::chrono::milliseconds eval_timeout{std::chrono::seconds{30}};
};
struct CompiledDescriptor {
std::filesystem::path executable_path;
std::string seed_identity_hash;
std::vector<std::filesystem::path> config_sources;
std::vector<std::filesystem::path> discovered_headers;
bool recompiled{false};
};
// Discovers configuration C++ sources purely from filesystem membership (works without .git!):
// build.cpp, optional build.profiles.cpp, sorted build-support/**/*.cpp, and explicit extra
// sources.
[[nodiscard]] Void::Result::Result<std::vector<std::filesystem::path>, Void::Result::Error>
discover_config_sources(const std::filesystem::path &project_root,
const std::vector<std::filesystem::path> &extra_build_sources = {});
// Compiles (or reuses cached valid) host configuration descriptor executable against
// the fixed Void::Build SDK without invoking CMake or resolving project packages.
[[nodiscard]] Void::Result::Result<CompiledDescriptor, Void::Result::Error>
compile_descriptor(const FrontendOptions &options);
// Invokes the compiled descriptor in profile-discovery mode, returning declared Profiles
// (or default debug/release profiles if build.profiles.cpp is absent).
[[nodiscard]] Void::Result::Result<Profiles, Void::Result::Error>
discover_profiles(const CompiledDescriptor &descriptor, const FrontendOptions &options);
// Evaluates build(Project&) out-of-process for a single resolved ProfileContext using a
// dedicated bounded result file (logs on stdout/stderr cannot corrupt protocol results).
[[nodiscard]] Void::Result::Result<Graph::ProjectDescription, Void::Result::Error>
evaluate_project(const CompiledDescriptor &descriptor, const ProfileContext &context,
const FrontendOptions &options);
} // namespace Void::Build::Config
+97
View File
@@ -0,0 +1,97 @@
#pragma once
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstdint>
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::Editor {
struct EditorCommandEntry {
std::filesystem::path directory;
std::filesystem::path file;
std::filesystem::path output;
std::vector<std::string> arguments;
std::string target_name;
std::vector<std::filesystem::path> missing_generated_prerequisites;
};
enum class GenerationStatus { Valid, Stale, Invalid };
struct EditorGeneration {
std::string generation_id;
std::string profile_name;
std::string profile_identity;
GenerationStatus status{GenerationStatus::Valid};
std::string diagnostic;
std::filesystem::path compdb_path;
std::size_t entry_count{0};
std::vector<std::string> readiness_warnings;
};
struct SelectionState {
std::uint64_t ticket{0};
std::string selected_profile;
std::filesystem::path selected_build_root;
std::string selected_generation_id;
std::filesystem::path selected_compdb_path;
bool managed_root_alias_active{false};
std::string root_alias_warning;
};
struct PublishOptions {
std::filesystem::path project_root;
std::filesystem::path build_root;
bool update_selection{false}; // False for watchers (never steal selection!).
std::optional<std::uint64_t> reserved_ticket;
bool manage_project_root_alias{true};
};
// Projects all compile actions across ALL configured enabled targets in `graph`
// onto editable logical source paths and immutable generated views (Plan 09).
// Never string-replaces arbitrary flags or macro definitions.
[[nodiscard]] std::vector<EditorCommandEntry>
project_editor_commands(const Graph::BuildGraph &graph);
// Formats standard Clang JSONCompilationDatabase array (arguments/file/directory/output).
[[nodiscard]] std::string
format_compile_commands_json(const std::vector<EditorCommandEntry> &entries);
// Reserves a monotonically increasing project-level selection ticket under advisory lock.
// Single-profile builds reserve on acceptance; manual `vbs compdb use` reserves a newer ticket.
[[nodiscard]] Void::Result::Result<std::uint64_t, Void::Result::Error>
reserve_selection_ticket(const std::filesystem::path &project_root,
const std::filesystem::path &build_root, std::string_view profile_name);
// Publishes an immutable per-profile editor generation atomically. Updates active build-root
// and managed project-root pointers ONLY if `options.update_selection` is true and no newer
// ticket has superseded `options.reserved_ticket`. Never overwrites an unrelated user-owned file.
[[nodiscard]] Void::Result::Result<EditorGeneration, Void::Result::Error>
publish_profile_compdb(const Graph::BuildGraph &graph, const PublishOptions &options);
// Marks a profile's editor metadata as stale/invalid while retaining the last valid
// compile_commands.json intact and clearly identifiable as stale.
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
mark_profile_stale(const std::filesystem::path &build_root, std::string_view profile_name,
GenerationStatus status, std::string_view diagnostic);
// Explicitly switches editor selection to an already-published profile (`vbs compdb use`).
[[nodiscard]] Void::Result::Result<SelectionState, Void::Result::Error>
select_editor_profile(const std::filesystem::path &project_root,
const std::filesystem::path &build_root, std::string_view profile_name,
bool manage_project_root_alias = true);
// Reads authoritative selection state and repairs stale filesystem pointers after crashes.
[[nodiscard]] Void::Result::Result<std::optional<SelectionState>, Void::Result::Error>
read_selection_state(const std::filesystem::path &project_root);
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
recover_editor_pointers(const std::filesystem::path &project_root);
} // namespace Void::Build::Editor
@@ -0,0 +1,73 @@
#pragma once
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <chrono>
#include <cstddef>
#include <filesystem>
#include <functional>
#include <stop_token>
#include <string>
#include <vector>
namespace Void::Build::Execution {
struct ActionExecutionResult {
std::string action_id;
std::string target_name;
bool succeeded{false};
bool from_cache{false};
bool cancelled{false};
bool timed_out{false};
int exit_code{-1};
int term_signal{0};
std::string stdout_data;
std::string stderr_data;
std::string error_message;
std::chrono::milliseconds elapsed{0};
};
struct ExecutionEvent {
enum class Kind { ActionStarted, ActionCached, ActionSucceeded, ActionFailed };
Kind kind{Kind::ActionStarted};
std::string action_id;
std::string target_name;
std::size_t completed{0};
std::size_t total{0};
std::string message;
};
struct ExecutionOptions {
std::size_t jobs{0}; // 0 = hardware_concurrency (clamped >= 1)
bool fail_fast{true};
bool use_cache{true};
std::vector<std::string> selected_targets;
std::chrono::milliseconds action_timeout{0};
std::function<void(const ExecutionEvent &)> on_event;
};
struct ExecutionReport {
bool succeeded{false};
bool cancelled{false};
std::size_t total_selected{0};
std::size_t executed_count{0};
std::size_t cached_count{0};
std::size_t failed_count{0};
std::vector<ActionExecutionResult> results;
std::string diagnostic;
};
// Parses a GCC/Clang GNU Make depfile (.d) into its list of dependency file paths.
[[nodiscard]] Void::Result::Result<std::vector<std::filesystem::path>, Void::Result::Error>
parse_depfile(const std::filesystem::path &depfile_path);
// Executes the selected action closure of `graph` with bounded parallelism,
// per-profile serialization, immutable CAS verification, depfile tracking, and cancellation.
[[nodiscard]] Void::Result::Result<ExecutionReport, Void::Result::Error>
execute_graph(const Graph::BuildGraph &graph, State::StateStore &state,
const ExecutionOptions &options = {}, std::stop_token stop = {});
} // namespace Void::Build::Execution
+146
View File
@@ -0,0 +1,146 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Build/Snapshot/Snapshot.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstddef>
#include <filesystem>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
namespace Void::Build::Graph {
struct ProjectDescription {
int schema_version{1};
ProfileContext profile;
std::vector<TargetRecord> targets;
std::vector<DependencyRecord> dependencies;
std::vector<std::string> dependency_files;
std::vector<InstallRule> install_rules;
[[nodiscard]] static Void::Result::Result<ProjectDescription, Void::Result::Error>
from_json(std::string_view json_text);
};
// Typed consumer interface supplied by a foreign/native package provider (Plan 13).
struct ImportedTargetInterface {
std::string dependency_name;
std::string target_name;
std::vector<std::pair<std::filesystem::path, bool>> include_dirs; // (abs path, is_system)
std::vector<std::string> defines;
std::vector<std::string> compile_options;
std::vector<std::string> link_options;
std::vector<std::filesystem::path> static_libraries;
std::vector<std::filesystem::path> shared_libraries;
std::vector<std::filesystem::path> runtime_files;
std::vector<std::filesystem::path> generated_prerequisites;
};
enum class ActionKind {
Compile,
PrecompiledHeader,
HeaderUnit,
ModuleScan,
ModuleBmi,
Archive,
Link,
Custom
};
struct ActionNode {
std::string id;
ActionKind kind{ActionKind::Compile};
std::string target_name;
std::filesystem::path executable;
std::vector<std::string> arguments;
std::map<std::string, std::string, std::less<>> environment;
std::filesystem::path working_directory;
std::optional<std::filesystem::path> response_file;
std::string response_file_content;
std::vector<std::filesystem::path> declared_inputs;
std::vector<std::filesystem::path> declared_outputs;
std::optional<std::filesystem::path> depfile;
// Structured metadata for Editor Compilation Database projection (Plan 09) and lookup guards.
std::filesystem::path logical_source_file;
std::filesystem::path physical_source_file;
std::filesystem::path logical_output_file;
std::filesystem::path physical_output_file;
std::vector<std::pair<std::filesystem::path, bool>> logical_include_dirs;
std::vector<std::pair<std::filesystem::path, bool>> physical_include_dirs;
std::vector<std::string> defines;
std::vector<std::string> compile_options;
CxxStandard cxx_standard{CxxStandard::Default};
LtoMode lto{LtoMode::None};
std::vector<Sanitizer> sanitizers;
bool position_independent{false};
std::optional<std::filesystem::path> precompiled_header;
std::vector<std::string> dependencies; // Action IDs that must precede this node.
bool nondeterministic{false};
bool cacheable{true};
std::string action_key;
};
struct ResolvedTargetSummary {
std::string name;
TargetKind kind{TargetKind::Executable};
bool enabled{true};
std::vector<std::filesystem::path> expanded_sources;
std::vector<std::filesystem::path> primary_outputs;
std::vector<std::filesystem::path> runtime_shared_libraries;
std::vector<std::string> action_ids;
};
struct BuildGraph {
ProfileContext profile;
Toolchain::ToolchainCapabilities toolchain;
std::string profile_identity;
std::filesystem::path project_root;
std::filesystem::path profile_build_dir;
std::filesystem::path snapshot_materialized_root;
std::string snapshot_id;
std::vector<ResolvedTargetSummary> targets;
std::vector<ActionNode> actions; // Topologically ordered!
std::map<std::string, std::size_t, std::less<>> action_index_by_id;
// Returns the exact ordered action subset required to build `selected_targets`
// (empty = all enabled targets).
[[nodiscard]] Void::Result::Result<std::vector<std::size_t>, Void::Result::Error>
select_action_closure(const std::vector<std::string> &selected_targets) const;
};
struct GraphLowerOptions {
std::filesystem::path project_root;
std::filesystem::path build_root;
const Snapshot::InputSnapshot *snapshot{nullptr};
std::map<std::string, ImportedTargetInterface, std::less<>> imported_targets;
std::size_t response_file_threshold{32768};
};
// Matches a POSIX-style glob pattern (*, **, ?) against a relative posix path.
[[nodiscard]] bool match_glob(std::string_view pattern, std::string_view path) noexcept;
// Deterministically expands a glob pattern under project_root, excluding build outputs,
// VCS metadata, secrets, and configuration sources.
[[nodiscard]] Void::Result::Result<std::vector<std::filesystem::path>, Void::Result::Error>
expand_glob(const std::filesystem::path &project_root, std::string_view pattern);
// Validates target graph, resolves public/private/interface compile & link usage
// requirements, lowers all targets to topologically ordered actions, and rejects
// cycles, output collisions, and source/output overlaps.
[[nodiscard]] Void::Result::Result<BuildGraph, Void::Result::Error>
lower_project_graph(const ProjectDescription &description,
const Toolchain::ToolchainCapabilities &toolchain,
const GraphLowerOptions &options);
} // namespace Void::Build::Graph
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <filesystem>
#include <optional>
#include <string>
#include <vector>
namespace Void::Build::Install {
struct InstallOptions {
std::string package_name;
std::string package_version{"0.1.0"};
std::filesystem::path prefix;
std::optional<std::string> component; // Empty = install all components
bool export_cmake_config{true};
bool export_native_metadata{true};
};
struct InstallReport {
std::filesystem::path prefix;
std::filesystem::path manifest_path;
std::vector<std::filesystem::path> installed_files;
std::optional<std::filesystem::path> cmake_config_file;
std::optional<std::filesystem::path> native_package_file;
};
// Installs declared targets, files, headers, and relocatable native + CMake export
// metadata into `options.prefix` via managed staging and an ownership manifest (Plan 15).
// Rejects path traversal, destination collisions, and build-tree path leaks.
[[nodiscard]] Void::Result::Result<InstallReport, Void::Result::Error>
install_project(const Graph::ProjectDescription &description, const Graph::BuildGraph &graph,
const InstallOptions &options);
// Safely removes ONLY files owned by VBS in `<prefix>/.vbs-install-manifest.json`,
// preserving all unrelated user files in the prefix!
[[nodiscard]] Void::Result::Result<std::size_t, Void::Result::Error>
uninstall_prefix(const std::filesystem::path &prefix);
} // namespace Void::Build::Install
@@ -0,0 +1,80 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <filesystem>
#include <map>
#include <string>
#include <vector>
namespace Void::Build::Modules {
struct ModuleScanUnit {
std::filesystem::path source_file;
std::vector<std::string> provides; // Logical module/partition names provided by this TU.
std::vector<std::string>
required_modules; // Logical module/partition names imported by this TU.
bool is_interface{false};
};
struct CollatedModuleNode {
std::filesystem::path source_file;
std::vector<std::string> provides;
std::vector<std::string> required_modules;
std::filesystem::path bmi_output_path;
std::filesystem::path module_mapper_path; // For GCC -fmodule-mapper
std::vector<std::pair<std::string, std::filesystem::path>> imported_bmis;
};
struct CollatedModulePlan {
// Topologically sorted: every provider precedes all of its importers.
std::vector<CollatedModuleNode> ordered_units;
std::map<std::string, std::filesystem::path, std::less<>> module_to_bmi;
};
// Parses official P1689r5 JSON output emitted by GCC (`-fdeps-format=p1689r5`) or
// `clang-scan-deps`.
[[nodiscard]] Void::Result::Result<ModuleScanUnit, Void::Result::Error>
parse_p1689_json(std::string_view json_text, const std::filesystem::path &source_file);
// Scans a C++ translation unit using the real target compiler's P1689 scanner.
[[nodiscard]] Void::Result::Result<ModuleScanUnit, Void::Result::Error>
scan_translation_unit(const Toolchain::ToolchainCapabilities &toolchain,
const std::filesystem::path &source_file,
const std::filesystem::path &scratch_dir,
const std::vector<std::pair<std::filesystem::path, bool>> &include_dirs,
const std::vector<std::string> &defines,
const std::vector<std::string> &compile_options, CxxStandard standard);
// Collates scanned module units into a cycle-free, duplicate-free, missing-import-checked
// topological build plan with profile/compiler-isolated BMI paths and GCC mapper files (Plan 08).
[[nodiscard]] Void::Result::Result<CollatedModulePlan, Void::Result::Error>
collate_modules(const std::vector<ModuleScanUnit> &units, const std::filesystem::path &bmi_root,
const std::string &context_isolation_key, std::string_view bmi_extension = ".gcm");
// Compiles an explicitly declared header unit into an isolated BMI/PCM (Plan 08).
[[nodiscard]] Void::Result::Result<Toolchain::LoweredCommand, Void::Result::Error>
lower_header_unit_command(const Toolchain::ToolchainCapabilities &toolchain,
const std::filesystem::path &header_path,
const std::filesystem::path &bmi_output,
const std::vector<std::pair<std::filesystem::path, bool>> &include_dirs,
const std::vector<std::string> &defines,
const std::vector<std::string> &compile_options, CxxStandard standard);
struct UnityBatchResult {
std::vector<std::filesystem::path> generated_unity_files;
std::vector<std::filesystem::path>
standalone_files; // Modules & per-file-option files excluded!
};
// Generates deterministic unity batches excluding module TUs and per-file-override TUs (Plan 08).
[[nodiscard]] Void::Result::Result<UnityBatchResult, Void::Result::Error>
generate_unity_batches(const std::string &target_name,
const std::vector<std::filesystem::path> &sources,
const std::vector<std::filesystem::path> &excluded_sources,
std::size_t batch_size, const std::filesystem::path &unity_dir);
} // namespace Void::Build::Modules
+53
View File
@@ -0,0 +1,53 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <string>
#include <vector>
namespace Void::Build::Package {
struct ArchiveLimits {
std::size_t max_entries{10000};
std::uint64_t max_file_bytes{512ULL * 1024ULL * 1024ULL};
std::uint64_t max_total_bytes{2ULL * 1024ULL * 1024ULL * 1024ULL};
};
struct ArchiveExtractionStats {
std::size_t entries{0};
std::uint64_t total_bytes{0};
std::vector<std::filesystem::path> extracted_files;
};
struct ArchiveEntrySpec {
std::string archive_path; // Relative POSIX path inside archive.
std::filesystem::path source_file;
std::uint32_t mode{0644};
};
// Creates a byte-deterministic USTAR/PAX tar archive (canonical mtime/uid/gid, sorted entries)
// and returns its SHA-256 hex digest (VL-006).
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
create_deterministic_tar(const std::filesystem::path &output_tar,
std::vector<ArchiveEntrySpec> entries,
std::int64_t reproducibility_epoch = 0);
// Packages a VBS project's source tree cleanly (retaining build.cpp, optional build.profiles.cpp,
// build-support/**, and declared sources/headers while excluding .git, build/, .vbs/, secrets).
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
create_source_package(const std::filesystem::path &project_root,
const std::filesystem::path &output_tar,
std::int64_t reproducibility_epoch = 0);
// Extracts a tar archive with strict security checks:
// rejects absolute paths, '..' traversal, symlinks/hardlinks/special files, duplicate paths,
// and count/size quota overflows. Stages privately and publishes atomically only on full success.
[[nodiscard]] Void::Result::Result<ArchiveExtractionStats, Void::Result::Error>
extract_safe_tar(const std::filesystem::path &tar_path,
const std::filesystem::path &destination_dir, const ArchiveLimits &limits = {});
} // namespace Void::Build::Package
+67
View File
@@ -0,0 +1,67 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Build/Package/Archive.hpp>
#include <Void/Build/Package/Solver.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
namespace Void::Build::Package {
struct BinaryCompatibilityKey {
std::string os;
std::string architecture;
std::string compiler_family;
std::string compiler_abi;
std::string stdlib_abi;
std::string linkage; // "static" or "shared"
std::string cpu_features;
std::string sanitizers_key;
std::string lto_mode;
std::string dependency_closure_hash;
[[nodiscard]] std::string compute_key_hash() const;
[[nodiscard]] bool matches(const BinaryVariantMeta &candidate) const noexcept;
};
struct FetchOptions {
std::filesystem::path cache_dir;
std::filesystem::path project_root;
bool offline{false};
ArchiveLimits archive_limits;
};
struct MaterializedSource {
std::string alias;
std::filesystem::path source_dir;
std::string content_identity_hash;
bool from_cache{false};
};
// Redacts credentials from URLs and bearer headers before logging/diagnostics.
[[nodiscard]] std::string redact_secrets(std::string_view text);
// Computes strict binary compatibility key from profile, toolchain, linkage, and dep closure.
[[nodiscard]] BinaryCompatibilityKey
make_binary_compatibility_key(const ProfileContext &profile,
const Toolchain::ToolchainCapabilities &toolchain,
std::string_view linkage, std::string_view dependency_closure_hash);
// Selects an exact compatible binary variant, returning nullopt on any ABI/CPU/sanitizer/LTO
// or dependency-closure mismatch (never optimistically selects incompatible binaries!).
[[nodiscard]] std::optional<BinaryVariantMeta>
select_compatible_binary(const BinaryCompatibilityKey &key,
const std::vector<BinaryVariantMeta> &available);
// Acquires and verifies a source dependency (local path, exact pinned Git SHA, or
// SHA-256 verified archive) into managed storage without ever modifying external checkouts.
[[nodiscard]] Void::Result::Result<MaterializedSource, Void::Result::Error>
materialize_dependency_source(const DependencyRecord &dep, const FetchOptions &options);
} // namespace Void::Build::Package
+93
View File
@@ -0,0 +1,93 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Build/Package/Solver.hpp>
#include <Void/Build/Package/Toml.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <filesystem>
#include <map>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::Package {
inline constexpr int kLockfileSchemaVersion = 1;
struct LockedSourceEntry {
std::string alias;
std::string source_kind; // "git", "package", "path", "archive", "conan"
std::string registry_authority;
std::string package_name;
std::string version;
std::string location;
std::string revision;
std::string sha256;
std::string builder;
std::vector<std::string> features;
bool build_dependency{false};
};
struct LockContextRecord {
std::string context_key; // e.g. "debug:gcc:Linux:x86_64:target"
std::string profile_name;
std::string compiler;
std::string os;
std::string architecture;
std::string machine_role; // "target" or "build"
std::string declaration_fingerprint;
std::vector<LockedSourceEntry> entries;
};
struct LockfileDocument {
int schema_version{kLockfileSchemaVersion};
std::string revision_hash; // SHA-256 of canonical contexts payload.
std::map<std::string, LockContextRecord, std::less<>> contexts;
};
// Immutable lock payload pinned at the start of a build so concurrent updates never mix revisions.
struct PinnedLock {
std::string revision_hash;
std::string raw_json;
LockfileDocument document;
};
// Computes canonical declaration fingerprint for a profile/role context (used to detect
// incompatible manifest/option changes before running any build action!).
[[nodiscard]] std::string
compute_declaration_fingerprint(const ProfileContext &profile, std::string_view machine_role,
const std::vector<NormalizedDependency> &declarations);
[[nodiscard]] std::string make_lock_context_key(const ProfileContext &profile,
std::string_view machine_role);
// Serializes and parses vbs.lock deterministically (never stores credentials!).
[[nodiscard]] std::string serialize_lockfile(const LockfileDocument &doc);
[[nodiscard]] Void::Result::Result<LockfileDocument, Void::Result::Error>
parse_lockfile(std::string_view json_text);
// Reads and pins one immutable lockfile revision from disk (returns nullopt if absent).
[[nodiscard]] Void::Result::Result<std::optional<PinnedLock>, Void::Result::Error>
load_pinned_lock(const std::filesystem::path &lock_path);
// Validates an existing pinned lock against current declarations for `context_key`.
// Fails explicitly if declarations/options/platform facts are incompatible (requires
// resolve/update).
[[nodiscard]] Void::Result::Result<const LockContextRecord *, Void::Result::Error>
validate_locked_context(const LockfileDocument &doc, std::string_view context_key,
std::string_view expected_declaration_fingerprint);
// Atomic CAS lockfile publication (D-025 / Plan 11):
// Acquires short project mutex (`vbs.lock.mutex`), compares on-disk revision hash against
// `expected_base_revision` (empty if creating a new lock), merges `updated_context` without
// discarding other profiles' contexts, and atomically replaces `vbs.lock`.
// Fails with SystemErrorCode::busy on a competing revision conflict so caller can re-resolve/retry!
[[nodiscard]] Void::Result::Result<PinnedLock, Void::Result::Error>
publish_lock_context_cas(const std::filesystem::path &lock_path,
std::string_view expected_base_revision,
const LockContextRecord &updated_context, bool locked_mode = false);
} // namespace Void::Build::Package
@@ -0,0 +1,51 @@
#pragma once
#include <Void/Build/Package/Solver.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::Package {
struct RegistryAuth {
std::string bearer_token; // Runtime-only; never written to locks or logs.
};
struct PublishOptions {
std::string registry_url;
std::string package_name;
std::string version;
std::filesystem::path archive_path;
std::string description;
bool is_private{false};
RegistryAuth auth;
};
struct PublishReceipt {
std::string sha256;
bool already_published{false};
};
// Queries GET /api/v1/packages/<name> on a VBS registry and parses all release records
// into Package::ReleaseRecord entries ready for PackageIndex + PubGrub solving.
[[nodiscard]] Void::Result::Result<std::vector<ReleaseRecord>, Void::Result::Error>
fetch_package_releases(std::string_view registry_url, std::string_view package_name,
const RegistryAuth &auth = {});
// Downloads GET /api/v1/packages/<name>/<version>/download, verifies SHA-256 against
// `expected_sha256` before atomic publication to `dest_file`.
[[nodiscard]] Void::Result::Result<std::filesystem::path, Void::Result::Error>
download_release_archive(std::string_view registry_url, std::string_view package_name,
std::string_view version, std::string_view expected_sha256,
const std::filesystem::path &dest_file, const RegistryAuth &auth = {});
// Publishes a verified deterministic archive via PUT /api/v1/packages/<name>/<version>.
[[nodiscard]] Void::Result::Result<PublishReceipt, Void::Result::Error>
publish_package_archive(const PublishOptions &options);
} // namespace Void::Build::Package
+97
View File
@@ -0,0 +1,97 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <Void/Text/Semver.hpp>
#include <compare>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <vector>
namespace Void::Build::Package {
// Registry authority is an explicit part of package identity to prevent cross-registry
// substitution.
struct PackageId {
std::string registry_authority;
std::string name;
auto operator<=>(const PackageId &) const = default;
[[nodiscard]] std::string format() const;
};
struct DependencyConstraint {
PackageId target;
std::string range_expr;
std::vector<std::string> required_features;
std::string origin_label;
};
struct BinaryVariantMeta {
std::string variant_id;
std::string os;
std::string architecture;
std::string compiler_family;
std::string compiler_abi;
std::string stdlib_abi;
std::string linkage;
std::string cpu_features;
std::string sanitizers_key;
std::string lto_mode;
std::string dependency_closure_hash;
std::string sha256;
std::string download_url;
};
struct ReleaseRecord {
PackageId id;
Void::Semver::Version version;
bool yanked{false};
std::string source_sha256;
std::string source_url;
std::vector<DependencyConstraint> dependencies;
std::vector<BinaryVariantMeta> binaries;
};
class PackageIndex {
public:
void add_release(ReleaseRecord release);
[[nodiscard]] std::vector<ReleaseRecord> releases_for(const PackageId &id) const;
private:
std::map<PackageId, std::vector<ReleaseRecord>> releases_;
};
struct SolvedPackage {
PackageId id;
Void::Semver::Version version;
std::string source_sha256;
std::string source_url;
std::set<std::string> enabled_features;
std::vector<PackageId> dependencies;
std::vector<BinaryVariantMeta> binaries;
};
struct SolveResult {
std::map<PackageId, SolvedPackage> packages; // Deterministically ordered.
};
struct SolveOptions {
// Already-pinned compatible versions from an existing lockfile (never silently upgraded!).
std::map<PackageId, Void::Semver::Version> pinned_versions;
bool allow_yanked_if_pinned{true};
std::size_t max_steps{50000};
};
// Deterministic PubGrub-style SemVer dependency solver (Plan 11):
// - One version per PackageId per resolution context
// - Prefers compatible pinned versions; otherwise picks highest non-yanked matching version
// - Produces human-readable incompatibility chains on unsatisfiable graphs.
[[nodiscard]] Void::Result::Result<SolveResult, Void::Result::Error>
solve_dependencies(const std::vector<DependencyConstraint> &root_constraints,
const PackageIndex &index, const SolveOptions &options = {});
} // namespace Void::Build::Package
+97
View File
@@ -0,0 +1,97 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <variant>
#include <vector>
namespace Void::Build::Package {
struct SourceOrigin {
std::string file;
std::size_t line{0};
std::size_t column{0};
[[nodiscard]] std::string format() const;
};
struct TomlValue;
using TomlArray = std::vector<TomlValue>;
using TomlTable = std::map<std::string, TomlValue, std::less<>>;
// TOML 1.0 value with source origin metadata (VL-002 adapter; swappable when Void::Data::Toml
// lands).
struct TomlValue {
using Storage = std::variant<std::string, bool, std::int64_t, double,
std::shared_ptr<TomlArray>, std::shared_ptr<TomlTable>>;
Storage value;
SourceOrigin origin;
[[nodiscard]] bool is_string() const noexcept {
return std::holds_alternative<std::string>(value);
}
[[nodiscard]] bool is_bool() const noexcept { return std::holds_alternative<bool>(value); }
[[nodiscard]] bool is_int() const noexcept {
return std::holds_alternative<std::int64_t>(value);
}
[[nodiscard]] bool is_double() const noexcept { return std::holds_alternative<double>(value); }
[[nodiscard]] bool is_array() const noexcept {
return std::holds_alternative<std::shared_ptr<TomlArray>>(value);
}
[[nodiscard]] bool is_table() const noexcept {
return std::holds_alternative<std::shared_ptr<TomlTable>>(value);
}
[[nodiscard]] const std::string &as_string() const { return std::get<std::string>(value); }
[[nodiscard]] bool as_bool() const { return std::get<bool>(value); }
[[nodiscard]] std::int64_t as_int() const { return std::get<std::int64_t>(value); }
[[nodiscard]] double as_double() const { return std::get<double>(value); }
[[nodiscard]] const TomlArray &as_array() const {
return *std::get<std::shared_ptr<TomlArray>>(value);
}
[[nodiscard]] const TomlTable &as_table() const {
return *std::get<std::shared_ptr<TomlTable>>(value);
}
[[nodiscard]] TomlTable &as_table_mut() { return *std::get<std::shared_ptr<TomlTable>>(value); }
[[nodiscard]] TomlArray &as_array_mut() { return *std::get<std::shared_ptr<TomlArray>>(value); }
static TomlValue make_table(SourceOrigin origin = {});
static TomlValue make_array(SourceOrigin origin = {});
};
// Parses TOML 1.0 text with exact file:line:col diagnostics and duplicate-key rejection.
[[nodiscard]] Void::Result::Result<TomlTable, Void::Result::Error>
parse_toml(std::string_view text, std::string_view source_name = "<memory>");
[[nodiscard]] Void::Result::Result<TomlTable, Void::Result::Error>
parse_toml_file(const std::filesystem::path &path);
// Canonical deterministic TOML 1.0 serializer.
[[nodiscard]] std::string serialize_toml(const TomlTable &table);
struct NormalizedDependency {
DependencyRecord record;
SourceOrigin origin;
};
// Loads [dependencies.<alias>] tables from a TOML manifest into the exact same
// DependencyRecord model used by C++ project.dependency(...) declarations (Plan 11).
[[nodiscard]] Void::Result::Result<std::vector<NormalizedDependency>, Void::Result::Error>
load_dependencies_toml(const std::filesystem::path &toml_path);
// Merges C++ inline declarations and TOML-loaded declarations. Rejects contradictory
// duplicate aliases/sources/options with both origins clearly diagnosed.
[[nodiscard]] Void::Result::Result<std::vector<NormalizedDependency>, Void::Result::Error>
merge_dependencies(const std::vector<DependencyRecord> &cpp_deps,
const std::vector<NormalizedDependency> &toml_deps);
} // namespace Void::Build::Package
+94
View File
@@ -0,0 +1,94 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstdint>
#include <filesystem>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::Platform {
enum class LockMode { Shared, Exclusive };
// RAII advisory flock lock (VL-010).
class FileLock {
public:
FileLock() noexcept = default;
~FileLock() noexcept;
FileLock(const FileLock &) = delete;
FileLock &operator=(const FileLock &) = delete;
FileLock(FileLock &&other) noexcept;
FileLock &operator=(FileLock &&other) noexcept;
[[nodiscard]] static Void::Result::Result<FileLock, Void::Result::Error>
acquire(const std::filesystem::path &lock_path, LockMode mode = LockMode::Exclusive,
bool non_blocking = false);
[[nodiscard]] bool valid() const noexcept { return fd_ >= 0; }
void release() noexcept;
private:
explicit FileLock(int fd) noexcept : fd_{fd} {}
int fd_{-1};
};
struct FileMetadata {
bool exists{false};
bool is_regular{false};
bool is_directory{false};
bool is_symlink{false};
std::uint64_t dev{0};
std::uint64_t ino{0};
std::uint64_t size{0};
std::uint64_t nlink{0};
std::uint32_t mode{0};
std::int64_t mtime_sec{0};
std::int64_t mtime_nsec{0};
std::string symlink_target;
};
// lstat wrapper that distinguishes ENOENT (exists=false) from permission/IO errors.
[[nodiscard]] Void::Result::Result<FileMetadata, Void::Result::Error>
stat_lstat(const std::filesystem::path &path);
// Private isolated file copy: tries Linux FICLONE reflink, falls back to byte copy.
// NEVER creates hardlinks. Guarantees distinct inode and nlink == 1 on destination.
[[nodiscard]] Void::Result::Result<bool, Void::Result::Error>
copy_isolated(const std::filesystem::path &src, const std::filesystem::path &dst,
std::optional<std::uint32_t> mode_override = std::nullopt);
// Canonicalizes mtime/atime via utimensat(..., AT_SYMLINK_NOFOLLOW).
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
set_canonical_mtime(const std::filesystem::path &path, std::int64_t epoch_seconds);
// Durable atomic file replace (wraps Void::FileSystem::replace_file).
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
atomic_write_file(const std::filesystem::path &path, std::string_view content,
bool durable_sync = true, unsigned mode = 0644);
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
atomic_write_bytes(const std::filesystem::path &path, std::span<const std::byte> bytes,
bool durable_sync = true, unsigned mode = 0644);
// Atomically replaces symlink at `link_path` pointing to `target` + parent fsync.
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
atomic_swap_symlink(const std::filesystem::path &link_path, const std::filesystem::path &target);
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
fsync_directory(const std::filesystem::path &dir_path);
// Validates that `candidate` stays inside `root` (or one of `allowed_external_roots`)
// without symlink loops or directory traversal escapes.
[[nodiscard]] Void::Result::Result<std::filesystem::path, Void::Result::Error>
resolve_confined_path(const std::filesystem::path &root, const std::filesystem::path &candidate,
const std::vector<std::filesystem::path> &allowed_external_roots = {});
[[nodiscard]] bool path_is_within(const std::filesystem::path &root,
const std::filesystem::path &path);
} // namespace Void::Build::Platform
@@ -0,0 +1,79 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <chrono>
#include <cstddef>
#include <filesystem>
#include <functional>
#include <map>
#include <optional>
#include <stop_token>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::Platform {
enum class EnvPolicyMode { Inherit, Allowlist, ExplicitOnly };
struct ProcessEnvironment {
EnvPolicyMode mode{EnvPolicyMode::Inherit};
std::vector<std::string> allowlist;
std::map<std::string, std::string, std::less<>> set_vars;
std::vector<std::string> unset_keys;
};
struct ProcessRequest {
std::filesystem::path executable;
std::vector<std::string> arguments; // Does NOT include argv[0]; executable is prepended.
std::optional<std::filesystem::path> working_directory;
ProcessEnvironment environment;
std::string stdin_data;
std::size_t max_stdout_bytes{8ULL * 1024ULL * 1024ULL};
std::size_t max_stderr_bytes{8ULL * 1024ULL * 1024ULL};
bool fail_on_overflow{false};
std::chrono::milliseconds timeout{0}; // 0 = no timeout
std::chrono::milliseconds kill_grace{200};
bool search_path{true};
std::function<void(std::string_view)> on_stdout_chunk;
std::function<void(std::string_view)> on_stderr_chunk;
};
struct ProcessResult {
bool exec_failed{false};
int exec_errno{0};
std::string exec_error_message;
bool exited{false};
int exit_code{-1};
int term_signal{0};
bool timed_out{false};
bool cancelled{false};
bool stdout_truncated{false};
bool stderr_truncated{false};
bool overflowed{false};
std::string stdout_data;
std::string stderr_data;
[[nodiscard]] bool succeeded() const noexcept {
return !exec_failed && exited && exit_code == 0 && !timed_out && !cancelled && !overflowed;
}
};
// Resolves an executable path cleanly using PATH (without invoking a shell).
[[nodiscard]] std::optional<std::filesystem::path>
resolve_executable(const std::filesystem::path &executable,
std::optional<std::string_view> path_override = std::nullopt);
// Executes a subprocess in its own process group with Linux descendant supervision (VL-001):
// - Direct fork/execve (never shell concatenation)
// - CLOEXEC error pipe distinguishing exec failure from program exit code 127
// - Non-blocking poll-driven stdout/stderr drains with overflow bounds
// - On timeout/cancellation/overflow, terminates the ENTIRE process group (-pgid)
// via SIGTERM -> grace -> SIGKILL -> poll until ESRCH so stubborn grandchildren
// whose group leader already exited cannot outlive the supervisor call.
[[nodiscard]] Void::Result::Result<ProcessResult, Void::Result::Error>
run_supervised(const ProcessRequest &request, std::stop_token stop = {});
} // namespace Void::Build::Platform
+52
View File
@@ -0,0 +1,52 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/Package/Fetch.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <filesystem>
#include <map>
#include <optional>
#include <stop_token>
#include <string>
#include <vector>
namespace Void::Build::Provider {
enum class ProviderMode { FullBuild, MetadataOnly };
struct ProviderRequest {
DependencyRecord dependency;
Package::MaterializedSource source;
ProfileContext profile;
Toolchain::ToolchainCapabilities toolchain;
std::filesystem::path provider_build_root; // Isolated per source/profile/hash
ProviderMode mode{ProviderMode::FullBuild};
// Explicit typed interface overrides for foreign projects with incomplete metadata.
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> explicit_overrides;
};
struct ProviderExport {
std::string dependency_name;
std::string builder;
std::string input_identity_hash;
bool from_cache{false};
bool stale_needs_build{false};
std::string stale_diagnostic;
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> targets;
};
// Computes complete provider input identity (source content hash, builder, options,
// toolchain identity, profile options) so timestamp-preserved edits always invalidate!
[[nodiscard]] std::string compute_provider_input_hash(const ProviderRequest &request);
// Runs or reads cached CMake / Meson / Conan2 foreign provider metadata (Plan 13).
// In MetadataOnly mode: strictly reads ONLY validated cached provider-export.json;
// NEVER invokes cmake, meson, or conan! Returns stale_needs_build=true on mismatch/miss.
[[nodiscard]] Void::Result::Result<ProviderExport, Void::Result::Error>
resolve_foreign_provider(const ProviderRequest &request, std::stop_token stop = {});
} // namespace Void::Build::Provider
@@ -0,0 +1,35 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstddef>
#include <filesystem>
#include <string>
#include <vector>
namespace Void::Build::SelfHost {
struct DiscoveredTestCase {
std::string suite_name;
std::string function_name;
std::filesystem::path source_file;
std::size_t line_number{0};
};
struct GeneratedRegistration {
std::filesystem::path generated_cpp;
std::vector<DiscoveredTestCase> cases;
};
// Native non-CMake Void::Testing scanner & registration generator (Plan 18 / VL-009).
// Uses path-hashed output filenames so equal basenames in different subdirectories
// never collide, preserving exact suite/test names and counts without CMake.
[[nodiscard]] Void::Result::Result<std::vector<DiscoveredTestCase>, Void::Result::Error>
scan_void_tests(const std::filesystem::path &source_file);
[[nodiscard]] Void::Result::Result<GeneratedRegistration, Void::Result::Error>
generate_test_registration_unit(const std::filesystem::path &source_file,
const std::filesystem::path &output_dir);
} // namespace Void::Build::SelfHost
+87
View File
@@ -0,0 +1,87 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstdint>
#include <filesystem>
#include <map>
#include <optional>
#include <string>
#include <vector>
namespace Void::Build::Snapshot {
enum class EntryKind { RegularFile, Symlink, Directory };
struct SnapshotEntry {
std::string logical_path;
EntryKind kind{EntryKind::RegularFile};
std::string sha256;
std::uint64_t size{0};
std::uint32_t mode{0644};
std::string symlink_target;
std::filesystem::path materialized_path;
};
struct DirectoryMembership {
std::string logical_dir;
std::vector<std::string> entries; // Sorted lexicographically.
};
// Tracks header/include search lookup order across include directories so that
// a newly created shadowing header or newly true __has_include invalidates consumers.
struct LookupGuard {
std::vector<std::string> search_roots;
std::string lookup_name;
int matched_root_index{-1}; // -1 = negative lookup (absent across all search_roots)
std::string matched_sha256;
};
struct InputSnapshot {
std::string snapshot_id;
std::filesystem::path project_root;
std::filesystem::path materialized_root;
std::int64_t reproducibility_epoch{0};
std::map<std::string, SnapshotEntry, std::less<>> entries;
std::map<std::string, DirectoryMembership, std::less<>> memberships;
std::vector<LookupGuard> lookup_guards;
};
struct SnapshotOptions {
std::filesystem::path project_root;
std::filesystem::path snapshot_store_dir;
std::vector<std::filesystem::path> allowed_external_roots;
std::vector<std::string> excluded_names{".git", ".vbs", "build", ".serena",
".cache", ".env", "keys", "WG.conf"};
std::int64_t reproducibility_epoch{0};
int max_revalidate_retries{5};
bool materialize{true};
};
// Captures explicit files, recursive search/include roots, and lookup guards into
// a content-verified immutable InputSnapshot. Never hardlinks editable sources;
// revalidates every captured byte and directory membership before sealing.
[[nodiscard]] Void::Result::Result<InputSnapshot, Void::Result::Error> capture_snapshot(
const SnapshotOptions &options, const std::vector<std::filesystem::path> &explicit_files,
const std::vector<std::filesystem::path> &directory_roots,
const std::vector<std::pair<std::vector<std::string>, std::string>> &lookup_queries = {});
// Re-checks a sealed snapshot against the live filesystem (content + membership +
// lookup guards + symlink targets), detecting same-size/same-mtime mutations.
[[nodiscard]] Void::Result::Result<bool, Void::Result::Error>
is_snapshot_fresh(const InputSnapshot &snapshot, const SnapshotOptions &options);
// Promotes a validated generated file into the immutable snapshot store with
// canonical metadata and returns its sealed SnapshotEntry.
[[nodiscard]] Void::Result::Result<SnapshotEntry, Void::Result::Error>
seal_generated_artifact(const std::filesystem::path &staged_file, std::string logical_path,
const std::filesystem::path &snapshot_store_dir,
std::int64_t reproducibility_epoch);
// Persists a sealed snapshot manifest atomically as UTF-8 JSON.
[[nodiscard]] Void::Result::Result<std::filesystem::path, Void::Result::Error>
write_snapshot_manifest(const InputSnapshot &snapshot,
const std::filesystem::path &snapshot_store_dir);
} // namespace Void::Build::Snapshot
+138
View File
@@ -0,0 +1,138 @@
#pragma once
#include <Void/Build/Snapshot/Snapshot.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::State {
inline constexpr int kStateSchemaVersion = 1;
struct BlobRef {
std::string sha256;
std::uint64_t size{0};
std::uint32_t mode{0644};
};
struct ActionSuccessRecord {
std::string action_key;
std::string profile_identity;
std::string target_name;
std::map<std::string, BlobRef, std::less<>> outputs; // relative/logical output -> CAS blob
std::map<std::string, std::string, std::less<>> discovered_inputs; // path -> sha256
std::vector<Snapshot::LookupGuard> lookup_guards;
std::int64_t recorded_epoch{0};
};
struct GraphGenerationRecord {
std::string generation_id;
std::string profile_name;
std::string profile_identity;
std::string snapshot_id;
std::string status; // "valid", "invalid", "stale"
std::string diagnostic;
std::uint64_t sequence{0};
};
struct GcStats {
std::size_t removed_blobs{0};
std::uint64_t freed_bytes{0};
std::size_t retained_blobs{0};
std::size_t cleaned_staging_files{0};
};
struct LeaseHandle {
std::string lease_id;
std::filesystem::path lease_file;
~LeaseHandle() noexcept;
LeaseHandle() = default;
LeaseHandle(const LeaseHandle &) = delete;
LeaseHandle &operator=(const LeaseHandle &) = delete;
LeaseHandle(LeaseHandle &&other) noexcept;
LeaseHandle &operator=(LeaseHandle &&other) noexcept;
void release() noexcept;
};
// Transactional persistent state & SHA-256 content-addressed local artifact cache (Plan 07).
// Uses Void::Sqlite when compiled with SQLite3 support and a durable atomic-replace
// transactional store via Void::FileSystem::replace_file in minimal environments (VL-011).
class StateStore {
public:
[[nodiscard]] static Void::Result::Result<StateStore, Void::Result::Error>
open(const std::filesystem::path &vbs_dir);
[[nodiscard]] const std::filesystem::path &root() const noexcept { return root_; }
[[nodiscard]] std::filesystem::path cas_blob_path(std::string_view sha256) const;
// CAS operations: publish immutable blobs BEFORE recording references in state.
[[nodiscard]] Void::Result::Result<BlobRef, Void::Result::Error>
store_blob_from_file(const std::filesystem::path &file_path);
[[nodiscard]] Void::Result::Result<bool, Void::Result::Error>
verify_blob(std::string_view sha256) const;
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
materialize_blob(const BlobRef &ref, const std::filesystem::path &destination) const;
// Transactional action cache queries & publication.
[[nodiscard]] Void::Result::Result<std::optional<ActionSuccessRecord>, Void::Result::Error>
lookup_action(std::string_view action_key) const;
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
record_action_success(const ActionSuccessRecord &record);
// Graph generation tracking.
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
record_generation(const GraphGenerationRecord &generation);
[[nodiscard]] Void::Result::Result<std::vector<GraphGenerationRecord>, Void::Result::Error>
list_generations(std::optional<std::string_view> profile_name = std::nullopt) const;
// Leases protect active runs from GC deletion.
[[nodiscard]] Void::Result::Result<LeaseHandle, Void::Result::Error>
acquire_lease(std::string_view profile_name, const std::set<std::string> &pinned_blobs = {});
// Conservative crash recovery: removes uncommitted staging files and dead leases;
// never invents a successful action record.
[[nodiscard]] Void::Result::Result<std::size_t, Void::Result::Error> recover();
// Garbage collects unreachable CAS blobs outside active leases and pinned generations.
[[nodiscard]] Void::Result::Result<GcStats, Void::Result::Error>
gc(std::uint64_t max_cache_bytes = 0);
[[nodiscard]] std::size_t recorded_action_count() const;
private:
struct DatabaseSnapshot {
int schema_version{kStateSchemaVersion};
std::uint64_t next_sequence{1};
std::map<std::string, ActionSuccessRecord, std::less<>> actions;
std::vector<GraphGenerationRecord> generations;
};
explicit StateStore(std::filesystem::path root);
[[nodiscard]] Void::Result::Result<DatabaseSnapshot, Void::Result::Error>
load_db_locked() const;
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
save_db_locked(const DatabaseSnapshot &db) const;
std::filesystem::path root_;
std::filesystem::path cas_dir_;
std::filesystem::path staging_dir_;
std::filesystem::path leases_dir_;
std::filesystem::path db_file_;
std::filesystem::path lock_file_;
};
} // namespace Void::Build::State
+136
View File
@@ -0,0 +1,136 @@
#pragma once
#include <Void/Build.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <map>
#include <optional>
#include <string>
#include <utility>
#include <vector>
namespace Void::Build::Toolchain {
struct ToolchainCapabilities {
CompilerFamily family{CompilerFamily::Gcc};
std::filesystem::path cxx_compiler;
std::filesystem::path archiver;
std::optional<std::filesystem::path> module_scanner;
std::string version_banner;
std::string target_triple;
std::string sysroot;
std::string compiler_sha256;
std::string archiver_sha256;
std::vector<std::string> default_include_dirs;
std::map<std::string, std::string, std::less<>> relevant_env;
bool supports_cxx17{false};
bool supports_cxx20{false};
bool supports_cxx23{false};
bool supports_cxx26{false};
bool supports_reflection{false};
bool supports_file_prefix_map{false};
bool supports_macro_prefix_map{false};
bool supports_debug_prefix_map{false};
bool supports_p1689_scan{false};
bool supports_pch{true};
bool supports_lto_full{false};
bool supports_lto_thin{false};
bool supports_asan{false};
bool supports_ubsan{false};
bool supports_tsan{false};
bool is_cross_toolchain{false};
std::string identity_hash;
};
struct PathPrefixMap {
std::filesystem::path from;
std::filesystem::path to;
};
struct CompileRequest {
std::filesystem::path source_file;
std::filesystem::path output_object;
std::optional<std::filesystem::path> depfile;
std::optional<std::filesystem::path> response_file_dir;
std::vector<std::pair<std::filesystem::path, bool>> include_dirs; // (path, is_system)
std::vector<std::string> defines;
std::vector<std::string> compile_options;
CxxStandard cxx_standard{CxxStandard::Default};
LtoMode lto{LtoMode::None};
std::vector<Sanitizer> sanitizers;
bool position_independent{false};
std::optional<std::filesystem::path> precompiled_header;
std::vector<PathPrefixMap> prefix_maps;
std::int64_t reproducibility_epoch{0};
bool nondeterministic{false};
std::size_t response_file_threshold{32768};
bool compile_only{true};
bool is_module_interface{false};
std::optional<std::filesystem::path> bmi_output;
std::vector<std::pair<std::string, std::filesystem::path>> module_bmi_imports;
std::optional<std::filesystem::path> module_mapper_file;
};
struct LinkRequest {
TargetKind kind{TargetKind::Executable};
std::filesystem::path output_file;
std::optional<std::filesystem::path> response_file_dir;
std::vector<std::filesystem::path> object_files;
std::vector<std::filesystem::path> static_libraries;
std::vector<std::filesystem::path> shared_libraries;
std::vector<std::filesystem::path> rpaths;
std::vector<std::string> link_options;
LtoMode lto{LtoMode::None};
std::vector<Sanitizer> sanitizers;
std::size_t response_file_threshold{32768};
};
struct LoweredCommand {
std::filesystem::path executable;
std::vector<std::string> arguments;
std::map<std::string, std::string, std::less<>> environment;
std::optional<std::filesystem::path> response_file;
std::string response_file_content;
};
// Discovers compiler & archiver, computes complete binary/sysroot/env identity,
// and probes capabilities without executing any target binaries (cross-safe).
[[nodiscard]] Void::Result::Result<ToolchainCapabilities, Void::Result::Error>
discover_and_probe(const ProfileContext &context,
const std::optional<std::filesystem::path> &cache_dir = std::nullopt);
// Computes canonical identity hash for a resolved profile + toolchain pair.
[[nodiscard]] std::string compute_profile_identity(const ProfileContext &context,
const ToolchainCapabilities &toolchain);
// Escapes a single argument for GCC/Clang @response-file parsing.
[[nodiscard]] std::string escape_response_file_arg(std::string_view arg);
// Lowers a structured compile request into argv, environment, and optional response file.
// Fails explicitly if requested deterministic path maps or compiler features are unsupported.
[[nodiscard]] Void::Result::Result<LoweredCommand, Void::Result::Error>
lower_compile_command(const ToolchainCapabilities &toolchain, const CompileRequest &request);
// Lowers a deterministic static library archive command (`ar rcsD`).
[[nodiscard]] Void::Result::Result<LoweredCommand, Void::Result::Error>
lower_archive_command(const ToolchainCapabilities &toolchain,
const std::filesystem::path &output_archive,
const std::vector<std::filesystem::path> &object_files,
const std::optional<std::filesystem::path> &response_file_dir = std::nullopt,
std::size_t response_file_threshold = 32768);
// Lowers a structured link command for executables and shared libraries.
[[nodiscard]] Void::Result::Result<LoweredCommand, Void::Result::Error>
lower_link_command(const ToolchainCapabilities &toolchain, const LinkRequest &request);
// Returns the host operating system and architecture labels.
[[nodiscard]] std::string host_os_name();
[[nodiscard]] std::string host_architecture_name();
} // namespace Void::Build::Toolchain
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::Util {
// Strict UTF-8 validation per RFC 8259 / Unicode scalar value rules (VL-008).
[[nodiscard]] bool is_valid_utf8(std::string_view text) noexcept;
void require_valid_utf8(std::string_view text);
// Emits a valid JSON string literal, throwing std::invalid_argument on malformed UTF-8.
[[nodiscard]] std::string json_quote(std::string_view text);
template <typename Range, typename Serialize>
[[nodiscard]] std::string json_array(const Range &range, Serialize serialize) {
std::string output{"["};
bool first = true;
for (const auto &item : range) {
if (!first) {
output += ',';
}
first = false;
output += serialize(item);
}
output += ']';
return output;
}
} // namespace Void::Build::Util
+53
View File
@@ -0,0 +1,53 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <array>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <span>
#include <string>
#include <string_view>
namespace Void::Build::Util {
using Sha256Digest = std::array<std::uint8_t, 32>;
// Streaming FIPS 180-4 SHA-256 hasher (VL-007: delegates to Void::Crypto when
// OpenSSL is available; provides zero-dependency built-in fallback otherwise).
class Sha256Hasher {
public:
Sha256Hasher() noexcept;
void update(std::span<const std::byte> data) noexcept;
void update(std::span<const std::uint8_t> data) noexcept;
void update(std::string_view text) noexcept;
void update_length_prefixed(std::string_view text) noexcept;
void update_u64(std::uint64_t value) noexcept;
[[nodiscard]] Sha256Digest finalize() noexcept;
[[nodiscard]] std::string finalize_hex() noexcept;
private:
void transform(const std::uint8_t block[64]) noexcept;
std::uint32_t state_[8];
std::uint64_t bit_count_{0};
std::uint8_t buffer_[64]{};
std::size_t buffer_len_{0};
bool finalized_{false};
};
[[nodiscard]] std::string to_hex(const Sha256Digest &digest);
[[nodiscard]] Sha256Digest sha256_bytes(std::span<const std::byte> data) noexcept;
[[nodiscard]] std::string sha256_hex(std::string_view text);
[[nodiscard]] std::string sha256_hex(std::span<const std::byte> data);
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
sha256_file_hex(const std::filesystem::path &path);
// Constant-time equality for hex digests / authentication tokens.
[[nodiscard]] bool constant_time_equal(std::string_view a, std::string_view b) noexcept;
} // namespace Void::Build::Util
+125
View File
@@ -0,0 +1,125 @@
#pragma once
#include <Void/Build/Config/Frontend.hpp>
#include <Void/Build/Editor/CompDb.hpp>
#include <Void/Build/Execution/Scheduler.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/Snapshot/Snapshot.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <chrono>
#include <cstddef>
#include <filesystem>
#include <functional>
#include <map>
#include <optional>
#include <stop_token>
#include <string>
#include <vector>
namespace Void::Build::Watch {
struct WatchBatch {
std::vector<std::filesystem::path> changed_paths;
bool overflowed{false};
bool rescan_required{false};
};
// Linux inotify recursive directory watcher (VL-003).
// Automatically excludes build/cache/VCS trees to prevent feedback loops, attaches watches
// to newly created subdirectories, and reports IN_Q_OVERFLOW as rescan_required.
class InotifyWatcher {
public:
InotifyWatcher() = default;
~InotifyWatcher() noexcept;
InotifyWatcher(const InotifyWatcher &) = delete;
InotifyWatcher &operator=(const InotifyWatcher &) = delete;
InotifyWatcher(InotifyWatcher &&other) noexcept;
InotifyWatcher &operator=(InotifyWatcher &&other) noexcept;
[[nodiscard]] static Void::Result::Result<InotifyWatcher, Void::Result::Error>
create(const std::filesystem::path &root_dir,
std::vector<std::string> excluded_names = {".git", ".vbs", "build", ".serena", ".cache",
"keys"});
// Polls for events up to `timeout` and coalesces burst activity across `debounce`.
[[nodiscard]] Void::Result::Result<WatchBatch, Void::Result::Error>
poll_events(std::chrono::milliseconds timeout,
std::chrono::milliseconds debounce = std::chrono::milliseconds{40});
// Forces full watch-tree reattachment (used after overflow or root replacement).
[[nodiscard]] Void::Result::Result<void, Void::Result::Error> rescan_watches();
[[nodiscard]] std::size_t watched_directory_count() const noexcept {
return wd_to_path_.size();
}
private:
explicit InotifyWatcher(int fd, std::filesystem::path root, std::vector<std::string> excluded);
void close_fd() noexcept;
Void::Result::Result<void, Void::Result::Error> watch_tree(const std::filesystem::path &dir);
bool is_excluded(const std::filesystem::path &rel) const;
int fd_{-1};
std::filesystem::path root_;
std::vector<std::string> excluded_;
std::map<int, std::filesystem::path> wd_to_path_;
};
enum class WatchMode { FullBuild, MetadataOnly };
struct WatchCycleReport {
std::size_t cycle_index{0};
std::string profile_name;
bool config_succeeded{false};
bool build_succeeded{false};
bool compdb_published{false};
bool provider_stale{false};
std::size_t executed_actions{0};
std::size_t cached_actions{0};
std::string diagnostic;
};
// Callback used in MetadataOnly mode to supply validated cached imported-target metadata
// WITHOUT ever invoking foreign configure/build/install/fetch or lockfile writes (Plan 10/13).
struct CachedProviderSnapshot {
bool valid{true};
std::string stale_diagnostic;
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> imported_targets;
};
using ProviderMetadataReader =
std::function<CachedProviderSnapshot(const Graph::ProjectDescription &, WatchMode)>;
struct WatchLoopOptions {
WatchMode mode{WatchMode::FullBuild};
Config::FrontendOptions frontend;
std::optional<std::string>
explicit_profile; // Empty in MetadataOnly -> follow active editor profile
std::optional<CompilerFamily> compiler_override;
std::vector<std::string> selected_targets;
std::size_t jobs{0};
std::chrono::milliseconds debounce{40};
std::chrono::milliseconds reconcile_interval{1000};
std::size_t max_cycles{0}; // 0 = run until stop_token requested
ProviderMetadataReader provider_reader;
std::function<void(const WatchCycleReport &)> on_cycle;
};
// Executes a single reconciliation cycle cleanly (used by one-shot builds, build watch,
// and metadata-only watch so all three share one exact invalidation pipeline).
[[nodiscard]] WatchCycleReport run_reconcile_cycle(const WatchLoopOptions &options,
std::size_t cycle_index,
bool allow_selection_update,
std::optional<std::uint64_t> reserved_ticket,
std::stop_token stop = {});
// Runs the full watch loop (inotify hints + periodic content/namespace reconciliation +
// overflow recovery + graceful cancellation via stop_token).
[[nodiscard]] Void::Result::Result<std::vector<WatchCycleReport>, Void::Result::Error>
run_watch_loop(const WatchLoopOptions &options, std::stop_token stop = {});
} // namespace Void::Build::Watch