Files
Build-System/include/Void/Build/Toolchain/Driver.hpp
T
faumaray 76f1e2a48c
VoidBuildSystem CI / 1 · Requirements (push) Successful in 3s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 2m30s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m40s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 3m4s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 4m16s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 5m48s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 4m18s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 1m20s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 29s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 16s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 18s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 6m4s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m28s
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: lifecycle commands and native compiler caching (G1, G7)
G1 (start):
- vbs run builds an executable target, passes program args through `--`,
  inherits stdio via Void::Process (interactive programs keep the terminal)
  and returns the program's exit code; Windows targets run under Wine.
- vbs metadata emits a schema-versioned workspace document built with
  Void::Json::Strict: roots, profile/compiler, targets (sources, includes,
  links, labels, install rules), dependencies and the lockfile revision.
- vbs why walks the target graph root -> target, or explains a dependency
  and the targets linking it.
- vbs add NAME[@RANGE] / vbs remove NAME edit vbs.deps.toml (canonical,
  comment-preserving block editing), validate ranges with
  Void::Semver::parse_range and refresh vbs.lock via the resolver.
- --frozen implies --locked --offline for build/test/run.

G7 (native caching):
- --native-cache off|auto|ccache|sccache (or VBS_NATIVE_CACHE) prepends
  ccache/sccache to compile actions only; the wrapper and real compiler are
  part of the action key, archive/link actions are untouched, and
  vbs doctor reports availability.

VoidLibrary reuse: Void::Process (spawn with inherited stdio),
Void::Json::Strict (metadata document), Void::Str (trim/split/prefix),
Void::Semver (range validation), plus the existing SDK helpers
(target_kind_name/visibility_name) instead of local duplicates.

Verified: lifecycle_run_metadata_why_and_manifest_editing,
native_cache_wrapper_is_lowered_into_compile_commands and
native_cache_wraps_compile_actions pass; CLI contracts pass; clang-format
clean.
2026-12-06 19:20:39 +03:00

155 lines
6.2 KiB
C++

#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 c_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 c_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_c11{false};
bool supports_c17{false};
bool supports_c23{false};
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};
// Shader compilers discovered from PATH (not part of the toolchain identity).
std::filesystem::path glslang_validator; // GLSL + HLSL -> SPIR-V
std::filesystem::path slangc; // Slang (and GLSL/HLSL) -> SPIR-V
std::filesystem::path dxc; // HLSL -> SPIR-V / DXIL
// Optional native compiler cache (ccache/sccache) prepended to compile actions. Not part of
// the toolchain identity: the wrapper is part of every compile action's command instead.
std::string native_cache_executable;
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;
bool is_c_source{false};
// Assembly source (`.s` plain, `.S` preprocessed): compiled with the C compiler driver.
bool is_asm_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<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