feat: complete Track A zero-CMake self-hosting, full VOID_TEST migration, and bit-identical Stage 2/3 bootstrap
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 2s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 2s
This commit is contained in:
1 parent
fe0d1a6483
commit
5e1916dc5c
23 files changed
+945
-141
No files matched your search
@@ -1,7 +1,10 @@
|
||||
#include <Void/Build/Provider/Provider.hpp>
|
||||
|
||||
#include <Void/Build/Config/Frontend.hpp>
|
||||
#include <Void/Build/Execution/Scheduler.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Snapshot/Snapshot.hpp>
|
||||
#include <Void/Build/Util/Json.hpp>
|
||||
#include <Void/Build/Util/Sha256.hpp>
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
@@ -9,6 +12,7 @@
|
||||
#include <Void/System/Path.hpp>
|
||||
#include <Void/System/Types.hpp>
|
||||
#include <Void/Time/Stopwatch.hpp>
|
||||
#include <VoidLibrary/VoidLibraryRecipe.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
@@ -868,6 +872,430 @@ run_conan_provider(const ProviderRequest &request, const std::filesystem::path &
|
||||
return exp;
|
||||
}
|
||||
|
||||
std::vector<std::string> parse_void_modules_option(const OptionMap &options) {
|
||||
std::vector<std::string> mods;
|
||||
const auto it = options.find("VOID_ENABLED_MODULES");
|
||||
if (it != options.end()) {
|
||||
const std::string raw = cmake_option_value(it->second);
|
||||
std::size_t pos = 0;
|
||||
while (pos < raw.size()) {
|
||||
const auto sep = raw.find_first_of(";,", pos);
|
||||
std::string_view token = sep == std::string::npos
|
||||
? std::string_view{raw}.substr(pos)
|
||||
: std::string_view{raw}.substr(pos, sep - pos);
|
||||
while (!token.empty() && (token.front() == ' ' || token.front() == '\t' ||
|
||||
token.front() == '\r' || token.front() == '\n')) {
|
||||
token.remove_prefix(1);
|
||||
}
|
||||
while (!token.empty() && (token.back() == ' ' || token.back() == '\t' ||
|
||||
token.back() == '\r' || token.back() == '\n')) {
|
||||
token.remove_suffix(1);
|
||||
}
|
||||
if (!token.empty()) {
|
||||
mods.emplace_back(token);
|
||||
}
|
||||
if (sep == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
pos = sep + 1;
|
||||
}
|
||||
}
|
||||
if (mods.empty()) {
|
||||
mods = {"Configuration", "Text", "Unicode", "Async",
|
||||
"Algorithms", "Crypto", "Archive", "Testing"};
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
|
||||
std::pair<std::vector<std::filesystem::path>, std::vector<std::filesystem::path>>
|
||||
collect_native_dep_snapshot_inputs(const Graph::ProjectDescription &desc,
|
||||
const std::filesystem::path &project_root) {
|
||||
std::error_code ec;
|
||||
const auto canon_root = std::filesystem::weakly_canonical(project_root, ec);
|
||||
const auto &root = ec ? project_root : canon_root;
|
||||
|
||||
std::set<std::filesystem::path> root_dirs;
|
||||
std::set<std::filesystem::path> files;
|
||||
|
||||
auto add_dir_if_in_project = [&](const std::filesystem::path &dir) {
|
||||
std::error_code dec;
|
||||
const auto norm = dir.lexically_normal();
|
||||
if (std::filesystem::is_directory(norm, dec) && Platform::path_is_within(root, norm) &&
|
||||
norm != root) {
|
||||
root_dirs.insert(norm);
|
||||
}
|
||||
};
|
||||
for (const char *d : {"src", "source", "include", "tests"}) {
|
||||
add_dir_if_in_project(root / d);
|
||||
}
|
||||
auto is_gen_ref = [](std::string_view p) {
|
||||
return p.starts_with("$GEN/") || p.starts_with("gen/");
|
||||
};
|
||||
for (const auto &t : desc.targets) {
|
||||
for (const auto &inc : t.include_directories) {
|
||||
if (!is_gen_ref(inc.path)) {
|
||||
const std::filesystem::path p{inc.path};
|
||||
add_dir_if_in_project(p.is_absolute() ? p : (root / p));
|
||||
}
|
||||
}
|
||||
for (const auto &src : t.sources) {
|
||||
if (is_gen_ref(src.path)) {
|
||||
continue;
|
||||
}
|
||||
if (src.kind == SourceKind::File || src.kind == SourceKind::ModuleInterface ||
|
||||
src.kind == SourceKind::ModulePartition || src.kind == SourceKind::HeaderUnit) {
|
||||
const std::filesystem::path p{src.path};
|
||||
const auto abs = (p.is_absolute() ? p : (root / p)).lexically_normal();
|
||||
if (std::filesystem::is_regular_file(abs, ec)) {
|
||||
files.insert(abs);
|
||||
if (abs.has_parent_path()) {
|
||||
add_dir_if_in_project(abs.parent_path());
|
||||
}
|
||||
}
|
||||
} else if (src.kind == SourceKind::Glob) {
|
||||
const auto star = src.path.find_first_of("*?[");
|
||||
const std::string_view prefix = star == std::string::npos
|
||||
? std::string_view{src.path}
|
||||
: std::string_view{src.path}.substr(0, star);
|
||||
const auto slash = prefix.rfind('/');
|
||||
if (slash != std::string_view::npos && slash > 0) {
|
||||
add_dir_if_in_project(root / std::filesystem::path{prefix.substr(0, slash)});
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &in : t.action_inputs) {
|
||||
if (!is_gen_ref(in)) {
|
||||
const std::filesystem::path p{in};
|
||||
const auto abs = (p.is_absolute() ? p : (root / p)).lexically_normal();
|
||||
if (std::filesystem::is_regular_file(abs, ec)) {
|
||||
files.insert(abs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> scan_roots;
|
||||
for (const auto &d : root_dirs) {
|
||||
bool covered = false;
|
||||
for (const auto &other : root_dirs) {
|
||||
if (other != d && Platform::path_is_within(other, d)) {
|
||||
covered = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!covered) {
|
||||
scan_roots.push_back(d);
|
||||
}
|
||||
}
|
||||
std::vector<std::filesystem::path> explicit_files;
|
||||
for (const auto &f : files) {
|
||||
bool covered = false;
|
||||
for (const auto &d : scan_roots) {
|
||||
if (Platform::path_is_within(d, f)) {
|
||||
covered = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!covered) {
|
||||
explicit_files.push_back(f);
|
||||
}
|
||||
}
|
||||
return {std::move(explicit_files), std::move(scan_roots)};
|
||||
}
|
||||
|
||||
Void::Result::Result<ProviderExport, Void::Result::Error>
|
||||
run_native_provider(const ProviderRequest &request, const std::filesystem::path &build_dir,
|
||||
const std::string &input_hash, std::stop_token stop) {
|
||||
std::error_code ec;
|
||||
std::filesystem::remove_all(build_dir, ec);
|
||||
std::filesystem::create_directories(build_dir, ec);
|
||||
|
||||
Graph::ProjectDescription desc;
|
||||
std::optional<Snapshot::InputSnapshot> snap;
|
||||
|
||||
const auto &src_dir = request.source.source_dir;
|
||||
const bool has_build_cpp = std::filesystem::is_regular_file(src_dir / "build.cpp", ec);
|
||||
const bool is_void_library = std::filesystem::is_directory(src_dir / "include" / "Void", ec) &&
|
||||
std::filesystem::is_directory(src_dir / "src" / "Core", ec);
|
||||
|
||||
if (has_build_cpp) {
|
||||
if (request.sdk_include_dir.empty() && request.sdk_source_dir.empty() &&
|
||||
!request.sdk_library_path) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::invalid_argument,
|
||||
"native subproject builder requires VBS SDK "
|
||||
"include/source paths in ProviderRequest")};
|
||||
}
|
||||
Void::Log::info("Provider", "Evaluating native subproject '{}' (profile='{}')...",
|
||||
request.dependency.name, request.profile.name);
|
||||
Config::FrontendOptions fopts;
|
||||
fopts.project_root = src_dir;
|
||||
fopts.build_root = build_dir;
|
||||
fopts.sdk_include_dir = request.sdk_include_dir;
|
||||
fopts.sdk_source_dir = request.sdk_source_dir;
|
||||
if (request.sdk_library_path) {
|
||||
fopts.sdk_library_path = *request.sdk_library_path;
|
||||
}
|
||||
auto compiled = Config::compile_descriptor(fopts);
|
||||
if (!compiled) {
|
||||
return std::unexpected{compiled.error()};
|
||||
}
|
||||
auto eval = Config::evaluate_project(*compiled, request.profile, fopts);
|
||||
if (!eval) {
|
||||
return std::unexpected{eval.error()};
|
||||
}
|
||||
if (!eval->dependencies.empty() || !eval->dependency_files.empty()) {
|
||||
return std::unexpected{make_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
std::format("native subproject '{}' declares nested dependencies which are not "
|
||||
"yet supported",
|
||||
request.dependency.name))};
|
||||
}
|
||||
desc = std::move(*eval);
|
||||
|
||||
const auto [explicit_files, scan_roots] = collect_native_dep_snapshot_inputs(desc, src_dir);
|
||||
Snapshot::SnapshotOptions sopts;
|
||||
sopts.project_root = src_dir;
|
||||
sopts.snapshot_store_dir = build_dir / ".vbs" / "snapshots";
|
||||
sopts.reproducibility_epoch = request.profile.reproducibility_epoch;
|
||||
auto cap = Snapshot::capture_snapshot(sopts, explicit_files, scan_roots);
|
||||
if (!cap) {
|
||||
return std::unexpected{cap.error()};
|
||||
}
|
||||
snap = std::move(*cap);
|
||||
} else if (is_void_library) {
|
||||
const auto mods = parse_void_modules_option(request.dependency.options);
|
||||
Void::Log::info("Provider",
|
||||
"Evaluating native VoidLibrary recipe for '{}' ({} module(s), "
|
||||
"profile='{}')...",
|
||||
request.dependency.name, mods.size(), request.profile.name);
|
||||
Project sub_proj{request.profile};
|
||||
try {
|
||||
(void)Recipes::add_void_library_native(sub_proj, src_dir, mods);
|
||||
} catch (const std::exception &ex) {
|
||||
return std::unexpected{
|
||||
make_error(Void::System::SystemErrorCode::invalid_argument, ex.what())};
|
||||
}
|
||||
auto parsed_desc = Graph::ProjectDescription::from_json(sub_proj.to_json());
|
||||
if (!parsed_desc) {
|
||||
return std::unexpected{parsed_desc.error()};
|
||||
}
|
||||
desc = std::move(*parsed_desc);
|
||||
} else {
|
||||
return std::unexpected{make_error(
|
||||
Void::System::SystemErrorCode::invalid_argument,
|
||||
std::format("native builder for '{}' requires build.cpp or a supported native recipe",
|
||||
request.dependency.name))};
|
||||
}
|
||||
|
||||
auto graph = Graph::lower_project_graph(
|
||||
desc, request.toolchain, {src_dir, build_dir, snap ? &(*snap) : nullptr, {}, 32768});
|
||||
if (!graph) {
|
||||
return std::unexpected{graph.error()};
|
||||
}
|
||||
|
||||
std::vector<std::string> selected_targets;
|
||||
for (const auto &t : desc.targets) {
|
||||
if (!t.enabled) {
|
||||
continue;
|
||||
}
|
||||
if (t.kind == TargetKind::StaticLibrary || t.kind == TargetKind::SharedLibrary ||
|
||||
t.kind == TargetKind::ObjectLibrary || t.kind == TargetKind::CustomAction ||
|
||||
(request.dependency.build_dependency && t.kind == TargetKind::Executable)) {
|
||||
selected_targets.push_back(t.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!selected_targets.empty()) {
|
||||
std::optional<State::StateStore> local_state;
|
||||
State::StateStore *state_ptr = request.shared_state;
|
||||
if (!state_ptr) {
|
||||
auto st = State::StateStore::open(build_dir / ".vbs");
|
||||
if (!st) {
|
||||
return std::unexpected{st.error()};
|
||||
}
|
||||
local_state.emplace(std::move(*st));
|
||||
state_ptr = &(*local_state);
|
||||
}
|
||||
Execution::ExecutionOptions eopts;
|
||||
eopts.jobs = request.jobs;
|
||||
eopts.use_cache = true;
|
||||
eopts.fail_fast = true;
|
||||
eopts.selected_targets = selected_targets;
|
||||
|
||||
const auto sw = Void::Time::Stopwatch::started();
|
||||
Void::Log::info("Provider", "Building native dependency '{}' ({} action(s))...",
|
||||
request.dependency.name, graph->actions.size());
|
||||
auto exec = Execution::execute_graph(*graph, *state_ptr, eopts, stop);
|
||||
if (!exec) {
|
||||
return std::unexpected{exec.error()};
|
||||
}
|
||||
if (!exec->succeeded) {
|
||||
std::string detail;
|
||||
for (const auto &ar : exec->results) {
|
||||
if (!ar.succeeded) {
|
||||
if (!detail.empty()) {
|
||||
detail += '\n';
|
||||
}
|
||||
detail += ar.action_id + ": " + ar.error_message;
|
||||
if (!ar.stderr_data.empty()) {
|
||||
detail += "\n" + ar.stderr_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::unexpected{make_error(
|
||||
Void::System::SystemErrorCode::io_error,
|
||||
std::format("native dependency '{}' build failed:\n{}", request.dependency.name,
|
||||
detail.empty() ? exec->diagnostic : detail))};
|
||||
}
|
||||
Void::Log::info("Provider",
|
||||
"Built native dependency '{}' in {:.2f}s ({} executed, {} cached)",
|
||||
request.dependency.name, sw.elapsed_ms() / 1000.0, exec->executed_count,
|
||||
exec->cached_count);
|
||||
}
|
||||
|
||||
ProviderExport exp;
|
||||
exp.dependency_name = request.dependency.name;
|
||||
exp.builder = "native";
|
||||
exp.input_identity_hash = input_hash;
|
||||
|
||||
std::map<std::string, const TargetRecord *, std::less<>> rec_by_name;
|
||||
for (const auto &t : desc.targets) {
|
||||
rec_by_name[t.name] = &t;
|
||||
}
|
||||
std::map<std::string, const Graph::ResolvedTargetSummary *, std::less<>> summary_by_name;
|
||||
for (const auto &s : graph->targets) {
|
||||
summary_by_name[s.name] = &s;
|
||||
}
|
||||
|
||||
const auto gen_root = graph->profile_build_dir / "gen";
|
||||
auto resolve_inc = [&](const std::string &raw) -> std::filesystem::path {
|
||||
if (raw.starts_with("$GEN/") || raw.starts_with("gen/")) {
|
||||
const auto suffix = raw.starts_with("$GEN/") ? raw.substr(5) : raw.substr(4);
|
||||
return (gen_root / suffix).lexically_normal();
|
||||
}
|
||||
const std::filesystem::path p{raw};
|
||||
return p.is_absolute() ? p.lexically_normal() : (src_dir / p).lexically_normal();
|
||||
};
|
||||
|
||||
for (const auto &t : desc.targets) {
|
||||
if (t.kind != TargetKind::StaticLibrary && t.kind != TargetKind::SharedLibrary &&
|
||||
t.kind != TargetKind::HeaderOnly) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Graph::ImportedTargetInterface iface;
|
||||
iface.dependency_name = request.dependency.name;
|
||||
iface.target_name = t.name;
|
||||
|
||||
std::set<std::string> usage_visited;
|
||||
auto collect_usage = [&](auto &&self, const std::string &cur_name) -> void {
|
||||
if (!usage_visited.insert(cur_name).second) {
|
||||
return;
|
||||
}
|
||||
const auto it = rec_by_name.find(cur_name);
|
||||
if (it == rec_by_name.end()) {
|
||||
return;
|
||||
}
|
||||
const auto &cur = *it->second;
|
||||
if (cur.use_conventional_sources &&
|
||||
std::filesystem::is_directory(src_dir / "include", ec)) {
|
||||
const auto inc = (src_dir / "include").lexically_normal();
|
||||
if (!std::ranges::contains(iface.include_dirs,
|
||||
std::pair<std::filesystem::path, bool>{inc, false})) {
|
||||
iface.include_dirs.emplace_back(inc, false);
|
||||
}
|
||||
}
|
||||
for (const auto &inc : cur.include_directories) {
|
||||
if (inc.visibility != Visibility::Private) {
|
||||
const std::pair<std::filesystem::path, bool> entry{resolve_inc(inc.path),
|
||||
inc.is_system};
|
||||
if (!std::ranges::contains(iface.include_dirs, entry)) {
|
||||
iface.include_dirs.push_back(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &def : cur.defines) {
|
||||
if (def.visibility != Visibility::Private &&
|
||||
!std::ranges::contains(iface.defines, def.value)) {
|
||||
iface.defines.push_back(def.value);
|
||||
}
|
||||
}
|
||||
for (const auto &opt : cur.scoped_compile_options) {
|
||||
if (opt.visibility != Visibility::Private &&
|
||||
!std::ranges::contains(iface.compile_options, opt.value)) {
|
||||
iface.compile_options.push_back(opt.value);
|
||||
}
|
||||
}
|
||||
for (const auto &l : cur.links) {
|
||||
if (l.kind == LinkKind::Local && l.visibility != Visibility::Private) {
|
||||
self(self, l.target);
|
||||
}
|
||||
}
|
||||
};
|
||||
collect_usage(collect_usage, t.name);
|
||||
|
||||
std::vector<std::string> post_order;
|
||||
std::set<std::string> link_visited;
|
||||
auto collect_links = [&](auto &&self, const std::string &cur_name) -> void {
|
||||
if (!link_visited.insert(cur_name).second) {
|
||||
return;
|
||||
}
|
||||
const auto it = rec_by_name.find(cur_name);
|
||||
if (it == rec_by_name.end()) {
|
||||
return;
|
||||
}
|
||||
for (const auto &l : it->second->links) {
|
||||
if (l.kind == LinkKind::Local) {
|
||||
self(self, l.target);
|
||||
}
|
||||
}
|
||||
post_order.push_back(cur_name);
|
||||
};
|
||||
collect_links(collect_links, t.name);
|
||||
|
||||
for (auto rit = post_order.rbegin(); rit != post_order.rend(); ++rit) {
|
||||
const auto rec_it = rec_by_name.find(*rit);
|
||||
const auto sum_it = summary_by_name.find(*rit);
|
||||
if (rec_it != rec_by_name.end()) {
|
||||
for (const auto &lo : rec_it->second->link_options) {
|
||||
if (lo.visibility != Visibility::Private &&
|
||||
!std::ranges::contains(iface.link_options, lo.value)) {
|
||||
iface.link_options.push_back(lo.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rec_it != rec_by_name.end() && sum_it != summary_by_name.end() &&
|
||||
!sum_it->second->primary_outputs.empty()) {
|
||||
const auto &art = sum_it->second->primary_outputs.front();
|
||||
if (rec_it->second->kind == TargetKind::StaticLibrary &&
|
||||
!std::ranges::contains(iface.static_libraries, art)) {
|
||||
iface.static_libraries.push_back(art);
|
||||
} else if (rec_it->second->kind == TargetKind::SharedLibrary &&
|
||||
!std::ranges::contains(iface.shared_libraries, art)) {
|
||||
iface.shared_libraries.push_back(art);
|
||||
if (!std::ranges::contains(iface.runtime_files, art)) {
|
||||
iface.runtime_files.push_back(art);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exp.targets[request.dependency.name + "::" + t.name] = iface;
|
||||
exp.targets[t.name] = iface;
|
||||
if (t.name.starts_with("Void_")) {
|
||||
auto alias = iface;
|
||||
alias.target_name = "Void::" + t.name.substr(5);
|
||||
exp.targets[request.dependency.name + "::" + alias.target_name] = alias;
|
||||
exp.targets[alias.target_name] = std::move(alias);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &[k, v] : request.explicit_overrides) {
|
||||
exp.targets[k] = v;
|
||||
}
|
||||
return exp;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string compute_provider_input_hash(const ProviderRequest &request) {
|
||||
@@ -933,6 +1361,8 @@ resolve_foreign_provider(const ProviderRequest &request, std::stop_token stop) {
|
||||
res = run_meson_provider(request, tool_build_dir, input_hash, stop);
|
||||
} else if (request.dependency.builder == "conan") {
|
||||
res = run_conan_provider(request, tool_build_dir, input_hash, stop);
|
||||
} else if (request.dependency.builder == "native") {
|
||||
res = run_native_provider(request, tool_build_dir, input_hash, stop);
|
||||
}
|
||||
if (!res) {
|
||||
return std::unexpected{res.error()};
|
||||
|
||||
Reference in new issue
Block a user