feat(worker): add the vbs remote-execution worker client
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 9s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 14s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 49s

This commit is contained in:
faumaray committed 2026-12-05 11:18:22 +03:00
1 parent 1ae72e4d07
commit 0674b7f9fe
10 files changed
+423 -1

No files matched your search

+131
View File
@@ -1449,6 +1449,117 @@ int execute_compdb_entries_command(const CompdbEntriesCmdOptions &opts) {
return 0;
}
struct WorkerCmdOptions {
std::optional<std::string> registry_arg;
std::optional<std::string> action_key_arg;
std::optional<std::string> record_arg;
std::string project_arg;
std::optional<std::string> build_arg;
std::string token_env{"VBS_REGISTRY_TOKEN"};
std::string lease_seconds_arg{"60"};
};
int execute_worker_command(const WorkerCmdOptions &opts) {
if (!opts.registry_arg || !opts.action_key_arg || !opts.record_arg) {
std::cerr << "vbs worker: --registry, --action-key, and --record are required\n";
return 2;
}
int lease_seconds = 60;
if (!Void::Str::to_int(opts.lease_seconds_arg, lease_seconds) || lease_seconds <= 0 ||
lease_seconds > 3600) {
std::cerr << "vbs worker: invalid --lease-seconds value '" << opts.lease_seconds_arg
<< "'\n";
return 2;
}
const std::string registry = *opts.registry_arg;
const std::string action_key = *opts.action_key_arg;
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
auto record_text = Void::FileSystem::read_file(*opts.record_arg);
if (!record_text) {
std::cerr << "vbs worker: " << record_text.error().message() << '\n';
return 1;
}
auto record_json = Void::Json::Strict::parse(*record_text);
const auto *record_object =
record_json ? std::get_if<Void::Json::Strict::Value::Object>(&record_json->value) : nullptr;
if (record_object == nullptr) {
std::cerr << "vbs worker: --record must contain a JSON object\n";
return 1;
}
const std::filesystem::path project_root{opts.project_arg};
const std::filesystem::path build_root =
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
auto state = State::StateStore::open(build_root / ".vbs");
if (!state) {
std::cerr << "vbs worker: " << state.error().message() << '\n';
return 1;
}
const std::string platform =
Toolchain::host_os_name() + "-" + Toolchain::host_architecture_name();
auto registration = Package::register_worker(registry, platform, auth);
if (!registration) {
std::cerr << "vbs worker: " << registration.error().message() << '\n';
return 1;
}
Void::Log::info("Worker", "Registered as {}", registration->worker_id);
auto leased =
Package::lease_action(registry, action_key, registration->worker_id, lease_seconds, auth);
if (!leased) {
std::cerr << "vbs worker: " << leased.error().message() << '\n';
return 1;
}
Void::Log::info("Worker", "Leased action {} until epoch {}", action_key, leased->expires_epoch);
State::RemoteCacheConfig remote;
remote.url = registry;
remote.bearer_token = auth.bearer_token;
state->configure_remote_cache(remote);
// Publish every referenced output blob, then the action record itself.
if (const auto outputs_it = record_object->find("outputs");
outputs_it != record_object->end()) {
if (const auto *outputs =
std::get_if<Void::Json::Strict::Value::Object>(&outputs_it->second.value)) {
for (const auto &[path, ref] : *outputs) {
const auto *ref_object = std::get_if<Void::Json::Strict::Value::Object>(&ref.value);
if (ref_object == nullptr) {
continue;
}
const auto sha_it = ref_object->find("sha256");
if (sha_it == ref_object->end()) {
continue;
}
const auto *sha = std::get_if<std::string>(&sha_it->second.value);
if (sha == nullptr) {
continue;
}
if (auto published = state->publish_remote_blob(*sha); !published) {
std::cerr << "vbs worker: publishing blob " << *sha << ": "
<< published.error().message() << '\n';
return 1;
}
}
}
}
if (auto published = state->publish_remote_action(action_key, *record_text); !published) {
std::cerr << "vbs worker: publishing action record: " << published.error().message()
<< '\n';
return 1;
}
if (auto submitted = Package::submit_action_result(registry, action_key, leased->lease_token,
*record_text, auth);
!submitted) {
std::cerr << "vbs worker: " << submitted.error().message() << '\n';
return 1;
}
std::cout << "worker " << registration->worker_id << " completed action " << action_key << '\n';
return 0;
}
struct MigrateCmdOptions {
std::string input_arg{"CMakeLists.txt"};
std::string output_arg{"build.cpp"};
@@ -2950,6 +3061,8 @@ int main(int argc, char **argv) {
VerifyCmdOptions verify_opts;
PresetsCmdOptions presets_opts;
MigrateCmdOptions migrate_opts;
WorkerCmdOptions worker_opts;
worker_opts.project_arg = cwd;
CompdbEntriesCmdOptions compdb_entries_opts;
publish_opts.project_arg = cwd;
BridgeCmdOptions bridge_opts;
@@ -3163,6 +3276,21 @@ int main(int argc, char **argv) {
verify_opts.trusted_key_files);
add_log_flags(verify_cmd, false); // `-v` is `--version` on verify.
auto &worker_cmd = root.subcommand(
"worker", "Run one remote-execution worker step (lease, publish, result upload)");
worker_cmd
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
worker_opts.registry_arg)
.option("--action-key", "", "Action key to lease and publish", worker_opts.action_key_arg)
.option("--record", "", "Action record JSON file to publish", worker_opts.record_arg)
.option_default("--project", "-C", "Project directory", worker_opts.project_arg, cwd)
.option("--build-dir", "-B", "Build directory", worker_opts.build_arg)
.option_default("--token-env", "", "Environment variable holding bearer token",
worker_opts.token_env, "VBS_REGISTRY_TOKEN")
.option_default("--lease-seconds", "", "Lease TTL in seconds (1..3600)",
worker_opts.lease_seconds_arg, "60");
add_log_flags(worker_cmd);
auto &migrate_cmd = root.subcommand(
"migrate", "Generate a build.cpp scaffold from a CMakeLists.txt (bounded subset)");
migrate_cmd
@@ -3666,6 +3794,9 @@ int main(int argc, char **argv) {
if (cmd == "migrate") {
return execute_migrate_command(migrate_opts);
}
if (cmd == "worker") {
return execute_worker_command(worker_opts);
}
if (cmd == "compdb-entries") {
return execute_compdb_entries_command(compdb_entries_opts);
}