feat(package): download and verify prebuilt binary variants
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 1m5s

This commit is contained in:
faumaray committed 2026-12-03 20:17:17 +03:00
1 parent 118c0dc860
commit 9b405ce772
9 files changed
+199 -3

No files matched your search

+27
View File
@@ -1,5 +1,6 @@
#include <Void/Build/Package/Fetch.hpp>
#include <Void/Build/Package/RegistryClient.hpp>
#include <Void/Build/Platform/FileOps.hpp>
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/Provenance/Verification.hpp>
@@ -172,6 +173,32 @@ select_compatible_signed_binary(const BinaryCompatibilityKey &key,
return *selected;
}
Void::Result::Result<BinaryVariantMeta, Void::Result::Error>
materialize_binary_variant(const BinaryCompatibilityKey &key,
const std::vector<BinaryVariantMeta> &available,
const BinaryFetchOptions &options) {
auto selected = select_compatible_signed_binary(key, available, options.trusted_public_keys);
if (!selected) {
return std::unexpected{selected.error()};
}
const auto destination = options.cache_dir / "binaries" / selected->sha256;
std::error_code ec;
if (std::filesystem::is_regular_file(destination, ec)) {
auto cached_digest = Util::sha256_file_hex(destination);
if (cached_digest && *cached_digest == selected->sha256) {
return *selected;
}
}
std::filesystem::create_directories(destination.parent_path(), ec);
auto downloaded =
download_binary_artifact(selected->download_url, selected->sha256, destination);
if (!downloaded) {
return std::unexpected{downloaded.error()};
}
return *selected;
}
Void::Result::Result<MaterializedSource, Void::Result::Error>
materialize_dependency_source(const DependencyRecord &dep, const FetchOptions &options) {
std::error_code ec;
+31
View File
@@ -379,6 +379,37 @@ download_release_archive(std::string_view registry_url, std::string_view package
return dest_file;
}
Void::Result::Result<std::filesystem::path, Void::Result::Error>
download_binary_artifact(std::string_view url, std::string_view expected_sha256,
const std::filesystem::path &dest_file) {
auto parsed_url = parse_registry_url(url);
if (!parsed_url) {
return std::unexpected{parsed_url.error()};
}
auto reply = send_http_request(*parsed_url, "GET", "", {}, {});
if (!reply) {
return std::unexpected{reply.error()};
}
if (reply->status != 200) {
return std::unexpected{make_error(
reply->status == 404 ? Void::System::SystemErrorCode::not_found
: Void::System::SystemErrorCode::io_error,
std::format("binary artifact GET {} failed with HTTP {}", url, reply->status))};
}
const std::string actual_sha = Util::sha256_hex(reply->body);
if (!expected_sha256.empty() && actual_sha != expected_sha256) {
return std::unexpected{
make_error(Void::System::SystemErrorCode::invalid_argument,
std::format("binary artifact SHA-256 mismatch: expected {}, got {}",
expected_sha256, actual_sha))};
}
auto wrote = Platform::atomic_write_file(dest_file, reply->body, true);
if (!wrote) {
return std::unexpected{wrote.error()};
}
return dest_file;
}
Void::Result::Result<PublishReceipt, Void::Result::Error>
publish_package_archive(const PublishOptions &options) {
if (!Void::Semver::parse_strict(options.version)) {