Files
Build-System/include/Void/Build/Graph/Graph.hpp
T
faumaray f03524628b
VoidBuildSystem CI / 1 · Requirements (push) Successful in 8s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m47s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 2m53s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m36s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m57s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m23s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 25s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 24s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 6m1s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 2m2s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 2m2s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m54s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 7m4s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
feat(features): additive C++ feature flags (G2)
- Project::feature(name, default_on) / FeatureDescription, Target's
  require_feature() (the `.requires` spelling is a C++20 keyword), and
  Dependency::when(feature) for optional dependencies.
- --features a,b / --no-default-features on build, test, run, explain and
  deps resolve/update. Unification is additive: defaults (unless
  disabled) + features required by targets + requested features.
- Enabled features add VBS_FEATURE_<NAME> compile definitions to every
  target, so action keys and the cache are feature-aware; switching the
  set invalidates cached actions.
- Optional dependencies are filtered before resolution, so vbs.lock
  contains only active ones.
- vbs explain --show-features prints the unified set with reasons
  (default/requested/required by target); vbs metadata lists declared
  features with their enabled state; the descriptor JSON carries features
  and target requirements.

API note: features provide preprocessor-level configuration (defines), not
ABI/layout changes across a feature boundary.

Verified: features_unify_defines_and_invalidate_action_keys and
optional_dependencies_follow_feature_selection pass; vbs_core_tests 8/8;
CLI contracts pass; clang-format clean.
2026-12-06 20:01:29 +03:00

157 lines
5.8 KiB
C++

#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<FeatureDescription> features;
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;
std::map<std::string, std::filesystem::path, std::less<>> module_bmis;
};
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;
bool is_c_source{false};
CStandard c_standard{CStandard::Default};
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::string> labels;
std::vector<std::string> resources;
std::vector<std::string> fixture_setup;
std::vector<std::string> fixture_required;
std::vector<std::string> fixture_cleanup;
std::vector<std::filesystem::path> expanded_sources;
std::vector<std::filesystem::path> primary_outputs;
std::vector<std::filesystem::path> runtime_shared_libraries;
std::map<std::string, std::filesystem::path, std::less<>> exported_module_bmis;
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