feat(install,ide): self-extracting installers and install tasks
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 8s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 11s

This commit is contained in:
faumaray committed 2026-12-05 03:45:09 +03:00
1 parent 83ec08390f
commit d23a878eec
9 files changed
+232 -5

No files matched your search

+87
View File
@@ -1,5 +1,6 @@
#include <Void/Build/Install/Installer.hpp>
#include <Void/Build/Package/Archive.hpp>
#include <Void/Build/Platform/FileOps.hpp>
#include <Void/Build/Util/Json.hpp>
#include <Void/Build/Util/Sha256.hpp>
@@ -128,6 +129,8 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
std::vector<std::string> local_deps;
};
std::vector<ExportedTarget> exported_targets;
std::set<std::string> bundled_library_names;
std::vector<std::filesystem::path> bundled_libraries;
for (const auto &trec : description.targets) {
if (!trec.install_rule) {
@@ -177,6 +180,20 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
}
et.rel_artifact = rel_dest;
}
// Bundle runtime shared libraries so the prefix is self-contained.
if (options.bundle_runtime_dependencies) {
for (const auto &library_path : sum_it->runtime_shared_libraries) {
const std::string filename = library_path.filename().string();
if (!bundled_library_names.insert(filename).second) {
continue;
}
const auto rel_dest = std::filesystem::path{"lib"} / filename;
if (auto r = add_item(library_path, rel_dest, 0755u, trec.name); !r) {
return std::unexpected{r.error()};
}
bundled_libraries.push_back(library_path);
}
}
exported_targets.push_back(std::move(et));
}
@@ -364,6 +381,76 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
if (!mw) {
return std::unexpected{mw.error()};
}
report.bundled_libraries = std::move(bundled_libraries);
// 7. Optional deterministic installer archive of the published prefix.
if (options.archive_path) {
std::vector<Package::ArchiveEntrySpec> archive_entries;
archive_entries.reserve(report.installed_files.size());
for (const auto &file : report.installed_files) {
const auto meta = Platform::stat_lstat(file);
archive_entries.push_back(
{file.lexically_relative(prefix_abs).generic_string(), file,
meta ? (meta->mode & 0777u) : 0644u});
}
const auto archive_target =
options.archive_as_script
? stage_root / "installer-payload.tar"
: std::filesystem::path{*options.archive_path};
auto archived = Package::create_deterministic_tar(archive_target,
std::move(archive_entries), 0);
if (!archived) {
return std::unexpected{archived.error()};
}
if (options.archive_as_script) {
// Self-extracting installer: a POSIX sh header followed by the tar payload.
const auto make_header = [&](std::size_t payload_line) {
return "#!/bin/sh\n"
"# VoidBuildSystem self-extracting installer for " +
options.package_name + " " + options.package_version +
"\n"
"# Usage: sh <installer> [--prefix DIR] (default: ${PREFIX:-/usr/local})\n"
"set -eu\n"
"prefix=\"${PREFIX:-/usr/local}\"\n"
"if [ \"${1:-}\" = \"--prefix\" ]; then\n"
" prefix=\"${2:?--prefix requires a directory}\"\n"
"fi\n"
"tmp=\"$(mktemp -d)\"\n"
"trap 'rm -rf \"$tmp\"' EXIT\n"
"tail -n +" +
std::to_string(payload_line) +
" \"$0\" > \"$tmp/payload.tar\"\n"
"mkdir -p \"$prefix\"\n"
"tar -x -f \"$tmp/payload.tar\" -C \"$prefix\"\n"
"echo \"installed " +
options.package_name +
" to $prefix\"\n"
"exit 0\n";
};
std::size_t header_lines = 0;
for (const char c : make_header(0)) {
if (c == '\n') {
++header_lines;
}
}
const std::string header = make_header(header_lines + 1);
auto payload = Void::FileSystem::read_file(archive_target);
if (!payload) {
return std::unexpected{payload.error()};
}
std::string script = header;
script += *payload;
if (auto written =
Platform::atomic_write_file(*options.archive_path, script, true, 0755);
!written) {
return std::unexpected{written.error()};
}
}
report.archive_path = *options.archive_path;
}
return report;
}