VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
- SDK: Workspace/workspace() declaration plus Project::workspace_dependency() - Frontend: workspace.cpp discovery/evaluation alongside build.cpp - Main: per-member builds sharing the root vbs.lock and build/.vbs CAS, --member and --changed-since selection - Cross-member native linking; member builds do not steal the root compile_commands.json alias - Path-dependency snapshots exclude generated editor metadata - Verified in Docker GCC 16: 8/8 CTest suites; 3-member workspace fixture with unified lockfile
367 lines
14 KiB
C++
367 lines
14 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 };
|
|
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 };
|
|
|
|
[[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 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;
|
|
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;
|
|
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;
|
|
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 &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 = {});
|
|
Dependency &native_builder(OptionMap options = {});
|
|
Dependency &package(std::string id, std::string range);
|
|
Dependency ®istry(std::string authority_url);
|
|
Dependency &feature(std::string name);
|
|
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_;
|
|
};
|
|
|
|
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);
|
|
[[nodiscard]] Target test(std::string name);
|
|
[[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);
|