diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 3642f67..7b192ff 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -286,6 +286,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 96 (Wine-First Windows Target Support)**: `discover_and_probe` selects the MinGW-w64 cross toolchain (`x86_64-w64-mingw32-{g++,gcc,ar}`, or `aarch64` for arm64 targets) when the profile targets Windows from a non-Windows host; Windows targets emit PE artifacts (`.exe`, `.dll`); `vbs build|test` accept `--target-os`/`--target-arch`; `vbs test` runs cross-built Windows test binaries under Wine. Verified end to end: a Windows-target project cross-compiles and its test passes under Wine (`FullV1Tests.track_c_windows_target_cross_build_and_wine_test`, skipped when MinGW/Wine are absent). +- **Wave 97 (Package Generators: ZIP & DEB)**: `vbs install --archive FILE --archive-format zip|deb` now supports a stored (uncompressed) deterministic ZIP and a Debian `ar` package (`debian-binary`, `control.tar`, `data.tar` with Package/Version/Architecture/Maintainer/Installed-Size/Description metadata). `dpkg-deb --info/--contents` validates the generated package. Tests assert the ZIP structure and parse/extract the DEB members. + ## Remaining future scope - **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index a02ecb7..3dc8620 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -100,4 +100,5 @@ Base HEAD: `fe0d1a6` | Wave 94 (Installer script + IDE install tasks) | `--archive-format sh` self-extracting installer executed in tests; VS Code/Zed install tasks | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; install and IDE tests pass, full CTest 8/8) | `include/Void/Build/Install/Installer.hpp`, `src/Install/Installer.cpp`, `src/Main.cpp`, `src/Editor/CompDb.cpp`, `tests/FullV1Tests.cpp`, docs | | Wave 95 (Superiority plan) | Wrote `22-superiority-and-gaps.md`: gap inventory, revised platforms (macOS deferred; Windows via MinGW-w64 + Wine; native MSVC deferred), CMake/Meson/build2 parity table, differentiators, priority order, acceptance gates; refreshed stale roadmap statuses | PLAN WRITTEN (implementation pending) | `docs/roadmap/22-superiority-and-gaps.md`, `docs/roadmap/{README,20,21}.md`, `STATE.md` | | Wave 96 (Wine-first Windows target) | MinGW-w64 cross discovery, PE artifact naming, `--target-os/--target-arch`, Wine test runner | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Windows target cross-build + Wine test pass; full CTest 8/8) | `src/Toolchain/Driver.cpp`, `src/Graph/Graph.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs | +| Wave 97 (ZIP & DEB generators) | `--archive-format zip|deb`: stored ZIP and Debian ar package with metadata; tested structurally and validated with real `dpkg-deb` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; install test passes, full CTest 8/8) | `include/Void/Build/Install/Installer.hpp`, `src/Install/Installer.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 0ae0d12..ba9133d 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1369,6 +1369,26 @@ dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc -p wine64 -c build/pinned/bin/vbs_v1 (8.91 s); it skips when MinGW or Wine is absent. - Full CTest: **8 / 8 passed** in 279.16 s. +## Package Generators: Stored ZIP & DEB (GCC 16.2, pin `0002e74`) + +```sh +dev cpp-gcc -c cmake --build build/pinned --parallel 8 +dev cpp-gcc -c build/pinned/bin/vbs_v1_tests --filter foreign_cmake_meson_providers_bridge_and_relocatable_install --no-color +dev cpp-gcc -p dpkg -c sh -c 'dpkg-deb --info cli_hi.deb; dpkg-deb --contents cli_hi.deb' +dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure +``` + +- `--archive-format zip` produces a stored ZIP containing `bin/cli_hi` and + `share/vbs/CliHiPkg/package.json` with valid local-header/EOCD signatures. +- `--archive-format deb` produces an `ar` package whose first member is `debian-binary` (`2.0\n`), + followed by `control.tar` and `data.tar`; the test extracts both and checks the control fields + and `bin/cli_hi`. +- External validation with real Debian tooling (`dpkg-deb` from `dev cpp-gcc -p dpkg`): + `--info` reports `Package: CliHiPkg`, `Version: 0.1.0`, `Architecture: amd64`, and the + Maintainer/Installed-Size fields; `--contents` lists `bin/cli_hi`, the CMake config files, and + the native package metadata. +- Install test: **passed** (6.45 s); full CTest: **8 / 8 passed** in 282.16 s. + ## Limits and Unrun Checks 1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified). diff --git a/docs/roadmap/22-superiority-and-gaps.md b/docs/roadmap/22-superiority-and-gaps.md index 966abeb..c99e41e 100644 --- a/docs/roadmap/22-superiority-and-gaps.md +++ b/docs/roadmap/22-superiority-and-gaps.md @@ -52,7 +52,7 @@ Concrete work this implies: | Languages | C, C++, CUDA, Fortran, ObjC, ASM, HIP… | C, C++, Rust, D, Fortran, Java… | C/C++ focused | C, C++ | ASM/CUDA/ObjC or a documented extension API | | Toolchains | MSVC, clang-cl, GCC, Clang, Apple, many | GCC, Clang, MSVC, many | GCC, Clang, MSVC | GCC, Clang (Linux) | MinGW target; MSVC deferred | | Package/registry | External (vcpkg, Conan, FetchContent) | wrapdb, subprojects | cppget.org / brep | **Built-in registry + solver + lock + binary variants + signatures + SBOM** | federation, mirrors, key distribution | -| Install/package | `install()`, `install(EXPORT)`, CPack (TGZ/ZIP/DEB/RPM/WIX/DMG/NuGet/APK…) | `install_data`, `install_headers`, dist scripts | install module | prefix staging, components, relocatable CMake + native exports, tar, self-extracting `sh`, SBOM, signing | ZIP, DEB, RPM, MSI/DMG-style, package metadata + signing | +| Install/package | `install()`, `install(EXPORT)`, CPack (TGZ/ZIP/DEB/RPM/WIX/DMG/NuGet/APK…) | `install_data`, `install_headers`, dist scripts | install module | prefix staging, components, relocatable CMake + native exports, tar, self-extracting `sh`, **stored ZIP**, **DEB (dpkg-validated)**, SBOM, signing | RPM, MSI/DMG-style, package signing | | IDE integration | File API, presets, every IDE | `meson-info` introspection | limited | `vbs ide generate/query`, CompDB, daemon protocol | File API shim, `CMakePresets.json` import, plugins | | Test runner | CTest: fixtures, labels, resource locks, timeouts, JUnit/CDash | `meson test`: suites, timeouts, JUnit | test module | `VOID_TEST` runner | fixtures, labels, locks, timeouts, JUnit | | Incremental / cache | compiler depfiles, ccache external | depfiles, ccache | internal caching model | **content-addressed state, immutable snapshots, remote action cache** | scale benchmarks | diff --git a/include/Void/Build/Install/Installer.hpp b/include/Void/Build/Install/Installer.hpp index 69adcd9..6cba9a1 100644 --- a/include/Void/Build/Install/Installer.hpp +++ b/include/Void/Build/Install/Installer.hpp @@ -21,11 +21,13 @@ struct InstallOptions { bool export_native_metadata{true}; // Copies runtime shared libraries of installed targets into /lib. bool bundle_runtime_dependencies{false}; - // Optional deterministic tar archive of the installed prefix (self-contained installer). + // Optional deterministic archive of the installed prefix (self-contained installer). std::optional archive_path; - // When true, archive_path receives an executable POSIX self-extracting installer script - // (tar payload appended) instead of a bare tar. Accepts [--prefix DIR] or $PREFIX. - bool archive_as_script{false}; + // Archive format: "tar" (default), "sh" (self-extracting script with tar payload), + // "zip" (stored, no compression) or "deb" (ar container with control.tar + data.tar). + std::string archive_format{"tar"}; + std::string package_description; // Used by package metadata (deb). + std::string maintainer; // Used by package metadata (deb). }; struct InstallReport { diff --git a/src/Install/Installer.cpp b/src/Install/Installer.cpp index 968061f..dd21dba 100644 --- a/src/Install/Installer.cpp +++ b/src/Install/Installer.cpp @@ -61,6 +61,199 @@ std::string escape_cmake_str(std::string_view s) { return out; } +void put_u16(std::string &out, std::uint16_t value) { + out.push_back(static_cast(value & 0xFFu)); + out.push_back(static_cast((value >> 8) & 0xFFu)); +} + +void put_u32(std::string &out, std::uint32_t value) { + for (int shift = 0; shift < 32; shift += 8) { + out.push_back(static_cast((value >> shift) & 0xFFu)); + } +} + +std::uint32_t crc32_bytes(std::string_view data) { + static const auto table = [] { + std::array t{}; + for (std::uint32_t i = 0; i < 256; ++i) { + std::uint32_t c = i; + for (int k = 0; k < 8; ++k) { + c = (c & 1u) != 0u ? (0xEDB88320u ^ (c >> 1)) : (c >> 1); + } + t[i] = c; + } + return t; + }(); + std::uint32_t crc = 0xFFFFFFFFu; + for (const char ch : data) { + crc = table[(crc ^ static_cast(ch)) & 0xFFu] ^ (crc >> 8); + } + return crc ^ 0xFFFFFFFFu; +} + +// Stored (uncompressed) deterministic ZIP archive of the installed files. +Void::Result::Result +write_stored_zip(const std::filesystem::path &output, + const std::vector &entries) { + struct Record { + std::string name; + std::uint32_t crc{0}; + std::uint32_t size{0}; + std::uint32_t offset{0}; + std::uint32_t mode{0644}; + }; + std::string local; + std::vector records; + for (const auto &entry : entries) { + auto content = Void::FileSystem::read_file(entry.source_file); + if (!content) { + return std::unexpected{content.error()}; + } + const auto crc = crc32_bytes(*content); + const auto size = static_cast(content->size()); + records.push_back( + {entry.archive_path, crc, size, static_cast(local.size()), entry.mode}); + put_u32(local, 0x04034b50u); + put_u16(local, 20); // version needed + put_u16(local, 0); // flags + put_u16(local, 0); // stored + put_u16(local, 0); // time + put_u16(local, 0x21); // 1980-01-01 + put_u32(local, crc); + put_u32(local, size); + put_u32(local, size); + put_u16(local, static_cast(entry.archive_path.size())); + put_u16(local, 0); // extra + local += entry.archive_path; + local += *content; + } + + std::string central; + for (const auto &record : records) { + put_u32(central, 0x02014b50u); + put_u16(central, 0x031e); // made by UNIX + put_u16(central, 20); + put_u16(central, 0); + put_u16(central, 0); + put_u16(central, 0); + put_u16(central, 0x21); + put_u32(central, record.crc); + put_u32(central, record.size); + put_u32(central, record.size); + put_u16(central, static_cast(record.name.size())); + put_u16(central, 0); // extra + put_u16(central, 0); // comment + put_u16(central, 0); // disk + put_u16(central, 0); // internal attrs + put_u32(central, (record.mode & 0777u) << 16); + put_u32(central, record.offset); + central += record.name; + } + + std::string eocd; + put_u32(eocd, 0x06054b50u); + put_u16(eocd, 0); + put_u16(eocd, 0); + put_u16(eocd, static_cast(records.size())); + put_u16(eocd, static_cast(records.size())); + put_u32(eocd, static_cast(central.size())); + put_u32(eocd, static_cast(local.size())); + put_u16(eocd, 0); + + std::string zip = local + central + eocd; + return Platform::atomic_write_file(output, zip, true); +} + +void append_ar_member(std::string &out, std::string_view name, std::string_view data) { + std::string header; + std::string padded_name{name}; + padded_name.push_back('/'); + header.reserve(60); + header += padded_name; + header.resize(16, ' '); + header += std::format("{:<12}", 0); // mtime + header += std::format("{:<6}", 0); // uid + header += std::format("{:<6}", 0); // gid + header += std::format("{:<8}", 100644); // mode + header += std::format("{:<10}", data.size()); // size + header += "`\n"; + out += header; + out += data; + if (data.size() % 2 != 0) { + out.push_back('\n'); + } +} + +// Debian package: ar container with debian-binary, control.tar and data.tar (uncompressed). +Void::Result::Result +write_deb_package(const std::filesystem::path &output, const InstallOptions &options, + const Graph::BuildGraph &graph, + const std::vector &entries) { + const auto scratch = output.parent_path() / (output.filename().string() + ".members"); + std::filesystem::remove_all(scratch); + std::error_code ec; + std::filesystem::create_directories(scratch, ec); + auto cleanup = Void::Scope::on_exit([&] { std::filesystem::remove_all(scratch, ec); }); + + const auto data_tar = scratch / "data.tar"; + auto data = Package::create_deterministic_tar(data_tar, entries, 0); + if (!data) { + return std::unexpected{data.error()}; + } + + std::uint64_t installed_size = 0; + for (const auto &entry : entries) { + if (const auto meta = Platform::stat_lstat(entry.source_file); meta && meta->exists) { + installed_size += meta->size; + } + } + std::string deb_arch = graph.profile.architecture; + std::ranges::transform(deb_arch, deb_arch.begin(), [](char c) { + return static_cast(std::tolower(static_cast(c))); + }); + if (deb_arch == "x86_64") { + deb_arch = "amd64"; + } else if (deb_arch == "aarch64" || deb_arch == "arm64") { + deb_arch = "arm64"; + } + const std::string control_text = + "Package: " + options.package_name + "\n" + "Version: " + options.package_version + "\n" + + "Architecture: " + deb_arch + "\n" + + "Maintainer: " + + (options.maintainer.empty() ? "Void Build " : options.maintainer) + + "\n" + "Installed-Size: " + std::to_string(installed_size / 1024) + "\n" + + "Section: misc\nPriority: optional\n" + "Description: " + + (options.package_description.empty() ? options.package_name + : options.package_description) + + "\n"; + + const auto control_file = scratch / "control"; + if (auto wrote = Platform::atomic_write_file(control_file, control_text, false); !wrote) { + return std::unexpected{wrote.error()}; + } + const auto control_tar = scratch / "control.tar"; + auto control = Package::create_deterministic_tar( + control_tar, {{"control", control_file, 0644u}}, 0); + if (!control) { + return std::unexpected{control.error()}; + } + + auto data_bytes = Void::FileSystem::read_file(data_tar); + if (!data_bytes) { + return std::unexpected{data_bytes.error()}; + } + auto control_bytes = Void::FileSystem::read_file(control_tar); + if (!control_bytes) { + return std::unexpected{control_bytes.error()}; + } + + std::string deb = "!\n"; + append_ar_member(deb, "debian-binary", "2.0\n"); + append_ar_member(deb, "control.tar", *control_bytes); + append_ar_member(deb, "data.tar", *data_bytes); + return Platform::atomic_write_file(output, deb, true); +} + } // namespace Void::Result::Result @@ -394,17 +587,34 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build meta ? (meta->mode & 0777u) : 0644u}); } - const auto archive_target = - options.archive_as_script - ? stage_root / "installer-payload.tar" - : std::filesystem::path{*options.archive_path}; + if (options.archive_format == "zip") { + if (auto zipped = write_stored_zip(*options.archive_path, archive_entries); !zipped) { + return std::unexpected{zipped.error()}; + } + report.archive_path = *options.archive_path; + return report; + } + if (options.archive_format == "deb") { + if (auto packed = write_deb_package(*options.archive_path, options, graph, + archive_entries); + !packed) { + return std::unexpected{packed.error()}; + } + report.archive_path = *options.archive_path; + return report; + } + + const bool archive_as_script = options.archive_format == "sh"; + const auto archive_target = 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) { + if (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" diff --git a/src/Main.cpp b/src/Main.cpp index e4ee942..47c201c 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1723,14 +1723,15 @@ int execute_install_command(const InstallCmdOptions &opts) { iopts.export_cmake_config = !opts.no_cmake_export; iopts.export_native_metadata = !opts.no_native_export; iopts.bundle_runtime_dependencies = opts.bundle_dependencies; - if (opts.archive_format_arg != "tar" && opts.archive_format_arg != "sh") { + if (opts.archive_format_arg != "tar" && opts.archive_format_arg != "sh" && + opts.archive_format_arg != "zip" && opts.archive_format_arg != "deb") { std::cerr << "vbs install: unsupported --archive-format '" << opts.archive_format_arg - << "' (expected tar or sh)\n"; + << "' (expected tar, sh, zip or deb)\n"; return 2; } if (opts.archive_arg && !opts.archive_arg->empty()) { iopts.archive_path = std::filesystem::path{*opts.archive_arg}; - iopts.archive_as_script = opts.archive_format_arg == "sh"; + iopts.archive_format = opts.archive_format_arg; } std::error_code ec; @@ -2872,7 +2873,7 @@ int main(int argc, char **argv) { .option("--archive", "", "Write a deterministic installer archive of the prefix", install_opts.archive_arg) .option_default("--archive-format", "", - "Installer archive format: tar (default) or sh (self-extracting)", + "Installer archive format: tar (default), sh, zip or deb", install_opts.archive_format_arg, "tar"); add_log_flags(install_cmd); diff --git a/tests/FullV1Tests.cpp b/tests/FullV1Tests.cpp index 109130f..67ba607 100644 --- a/tests/FullV1Tests.cpp +++ b/tests/FullV1Tests.cpp @@ -914,6 +914,101 @@ void build(Void::Build::Project &p) { "CliHiPkg" / "package.json")); } + // Stored ZIP package generator. + const auto zip_archive = tmp / "cli_hi.zip"; + auto zip_req = inst_req; + for (auto &arg : zip_req.arguments) { + if (arg == installer_archive.string()) { + arg = zip_archive.string(); + } + } + zip_req.arguments.push_back("--archive-format"); + zip_req.arguments.push_back("zip"); + auto zip_res = Platform::run_supervised(zip_req); + Void::Testing::expect(zip_res.has_value() && zip_res->succeeded()); + auto zip_bytes = Void::FileSystem::read_file(zip_archive); + Void::Testing::require(zip_bytes.has_value()); + const std::string zip_local_sig = std::string{"PK"} + char(3) + char(4); + const std::string zip_eocd_sig = std::string{"PK"} + char(5) + char(6); + Void::Testing::expect(zip_bytes->find(zip_local_sig) != std::string::npos); + Void::Testing::expect(zip_bytes->rfind(zip_eocd_sig) != std::string::npos); + Void::Testing::expect(zip_bytes->find("bin/cli_hi") != std::string::npos); + Void::Testing::expect(zip_bytes->find("share/vbs/CliHiPkg/package.json") != + std::string::npos); + + // Debian package generator: ar(debian-binary, control.tar, data.tar). + const auto deb_archive = tmp / "cli_hi.deb"; + auto deb_req = inst_req; + for (auto &arg : deb_req.arguments) { + if (arg == installer_archive.string()) { + arg = deb_archive.string(); + } + } + deb_req.arguments.push_back("--archive-format"); + deb_req.arguments.push_back("deb"); + auto deb_res = Platform::run_supervised(deb_req); + Void::Testing::expect(deb_res.has_value() && deb_res->succeeded()); + auto deb_bytes = Void::FileSystem::read_file(deb_archive); + Void::Testing::require(deb_bytes.has_value()); + Void::Testing::expect(deb_bytes->starts_with("!\n")); + std::vector> members; + if (deb_bytes->starts_with("!\n")) { + std::size_t pos = 8; + while (pos + 60 <= deb_bytes->size()) { + std::string member_name = deb_bytes->substr(pos, 16); + const auto name_end = member_name.find(' '); + if (name_end != std::string::npos) { + member_name.resize(name_end); + } + if (!member_name.empty() && member_name.back() == '/') { + member_name.pop_back(); + } + std::size_t member_size = 0; + try { + member_size = + static_cast(std::stoul(deb_bytes->substr(pos + 48, 10))); + } catch (...) { + break; + } + members.emplace_back(member_name, deb_bytes->substr(pos + 60, member_size)); + pos += 60 + member_size + (member_size % 2); + } + } + Void::Testing::require(members.size() >= 3); + Void::Testing::expect_eq(members.at(0).first, std::string{"debian-binary"}); + Void::Testing::expect_eq(members.at(0).second, std::string{"2.0\n"}); + const auto find_member = [&](std::string_view name) -> std::optional { + for (const auto &[member_name, content] : members) { + if (member_name == name) { + return content; + } + } + return std::nullopt; + }; + auto control_member = find_member("control.tar"); + Void::Testing::require(control_member.has_value()); + const auto control_out = tmp / "deb_control"; + if (control_member) { + const auto control_tar_path = tmp / "control.tar"; + write_file(control_tar_path, *control_member); + Void::Testing::expect( + Package::extract_safe_tar(control_tar_path, control_out).has_value()); + const auto control_text = Void::FileSystem::read_file(control_out / "control"); + Void::Testing::require(control_text.has_value()); + Void::Testing::expect(control_text->find("Package: CliHiPkg") != std::string::npos); + Void::Testing::expect(control_text->find("Architecture: ") != std::string::npos); + } + auto data_member = find_member("data.tar"); + Void::Testing::require(data_member.has_value()); + const auto data_out = tmp / "deb_data"; + if (data_member) { + const auto data_tar_path = tmp / "data.tar"; + write_file(data_tar_path, *data_member); + Void::Testing::expect( + Package::extract_safe_tar(data_tar_path, data_out).has_value()); + Void::Testing::expect(std::filesystem::exists(data_out / "bin" / "cli_hi")); + } + Platform::ProcessRequest uninst_req; uninst_req.executable = vbs_bin; uninst_req.arguments = {"uninstall", "--prefix", cli_prefix.string()};