VoidBuildSystem CI / 1 · Requirements (push) Successful in 5s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m50s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 3m29s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 4m7s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m53s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m22s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m22s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 1m57s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 2m0s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 19s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 18s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 7m8s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 7m24s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
- Dependency::profile(name, DependencyProfileOptions) records per-profile compile/link options, defines, LTO and sanitizers. The native provider applies the matching override to the dependency's own ProfileContext and hashes the overrides into the provider input hash, so changing them invalidates cached dependency builds. - vbs-toolchain.toml pins compiler, minimum version, C/C++ standards and sysroot (optional strict); it is loaded once and checked after every toolchain probe. Drift warns by default and fails with --locked-toolchain or strict = true; malformed pins fail with the TOML diagnostic. - vbs profile list|show|diff lists declared profiles with parents, prints a resolved profile (flags, standards, LTO, sanitizers, sysroot) or the fields that differ between two. Verified: dependency_profile_overrides_apply_to_native_builds (a define from the override is required by the dependency source), toolchain_pin_detects_and_enforces_drift and profile_commands_list_show_and_diff pass; vbs_core_tests 8/8; CLI contracts pass; clang-format clean.
426 lines
17 KiB
C++
426 lines
17 KiB
C++
#pragma once
|
|
|
|
#include <concepts>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <initializer_list>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <utility>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
namespace Void::Build {
|
|
|
|
inline constexpr int schema_version = 1;
|
|
|
|
enum class CompilerFamily { Gcc, Clang };
|
|
enum class Visibility { Private, Public, Interface };
|
|
enum class TargetKind {
|
|
Executable,
|
|
StaticLibrary,
|
|
SharedLibrary,
|
|
HeaderOnly,
|
|
ObjectLibrary,
|
|
CustomAction,
|
|
Test
|
|
};
|
|
enum class SourceKind { File, Glob, ModuleInterface, ModulePartition, HeaderUnit };
|
|
enum class LinkKind { Local, Imported };
|
|
enum class DependencySourceKind { Unspecified, Git, Package, Path, Archive, Conan, PkgConfig };
|
|
enum class CStandard { Default, C11, C17, C23 };
|
|
enum class CxxStandard { Default, Cxx17, Cxx20, Cxx23, Cxx26 };
|
|
enum class LtoMode { None, Full, Thin };
|
|
enum class Sanitizer { Address, Undefined, Thread, Memory, Leak };
|
|
enum class ShaderLanguage { Auto, Glsl, Hlsl, Slang };
|
|
enum class ShaderStage { Auto, Vertex, Fragment, Compute, Geometry, TessControl, TessEval };
|
|
|
|
struct ShaderSource {
|
|
std::string path;
|
|
ShaderLanguage language{ShaderLanguage::Auto};
|
|
ShaderStage stage{ShaderStage::Auto};
|
|
};
|
|
|
|
[[nodiscard]] std::string_view compiler_name(CompilerFamily compiler);
|
|
[[nodiscard]] CompilerFamily parse_compiler(std::string_view name);
|
|
[[nodiscard]] std::string_view visibility_name(Visibility visibility);
|
|
[[nodiscard]] Visibility parse_visibility(std::string_view name);
|
|
[[nodiscard]] std::string_view target_kind_name(TargetKind kind);
|
|
[[nodiscard]] TargetKind parse_target_kind(std::string_view name);
|
|
[[nodiscard]] std::string_view source_kind_name(SourceKind kind);
|
|
[[nodiscard]] SourceKind parse_source_kind(std::string_view name);
|
|
[[nodiscard]] std::string_view c_standard_name(CStandard standard);
|
|
[[nodiscard]] CStandard parse_c_standard(std::string_view name);
|
|
[[nodiscard]] std::string_view cxx_standard_name(CxxStandard standard);
|
|
[[nodiscard]] CxxStandard parse_cxx_standard(std::string_view name);
|
|
[[nodiscard]] std::string_view lto_mode_name(LtoMode mode);
|
|
[[nodiscard]] LtoMode parse_lto_mode(std::string_view name);
|
|
[[nodiscard]] std::string_view sanitizer_name(Sanitizer sanitizer);
|
|
[[nodiscard]] Sanitizer parse_sanitizer(std::string_view name);
|
|
|
|
struct ProfileContext {
|
|
std::string name;
|
|
CompilerFamily compiler{CompilerFamily::Gcc};
|
|
std::string os;
|
|
std::string architecture;
|
|
std::vector<std::string> compile_options;
|
|
std::vector<std::string> link_options;
|
|
std::vector<std::string> defines;
|
|
CStandard c_standard{CStandard::Default};
|
|
CxxStandard cxx_standard{CxxStandard::Default};
|
|
LtoMode lto{LtoMode::None};
|
|
std::vector<Sanitizer> sanitizers;
|
|
std::string sysroot;
|
|
std::string compiler_path;
|
|
std::int64_t reproducibility_epoch{0};
|
|
bool nondeterministic{false};
|
|
};
|
|
|
|
struct FeatureDescription {
|
|
std::string name;
|
|
bool default_on{false};
|
|
std::string description;
|
|
};
|
|
|
|
// Per-profile overrides applied to a dependency's own build (Tracks G3).
|
|
struct DependencyProfileOptions {
|
|
std::vector<std::string> compile_options;
|
|
std::vector<std::string> link_options;
|
|
std::vector<std::string> defines;
|
|
std::optional<LtoMode> lto;
|
|
std::vector<Sanitizer> sanitizers;
|
|
};
|
|
|
|
struct ProfileDescription {
|
|
std::string name;
|
|
std::vector<std::string> compile_options;
|
|
std::optional<std::string> parent;
|
|
std::vector<std::string> link_options;
|
|
std::vector<std::string> defines;
|
|
std::optional<CompilerFamily> compiler;
|
|
std::optional<CStandard> c_standard;
|
|
std::optional<CxxStandard> cxx_standard;
|
|
std::optional<LtoMode> lto;
|
|
std::vector<Sanitizer> sanitizers;
|
|
std::string sysroot;
|
|
std::string compiler_path;
|
|
std::optional<std::int64_t> reproducibility_epoch;
|
|
std::optional<bool> nondeterministic;
|
|
};
|
|
|
|
class Profiles {
|
|
public:
|
|
void add(std::string name, std::vector<std::string> compile_options = {});
|
|
void inherit(std::string name, std::string parent,
|
|
std::vector<std::string> compile_options = {});
|
|
void define(ProfileDescription description);
|
|
[[nodiscard]] const std::vector<ProfileDescription> &records() const noexcept;
|
|
[[nodiscard]] ProfileContext resolve(std::string_view name, CompilerFamily compiler,
|
|
std::string os, std::string architecture) const;
|
|
[[nodiscard]] ProfileContext resolve(std::string_view name,
|
|
std::optional<CompilerFamily> compiler_override,
|
|
std::string os, std::string architecture) const;
|
|
[[nodiscard]] std::string to_json() const;
|
|
|
|
private:
|
|
std::vector<ProfileDescription> records_;
|
|
};
|
|
|
|
[[nodiscard]] Profiles default_profiles();
|
|
|
|
struct SourceRecord {
|
|
SourceKind kind;
|
|
std::string path;
|
|
};
|
|
|
|
// Source spelling is recorded verbatim; construction never reads the filesystem.
|
|
class SourceSet {
|
|
public:
|
|
SourceSet() = default;
|
|
SourceSet(std::initializer_list<std::string_view> files);
|
|
[[nodiscard]] static SourceSet file(std::string path);
|
|
[[nodiscard]] static SourceSet glob(std::string pattern);
|
|
[[nodiscard]] static SourceSet module_interface(std::string path);
|
|
[[nodiscard]] static SourceSet module_partition(std::string path);
|
|
[[nodiscard]] static SourceSet header_unit(std::string path);
|
|
[[nodiscard]] const std::vector<SourceRecord> &records() const noexcept;
|
|
|
|
private:
|
|
std::vector<SourceRecord> records_;
|
|
};
|
|
|
|
struct OptionValue {
|
|
using Value = std::variant<std::string, bool, std::int64_t>;
|
|
Value value;
|
|
|
|
OptionValue(std::string text) : value{std::move(text)} {}
|
|
OptionValue(const char *text) : OptionValue{std::string{text}} {}
|
|
OptionValue(bool boolean) : value{boolean} {}
|
|
template <std::integral Integer>
|
|
requires(!std::same_as<Integer, bool>)
|
|
OptionValue(Integer integer) : value{std::int64_t{0}} {
|
|
if (!std::in_range<std::int64_t>(integer)) {
|
|
throw std::invalid_argument{"option integer is out of range"};
|
|
}
|
|
value = static_cast<std::int64_t>(integer);
|
|
}
|
|
};
|
|
using OptionMap = std::map<std::string, OptionValue, std::less<>>;
|
|
|
|
struct Commit {
|
|
std::string sha;
|
|
};
|
|
struct IncludeDirectory {
|
|
std::string path;
|
|
Visibility visibility{Visibility::Private};
|
|
bool is_system{false};
|
|
};
|
|
struct ScopedOption {
|
|
std::string value;
|
|
Visibility visibility{Visibility::Private};
|
|
};
|
|
struct LinkRecord {
|
|
LinkKind kind;
|
|
std::string target;
|
|
std::string dependency; // Empty for a local target.
|
|
Visibility visibility{Visibility::Private};
|
|
};
|
|
struct PerFileOption {
|
|
std::string source_path;
|
|
std::string option;
|
|
};
|
|
struct InstallRule {
|
|
std::string target_name;
|
|
std::string source_path;
|
|
std::string destination;
|
|
std::string component{"default"};
|
|
bool is_directory{false};
|
|
};
|
|
struct TargetRecord {
|
|
std::string name;
|
|
TargetKind kind;
|
|
std::vector<SourceRecord> sources;
|
|
std::vector<IncludeDirectory> include_directories;
|
|
std::vector<std::string> compile_options;
|
|
std::vector<LinkRecord> links;
|
|
std::vector<ScopedOption> scoped_compile_options;
|
|
std::vector<ScopedOption> defines;
|
|
std::vector<ScopedOption> link_options;
|
|
std::vector<std::string> prerequisites;
|
|
std::vector<std::string> required_features; // Project features this target requires.
|
|
CStandard c_standard{CStandard::Default};
|
|
CxxStandard cxx_standard{CxxStandard::Default};
|
|
std::string precompiled_header;
|
|
bool unity_enabled{false};
|
|
std::size_t unity_batch_size{8};
|
|
LtoMode lto{LtoMode::None};
|
|
std::vector<Sanitizer> sanitizers;
|
|
std::vector<PerFileOption> per_file_options;
|
|
std::vector<std::string> command_argv;
|
|
std::vector<std::string> action_inputs;
|
|
std::vector<std::string> action_outputs;
|
|
std::string working_directory;
|
|
std::map<std::string, std::string, std::less<>> environment;
|
|
std::vector<std::string> labels; // Test labels for filtering (`vbs test --label`).
|
|
std::vector<std::string> resources; // Exclusive resources held while the test runs.
|
|
std::vector<ShaderSource> shaders; // Shader sources compiled to SPIR-V.
|
|
std::vector<std::string> fixture_setup; // Fixtures this test sets up.
|
|
std::vector<std::string> fixture_required; // Fixtures this test requires.
|
|
std::vector<std::string> fixture_cleanup; // Fixtures this test tears down.
|
|
bool nondeterministic{false};
|
|
bool enabled{true};
|
|
bool use_conventional_sources{false};
|
|
std::optional<InstallRule> install_rule;
|
|
};
|
|
struct DependencyRecord {
|
|
std::string name;
|
|
DependencySourceKind source_kind{DependencySourceKind::Unspecified};
|
|
std::string location;
|
|
std::string revision;
|
|
std::string package;
|
|
std::string version;
|
|
std::string builder;
|
|
OptionMap options;
|
|
std::string registry_authority;
|
|
std::string sha256;
|
|
std::vector<std::string> features;
|
|
std::string required_feature; // Optional dependency: only used when this feature is on.
|
|
std::map<std::string, DependencyProfileOptions, std::less<>> profile_overrides;
|
|
bool build_dependency{false};
|
|
};
|
|
|
|
// Workspace declaration (E2): a root workspace.cpp lists member projects that share one
|
|
// vbs.lock and one build/.vbs CAS while each keeps its own build.cpp and profile outputs.
|
|
struct WorkspaceMemberRecord {
|
|
std::string name;
|
|
std::string path; // Relative to the workspace root (or absolute).
|
|
};
|
|
|
|
class Workspace {
|
|
public:
|
|
Workspace() = default;
|
|
Workspace &member(std::string name, std::string path);
|
|
[[nodiscard]] const std::vector<WorkspaceMemberRecord> &members() const noexcept;
|
|
[[nodiscard]] std::string to_json() const;
|
|
|
|
private:
|
|
std::vector<WorkspaceMemberRecord> members_;
|
|
};
|
|
|
|
namespace detail {
|
|
struct ProjectState;
|
|
}
|
|
class Project;
|
|
class Dependency;
|
|
|
|
// Handles retain an index and weak owner identity, never a pointer into a growing vector.
|
|
class ImportedTarget {
|
|
private:
|
|
friend class Dependency;
|
|
friend class Target;
|
|
ImportedTarget(std::weak_ptr<detail::ProjectState> owner, std::size_t dependency,
|
|
std::string name);
|
|
std::weak_ptr<detail::ProjectState> owner_;
|
|
std::size_t dependency_;
|
|
std::string name_;
|
|
};
|
|
|
|
class Target {
|
|
public:
|
|
Target &sources(const SourceSet &sources);
|
|
Target &conventional_sources();
|
|
Target &module_sources(const SourceSet &sources);
|
|
Target &header_unit(std::string header_path);
|
|
Target &include_directory(std::string path, Visibility visibility = Visibility::Private);
|
|
Target &system_include_directory(std::string path, Visibility visibility = Visibility::Private);
|
|
Target &compile_option(std::string option);
|
|
Target &compile_option(std::string option, Visibility visibility);
|
|
Target &define(std::string macro, Visibility visibility = Visibility::Private);
|
|
Target &link_option(std::string option, Visibility visibility = Visibility::Private);
|
|
Target &link(const Target &target, Visibility visibility = Visibility::Private);
|
|
Target &link(const ImportedTarget &target, Visibility visibility = Visibility::Private);
|
|
Target &depends_on(const Target &producer);
|
|
Target &c_standard(CStandard standard);
|
|
Target &cxx_standard(CxxStandard standard);
|
|
Target &precompiled_header(std::string header_path);
|
|
Target &unity_build(bool enabled, std::size_t batch_size = 8);
|
|
Target <o(LtoMode mode);
|
|
Target &sanitizer(Sanitizer sanitizer);
|
|
Target &per_file_option(std::string source_path, std::string option);
|
|
Target &command(std::vector<std::string> argv);
|
|
Target &inputs(std::vector<std::string> paths);
|
|
Target &outputs(std::vector<std::string> paths);
|
|
Target &working_directory(std::string directory);
|
|
Target &env(std::string key, std::string value);
|
|
Target &label(std::string label);
|
|
Target &resource(std::string name);
|
|
// Declares a shader source on a shader bundle (compiled to SPIR-V on build).
|
|
Target &shader(std::string source_path, ShaderLanguage language = ShaderLanguage::Auto,
|
|
ShaderStage stage = ShaderStage::Auto);
|
|
Target &fixture_setup(std::string name);
|
|
Target &fixture_required(std::string name);
|
|
Target &fixture_cleanup(std::string name);
|
|
// Contributes a project feature to the additive feature set (Cargo-style unification).
|
|
Target &require_feature(std::string feature);
|
|
Target &nondeterministic(bool enabled = true);
|
|
Target &enabled(bool flag);
|
|
Target &install(std::string destination = {}, std::string component = "default");
|
|
[[nodiscard]] const TargetRecord &record() const;
|
|
|
|
private:
|
|
friend class Project;
|
|
Target(std::weak_ptr<detail::ProjectState> owner, std::size_t index);
|
|
std::weak_ptr<detail::ProjectState> owner_;
|
|
std::size_t index_;
|
|
};
|
|
|
|
class Dependency {
|
|
public:
|
|
Dependency &git(std::string url, Commit commit);
|
|
Dependency &path(std::string local_path);
|
|
Dependency &archive(std::string url, std::string sha256);
|
|
Dependency &cmake(OptionMap options = {});
|
|
Dependency &meson(OptionMap options = {});
|
|
Dependency &conan(std::string reference, OptionMap options = {});
|
|
// A system library discovered through a pkg-config module spec (e.g. "zlib >= 1.2").
|
|
// Search paths come from PKG_CONFIG_PATH / PKG_CONFIG_LIBDIR plus conventional prefixes.
|
|
Dependency &pkgconfig(std::string spec);
|
|
Dependency &native_builder(OptionMap options = {});
|
|
Dependency &package(std::string id, std::string range);
|
|
Dependency ®istry(std::string authority_url);
|
|
Dependency &feature(std::string name);
|
|
// Optional dependency: resolved only when the project feature is enabled.
|
|
Dependency &when(std::string feature);
|
|
// Per-profile overrides for the dependency's own build (e.g. its release profile).
|
|
Dependency &profile(std::string profile, DependencyProfileOptions options = {});
|
|
Dependency &build_dependency(bool is_build_tool = true);
|
|
[[nodiscard]] ImportedTarget target(std::string exported_name) const;
|
|
[[nodiscard]] const DependencyRecord &record() const;
|
|
|
|
private:
|
|
friend class Project;
|
|
Dependency(std::weak_ptr<detail::ProjectState> owner, std::size_t index);
|
|
std::weak_ptr<detail::ProjectState> owner_;
|
|
std::size_t index_;
|
|
};
|
|
|
|
// Value of a `.native_builder({...})` option passed by the consuming project to this
|
|
// dependency's build.cpp (exposed as VBS_DEP_OPTION_<NAME>), or an empty string when unset.
|
|
[[nodiscard]] std::string dependency_option(std::string_view name);
|
|
|
|
class Project {
|
|
public:
|
|
explicit Project(ProfileContext context);
|
|
~Project();
|
|
Project(const Project &) = delete;
|
|
Project &operator=(const Project &) = delete;
|
|
Project(Project &&) = delete;
|
|
Project &operator=(Project &&) = delete;
|
|
|
|
[[nodiscard]] const ProfileContext &context() const noexcept;
|
|
[[nodiscard]] Target executable(std::string name);
|
|
[[nodiscard]] Target static_library(std::string name);
|
|
[[nodiscard]] Target shared_library(std::string name);
|
|
[[nodiscard]] Target header_only_library(std::string name);
|
|
[[nodiscard]] Target object_library(std::string name);
|
|
[[nodiscard]] Target custom_action(std::string name);
|
|
// A target that compiles declared shader sources to SPIR-V (`.shader(...)`).
|
|
[[nodiscard]] Target shader_bundle(std::string name);
|
|
[[nodiscard]] Target test(std::string name);
|
|
// Declares a project feature (additive; defaults are on unless --no-default-features).
|
|
Project &feature(std::string name, bool default_on = false);
|
|
Project &feature(FeatureDescription description);
|
|
[[nodiscard]] const std::vector<FeatureDescription> &features() const noexcept;
|
|
[[nodiscard]] Dependency dependency(std::string name);
|
|
// Links to another member of the enclosing workspace. The member path is supplied by the
|
|
// workspace driver through VBS_WORKSPACE_MEMBER_<name> and built with the native provider.
|
|
[[nodiscard]] Dependency workspace_dependency(std::string name);
|
|
void dependencies_file(std::string toml_path = "vbs.deps.toml");
|
|
void install_file(std::string source_path, std::string destination,
|
|
std::string component = "default");
|
|
void install_directory(std::string source_path, std::string destination,
|
|
std::string component = "default");
|
|
[[nodiscard]] SourceSet glob(std::string pattern) const;
|
|
[[nodiscard]] const std::vector<TargetRecord> &targets() const noexcept;
|
|
[[nodiscard]] const std::vector<DependencyRecord> &dependencies() const noexcept;
|
|
[[nodiscard]] const std::vector<std::string> &dependency_files() const noexcept;
|
|
[[nodiscard]] const std::vector<InstallRule> &install_rules() const noexcept;
|
|
// Emits UTF-8 JSON; malformed UTF-8 in any recorded string throws invalid_argument.
|
|
[[nodiscard]] std::string to_json() const;
|
|
|
|
private:
|
|
Target add_target(std::string name, TargetKind kind);
|
|
std::shared_ptr<detail::ProjectState> state_;
|
|
};
|
|
|
|
} // namespace Void::Build
|
|
|
|
// Description entry points supplied by ordinary user C++ translation units.
|
|
void build(Void::Build::Project &project);
|
|
void profiles(Void::Build::Profiles &profiles);
|
|
void workspace(Void::Build::Workspace &workspace);
|