feat(daemon): materialize project dependencies for daemon build requests
This commit is contained in:
1 parent
42172a24f8
commit
f5c0c9f09d
12 files changed
+580
-287
No files matched your search
+136
-17
@@ -5,9 +5,14 @@
|
||||
#include <Void/Build/Config/Frontend.hpp>
|
||||
#include <Void/Build/Execution/Scheduler.hpp>
|
||||
#include <Void/Build/Graph/Graph.hpp>
|
||||
#include <Void/Build/Package/Lockfile.hpp>
|
||||
#include <Void/Build/Package/Resolver.hpp>
|
||||
#include <Void/Build/Package/Toml.hpp>
|
||||
#include <Void/Build/Provider/Provider.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
#include <Void/Build/Toolchain/Driver.hpp>
|
||||
#include <Void/Build/Watch/Watcher.hpp>
|
||||
#include <Void/Configuration/Env.hpp>
|
||||
#include <Void/Data/StrictJson.hpp>
|
||||
#include <Void/Functional/Error.hpp>
|
||||
|
||||
@@ -330,7 +335,8 @@ Config::FrontendOptions make_frontend_options(const DaemonOptions &options) {
|
||||
|
||||
struct EvaluatedProject {
|
||||
ProfileContext context;
|
||||
Graph::BuildGraph graph;
|
||||
Graph::ProjectDescription description;
|
||||
Toolchain::ToolchainCapabilities toolchain;
|
||||
};
|
||||
|
||||
// Evaluates the project description in-process and lowers its graph. Workspace roots are
|
||||
@@ -372,19 +378,118 @@ evaluate_project_graph(const DaemonOptions &options, std::string_view profile_na
|
||||
return std::unexpected{std::format("{}: {}", op, toolchain.error().format())};
|
||||
}
|
||||
|
||||
Graph::GraphLowerOptions lower_options;
|
||||
lower_options.project_root = options.project_root;
|
||||
lower_options.build_root = options.build_root;
|
||||
auto graph = Graph::lower_project_graph(*description, *toolchain, lower_options);
|
||||
if (!graph) {
|
||||
return std::unexpected{std::format("{}: {}", op, graph.error().format())};
|
||||
}
|
||||
evaluated.graph = std::move(*graph);
|
||||
evaluated.description = std::move(*description);
|
||||
evaluated.toolchain = std::move(*toolchain);
|
||||
return evaluated;
|
||||
}
|
||||
|
||||
// Bounded build-serving request: lowers the project graph and executes it in-process against the
|
||||
// daemon's warm StateStore. Dependency materialization belongs to `vbs build`/`vbs deps`.
|
||||
Void::Result::Result<Graph::BuildGraph, std::string>
|
||||
lower_graph(const DaemonOptions &options, const EvaluatedProject &evaluated,
|
||||
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> imported_targets,
|
||||
std::string_view op) {
|
||||
Graph::GraphLowerOptions lower_options;
|
||||
lower_options.project_root = options.project_root;
|
||||
lower_options.build_root = options.build_root;
|
||||
lower_options.imported_targets = std::move(imported_targets);
|
||||
auto graph =
|
||||
Graph::lower_project_graph(evaluated.description, evaluated.toolchain, lower_options);
|
||||
if (!graph) {
|
||||
return std::unexpected{std::format("{}: {}", op, graph.error().format())};
|
||||
}
|
||||
return std::move(*graph);
|
||||
}
|
||||
|
||||
// Resolves, materializes, and imports the project's declared dependencies into typed target
|
||||
// interfaces. Returns the number of materialized sources.
|
||||
Void::Result::Result<std::size_t, std::string> materialize_project_dependencies(
|
||||
const DaemonOptions &options, State::StateStore &state, const EvaluatedProject &evaluated,
|
||||
std::size_t jobs,
|
||||
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> &imported_targets) {
|
||||
const auto &description = evaluated.description;
|
||||
if (description.dependencies.empty() && description.dependency_files.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<Package::NormalizedDependency> toml_deps;
|
||||
for (const auto &dep_file : description.dependency_files) {
|
||||
const auto path = std::filesystem::path{dep_file}.is_absolute()
|
||||
? std::filesystem::path{dep_file}
|
||||
: (options.project_root / dep_file);
|
||||
auto loaded = Package::load_dependencies_toml(path);
|
||||
if (!loaded) {
|
||||
return std::unexpected{std::format("build: {}", loaded.error().format())};
|
||||
}
|
||||
toml_deps.insert(toml_deps.end(), loaded->begin(), loaded->end());
|
||||
}
|
||||
auto merged = Package::merge_dependencies(description.dependencies, toml_deps);
|
||||
if (!merged) {
|
||||
return std::unexpected{std::format("build: {}", merged.error().format())};
|
||||
}
|
||||
if (merged->empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto pinned_lock = Package::load_pinned_lock(options.project_root / "vbs.lock");
|
||||
if (!pinned_lock) {
|
||||
return std::unexpected{std::format("build: {}", pinned_lock.error().format())};
|
||||
}
|
||||
Package::ResolveOptions resolve_options;
|
||||
resolve_options.project_root = options.project_root;
|
||||
resolve_options.build_root = options.build_root;
|
||||
resolve_options.pinned_lock = *pinned_lock;
|
||||
resolve_options.default_registry_url = Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
|
||||
resolve_options.registry_auth =
|
||||
Package::RegistryAuth{Void::Configuration::get_env_or("VBS_REGISTRY_TOKEN", "")};
|
||||
auto resolved =
|
||||
Package::resolve_and_materialize_dependencies(evaluated.context, *merged, resolve_options);
|
||||
if (!resolved) {
|
||||
return std::unexpected{std::format("build: {}", resolved.error().format())};
|
||||
}
|
||||
|
||||
const auto frontend = make_frontend_options(options);
|
||||
for (const auto &[dependency, source] : resolved->materialized) {
|
||||
DependencyRecord effective = dependency;
|
||||
std::error_code ec;
|
||||
if (effective.builder.empty()) {
|
||||
if (std::filesystem::is_regular_file(source.source_dir / "build.cpp", ec)) {
|
||||
effective.builder = "native";
|
||||
} else if (std::filesystem::is_regular_file(source.source_dir / "CMakeLists.txt", ec)) {
|
||||
effective.builder = "cmake";
|
||||
} else if (std::filesystem::is_regular_file(source.source_dir / "meson.build", ec)) {
|
||||
effective.builder = "meson";
|
||||
}
|
||||
}
|
||||
if (effective.builder != "cmake" && effective.builder != "meson" &&
|
||||
effective.builder != "conan" && effective.builder != "native") {
|
||||
continue;
|
||||
}
|
||||
Provider::ProviderRequest request{effective,
|
||||
source,
|
||||
evaluated.context,
|
||||
evaluated.toolchain,
|
||||
options.build_root / ".vbs" / "providers",
|
||||
Provider::ProviderMode::FullBuild,
|
||||
{},
|
||||
frontend.sdk_include_dir,
|
||||
frontend.sdk_source_dir,
|
||||
frontend.sdk_library_path.empty()
|
||||
? std::nullopt
|
||||
: std::optional{frontend.sdk_library_path},
|
||||
&state,
|
||||
jobs};
|
||||
auto exported = Provider::resolve_foreign_provider(request);
|
||||
if (!exported) {
|
||||
return std::unexpected{std::format("build: {}", exported.error().format())};
|
||||
}
|
||||
for (const auto &[name, interface] : exported->targets) {
|
||||
imported_targets[name] = interface;
|
||||
}
|
||||
}
|
||||
return resolved->materialized.size();
|
||||
}
|
||||
|
||||
// Bounded build-serving request: resolves dependencies, lowers the project graph, and executes it
|
||||
// in-process against the daemon's warm StateStore.
|
||||
std::string build_project(const DaemonOptions &options, State::StateStore &state,
|
||||
std::string_view profile_name,
|
||||
std::optional<CompilerFamily> compiler_override,
|
||||
@@ -394,10 +499,21 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
|
||||
return error_response(evaluated.error());
|
||||
}
|
||||
|
||||
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> imported_targets;
|
||||
auto materialized =
|
||||
materialize_project_dependencies(options, state, *evaluated, jobs, imported_targets);
|
||||
if (!materialized) {
|
||||
return error_response(materialized.error());
|
||||
}
|
||||
auto graph = lower_graph(options, *evaluated, std::move(imported_targets), "build");
|
||||
if (!graph) {
|
||||
return error_response(graph.error());
|
||||
}
|
||||
|
||||
Execution::ExecutionOptions exec_options;
|
||||
exec_options.jobs = jobs;
|
||||
exec_options.selected_targets = selected_targets;
|
||||
auto report = Execution::execute_graph(evaluated->graph, state, exec_options);
|
||||
auto report = Execution::execute_graph(*graph, state, exec_options);
|
||||
if (!report) {
|
||||
return error_response(std::format("build: {}", report.error().format()));
|
||||
}
|
||||
@@ -417,10 +533,9 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
|
||||
object.emplace("ok", JsonValue{report->succeeded});
|
||||
object.emplace("op", JsonValue{std::string{"build"}});
|
||||
object.emplace("profile", JsonValue{evaluated->context.name});
|
||||
object.emplace("targets",
|
||||
JsonValue{static_cast<std::int64_t>(evaluated->graph.targets.size())});
|
||||
object.emplace("actions",
|
||||
JsonValue{static_cast<std::int64_t>(evaluated->graph.actions.size())});
|
||||
object.emplace("targets", JsonValue{static_cast<std::int64_t>(graph->targets.size())});
|
||||
object.emplace("actions", JsonValue{static_cast<std::int64_t>(graph->actions.size())});
|
||||
object.emplace("dependencies", JsonValue{static_cast<std::int64_t>(*materialized)});
|
||||
object.emplace("executed", JsonValue{static_cast<std::int64_t>(report->executed_count)});
|
||||
object.emplace("cached", JsonValue{static_cast<std::int64_t>(report->cached_count)});
|
||||
object.emplace("failed", JsonValue{static_cast<std::int64_t>(report->failed_count)});
|
||||
@@ -436,7 +551,11 @@ std::string describe_project(const DaemonOptions &options, std::string_view prof
|
||||
if (!evaluated) {
|
||||
return error_response(evaluated.error());
|
||||
}
|
||||
const auto &graph = evaluated->graph;
|
||||
auto lowered = lower_graph(options, *evaluated, {}, "describe");
|
||||
if (!lowered) {
|
||||
return error_response(lowered.error());
|
||||
}
|
||||
const auto &graph = *lowered;
|
||||
const auto &context = evaluated->context;
|
||||
|
||||
std::vector<std::string> target_names;
|
||||
|
||||
Reference in new issue
Block a user