151 lines
5.6 KiB
C++
151 lines
5.6 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<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::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
|