feat: adopt VoidLibrary VL-001..VL-013, self-building build.cpp, live logs, and generated CLI help
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 10s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 10s
This commit is contained in:
1 parent
ab64147f9d
commit
363fb8200e
33 files changed
+1754
-3155
No files matched your search
+192
-17
@@ -5,8 +5,10 @@
|
||||
#include <Void/Build/Util/Json.hpp>
|
||||
#include <Void/Build/Util/Sha256.hpp>
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include <Void/System/Path.hpp>
|
||||
#include <Void/System/Types.hpp>
|
||||
#include <Void/Time/Stopwatch.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
@@ -237,6 +239,9 @@ run_cmake_provider(const ProviderRequest &request, const std::filesystem::path &
|
||||
build_dir / ".cmake" / "api" / "v1" / "query" / "codemodel-v2", "", false);
|
||||
|
||||
// 1. Configure with isolated profile/toolchain context.
|
||||
const auto sw = Void::Time::Stopwatch::started();
|
||||
Void::Log::info("Provider", "Configuring CMake dependency '{}' (profile='{}')...",
|
||||
request.dependency.name, request.profile.name);
|
||||
{
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = *cmake_bin;
|
||||
@@ -254,6 +259,14 @@ run_cmake_provider(const ProviderRequest &request, const std::filesystem::path &
|
||||
req.arguments.push_back("-D" + k + "=" + cmake_option_value(v));
|
||||
}
|
||||
req.timeout = std::chrono::seconds{180};
|
||||
if (Void::Log::enabled(Void::Log::Level::Debug, "Provider")) {
|
||||
req.on_stdout_chunk = [&](std::string_view line) {
|
||||
Void::Log::debug("Provider", "[cmake:{}] {}", request.dependency.name, line);
|
||||
};
|
||||
req.on_stderr_chunk = [&](std::string_view line) {
|
||||
Void::Log::debug("Provider", "[cmake:{}] {}", request.dependency.name, line);
|
||||
};
|
||||
}
|
||||
auto proc = Platform::run_supervised(req, stop);
|
||||
if (!proc || !proc->succeeded()) {
|
||||
return std::unexpected{make_error(
|
||||
@@ -265,11 +278,20 @@ run_cmake_provider(const ProviderRequest &request, const std::filesystem::path &
|
||||
}
|
||||
|
||||
// 2. Build all targets in isolated build directory.
|
||||
Void::Log::info("Provider", "Building CMake dependency '{}'...", request.dependency.name);
|
||||
{
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = *cmake_bin;
|
||||
req.arguments = {"--build", build_dir.string()};
|
||||
req.arguments = {"--build", build_dir.string(), "--parallel"};
|
||||
req.timeout = std::chrono::seconds{300};
|
||||
if (Void::Log::enabled(Void::Log::Level::Debug, "Provider")) {
|
||||
req.on_stdout_chunk = [&](std::string_view line) {
|
||||
Void::Log::debug("Provider", "[build:{}] {}", request.dependency.name, line);
|
||||
};
|
||||
req.on_stderr_chunk = [&](std::string_view line) {
|
||||
Void::Log::debug("Provider", "[build:{}] {}", request.dependency.name, line);
|
||||
};
|
||||
}
|
||||
auto proc = Platform::run_supervised(req, stop);
|
||||
if (!proc || !proc->succeeded()) {
|
||||
return std::unexpected{
|
||||
@@ -435,6 +457,37 @@ run_cmake_provider(const ProviderRequest &request, const std::filesystem::path &
|
||||
}
|
||||
}
|
||||
|
||||
// Extract link command fragments (-pthread, -ldl, -lm, etc.).
|
||||
if (const auto *lnk = find_key(*td, "link")) {
|
||||
if (const auto *lobj =
|
||||
std::get_if<JsonVal::Object>(&lnk->value)) {
|
||||
if (const auto *frags =
|
||||
find_key(*lobj, "commandFragments")) {
|
||||
if (const auto *farr =
|
||||
std::get_if<JsonVal::Array>(&frags->value)) {
|
||||
for (const auto &fv : *farr) {
|
||||
const auto *fo =
|
||||
std::get_if<JsonVal::Object>(&fv.value);
|
||||
if (!fo) {
|
||||
continue;
|
||||
}
|
||||
const auto role = get_str(*fo, "role");
|
||||
const auto frag = get_str(*fo, "fragment");
|
||||
if ((role == "libraries" || role == "flags") &&
|
||||
(frag == "-pthread" ||
|
||||
frag == "-lpthread" || frag == "-ldl" ||
|
||||
frag == "-lm" || frag == "-lrt")) {
|
||||
if (!std::ranges::contains(
|
||||
rt.iface.link_options, frag)) {
|
||||
rt.iface.link_options.push_back(frag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract dependencies for transitive static archive ordering.
|
||||
if (const auto *deps = find_key(*td, "dependencies")) {
|
||||
if (const auto *darr =
|
||||
@@ -457,7 +510,8 @@ run_cmake_provider(const ProviderRequest &request, const std::filesystem::path &
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve transitive static library link order across CMake targets.
|
||||
// Resolve transitive static library link order across CMake targets using post-order DFS
|
||||
// reversed so every dependent library strictly precedes all of its dependencies on `ld`.
|
||||
ProviderExport exp;
|
||||
exp.dependency_name = request.dependency.name;
|
||||
exp.builder = "cmake";
|
||||
@@ -465,36 +519,157 @@ run_cmake_provider(const ProviderRequest &request, const std::filesystem::path &
|
||||
|
||||
for (const auto &[id, rt] : raw_by_id) {
|
||||
Graph::ImportedTargetInterface resolved = rt.iface;
|
||||
std::set<std::string> visited{id};
|
||||
std::vector<std::string> queue = rt.dep_ids;
|
||||
for (std::size_t qi = 0; qi < queue.size(); ++qi) {
|
||||
const auto &dep_id = queue[qi];
|
||||
if (!visited.insert(dep_id).second) {
|
||||
continue;
|
||||
std::vector<std::string> post_order;
|
||||
std::set<std::string> visited;
|
||||
auto dfs = [&](auto &&self, const std::string &cur_id) -> void {
|
||||
if (!visited.insert(cur_id).second) {
|
||||
return;
|
||||
}
|
||||
const auto dit = raw_by_id.find(dep_id);
|
||||
const auto dit = raw_by_id.find(cur_id);
|
||||
if (dit == raw_by_id.end()) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
for (const auto &lib : dit->second.iface.static_libraries) {
|
||||
resolved.static_libraries.push_back(lib);
|
||||
for (const auto &sub : dit->second.dep_ids) {
|
||||
self(self, sub);
|
||||
}
|
||||
for (const auto &lib : dit->second.iface.shared_libraries) {
|
||||
resolved.shared_libraries.push_back(lib);
|
||||
post_order.push_back(cur_id);
|
||||
};
|
||||
for (const auto &dep_id : rt.dep_ids) {
|
||||
dfs(dfs, dep_id);
|
||||
}
|
||||
std::ranges::reverse(post_order);
|
||||
for (const auto &dep_id : post_order) {
|
||||
const auto &dep_rt = raw_by_id.at(dep_id);
|
||||
for (const auto &lib : dep_rt.iface.static_libraries) {
|
||||
if (!std::ranges::contains(resolved.static_libraries, lib)) {
|
||||
resolved.static_libraries.push_back(lib);
|
||||
}
|
||||
}
|
||||
for (const auto &inc : dit->second.iface.include_dirs) {
|
||||
for (const auto &lib : dep_rt.iface.shared_libraries) {
|
||||
if (!std::ranges::contains(resolved.shared_libraries, lib)) {
|
||||
resolved.shared_libraries.push_back(lib);
|
||||
}
|
||||
}
|
||||
for (const auto &inc : dep_rt.iface.include_dirs) {
|
||||
if (!std::ranges::contains(resolved.include_dirs, inc)) {
|
||||
resolved.include_dirs.push_back(inc);
|
||||
}
|
||||
}
|
||||
for (const auto &sub : dit->second.dep_ids) {
|
||||
queue.push_back(sub);
|
||||
for (const auto &def : dep_rt.iface.defines) {
|
||||
if (!std::ranges::contains(resolved.defines, def)) {
|
||||
resolved.defines.push_back(def);
|
||||
}
|
||||
}
|
||||
for (const auto &lo : dep_rt.iface.link_options) {
|
||||
if (!std::ranges::contains(resolved.link_options, lo)) {
|
||||
resolved.link_options.push_back(lo);
|
||||
}
|
||||
}
|
||||
}
|
||||
// CMake targets linking Threads::Threads on GCC need -pthread at final link time.
|
||||
if ((rt.name.starts_with("Void_") || request.dependency.name == "VoidLibrary") &&
|
||||
!std::ranges::contains(resolved.link_options, std::string{"-pthread"})) {
|
||||
resolved.link_options.push_back("-pthread");
|
||||
}
|
||||
|
||||
exp.targets[rt.name] = resolved;
|
||||
exp.targets[request.dependency.name + "::" + rt.name] = resolved;
|
||||
// Register CMake `Namespace::Component` alias convention (e.g. `Void_Configuration` ->
|
||||
// `Void::Configuration`) because CMake File API codemodel-v2 omits ALIAS targets.
|
||||
if (const auto us = rt.name.find('_'); us != std::string::npos && us > 0) {
|
||||
const std::string alias = rt.name.substr(0, us) + "::" + rt.name.substr(us + 1);
|
||||
exp.targets[alias] = resolved;
|
||||
exp.targets[request.dependency.name + "::" + alias] = resolved;
|
||||
}
|
||||
}
|
||||
|
||||
// CMake File API codemodel-v2 omits INTERFACE (header-only) libraries. For VoidLibrary,
|
||||
// synthesize `Void::<Mod>` interfaces for any module directory under `src/` that CMake
|
||||
// configured as header-only (e.g. Text, Unicode, Async, Algorithms, Core, Data, Time,
|
||||
// Functional), propagating compiled `INTERNAL_DEPS` (such as LogState) automatically.
|
||||
if (request.dependency.name == "VoidLibrary" &&
|
||||
std::filesystem::is_directory(request.source.source_dir / "include", ec) &&
|
||||
std::filesystem::is_directory(request.source.source_dir / "src", ec)) {
|
||||
std::vector<std::string> hdr_mods;
|
||||
for (const auto &entry :
|
||||
std::filesystem::directory_iterator(request.source.source_dir / "src", ec)) {
|
||||
if (!entry.is_directory(ec)) {
|
||||
continue;
|
||||
}
|
||||
const std::string mod = entry.path().filename().string();
|
||||
const std::string alias = "Void::" + mod;
|
||||
if (!exp.targets.contains(alias)) {
|
||||
hdr_mods.push_back(mod);
|
||||
Graph::ImportedTargetInterface hi;
|
||||
hi.dependency_name = request.dependency.name;
|
||||
hi.target_name = alias;
|
||||
hi.include_dirs.emplace_back(request.source.source_dir / "include", false);
|
||||
hi.link_options.push_back("-pthread");
|
||||
exp.targets[alias] = hi;
|
||||
exp.targets[request.dependency.name + "::" + alias] = std::move(hi);
|
||||
}
|
||||
}
|
||||
// Attach compiled INTERNAL_DEPS (e.g. Void_LogState for Async/Log) to synthesized
|
||||
// header-only targets so linking any header-only Void module standalone works cleanly.
|
||||
for (const auto &mod : hdr_mods) {
|
||||
const auto mod_cmake = request.source.source_dir / "src" / mod / "module.cmake";
|
||||
if (!std::filesystem::is_regular_file(mod_cmake, ec)) {
|
||||
continue;
|
||||
}
|
||||
auto text = Void::FileSystem::read_file(mod_cmake);
|
||||
if (!text) {
|
||||
continue;
|
||||
}
|
||||
const auto pos = text->find("INTERNAL_DEPS");
|
||||
if (pos == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
const std::string alias = "Void::" + mod;
|
||||
auto &hi = exp.targets[alias];
|
||||
const std::string_view rest = std::string_view{*text}.substr(pos + 13);
|
||||
std::size_t idx = 0;
|
||||
while (idx < rest.size()) {
|
||||
while (idx < rest.size() && (rest[idx] == ' ' || rest[idx] == '\t' ||
|
||||
rest[idx] == '\r' || rest[idx] == '\n')) {
|
||||
++idx;
|
||||
}
|
||||
if (idx >= rest.size() || rest[idx] == ')') {
|
||||
break;
|
||||
}
|
||||
const std::size_t start = idx;
|
||||
while (idx < rest.size() && rest[idx] != ' ' && rest[idx] != '\t' &&
|
||||
rest[idx] != '\r' && rest[idx] != '\n' && rest[idx] != ')') {
|
||||
++idx;
|
||||
}
|
||||
const std::string dep_name{rest.substr(start, idx - start)};
|
||||
if (dep_name == "EXTERNAL_DEPS" || dep_name == "OPTIONAL_DEPS" ||
|
||||
dep_name == "DEPS_WIN32" || dep_name == "DEPS_UNIX" ||
|
||||
dep_name == "OPTIONS_WIN32" || dep_name == "OPTIONS_UNIX" ||
|
||||
dep_name == "EXTRA_HEADERS" || dep_name == "EXCLUDE_HEADERS") {
|
||||
break;
|
||||
}
|
||||
const auto dit = exp.targets.find("Void::" + dep_name);
|
||||
if (dit != exp.targets.end()) {
|
||||
for (const auto &lib : dit->second.static_libraries) {
|
||||
if (!std::ranges::contains(hi.static_libraries, lib)) {
|
||||
hi.static_libraries.push_back(lib);
|
||||
}
|
||||
}
|
||||
for (const auto &def : dit->second.defines) {
|
||||
if (!std::ranges::contains(hi.defines, def)) {
|
||||
hi.defines.push_back(def);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exp.targets[request.dependency.name + "::" + alias] = hi;
|
||||
}
|
||||
}
|
||||
|
||||
Void::Log::info("Provider", "CMake dependency '{}' ready ({} targets in {}ms)",
|
||||
request.dependency.name, exp.targets.size(),
|
||||
sw.elapsed_as<std::chrono::milliseconds>().count());
|
||||
|
||||
// Apply explicit user overrides if supplied.
|
||||
for (const auto &[k, v] : request.explicit_overrides) {
|
||||
exp.targets[k] = v;
|
||||
|
||||
Reference in new issue
Block a user