From ff562acc1ad50687c2ff92de8a64e9e0d8744254 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sun, 6 Dec 2026 16:31:17 +0300 Subject: [PATCH] feat(install): msi installer format compiled from the WiX source 'vbs install --archive-format msi' renders the WiX v3 source with absolute file sources and compiles it with wixl (msitools) or the WiX toolset (candle/light) when available, failing explicitly otherwise. The .wxs intermediate is removed afterwards. Verified locally: wixl produces a valid MSI (OLE compound file, File table with the installed binaries and correct summary information), and the install suite passes with msitools on PATH. CI adds msi to the installer sets when the tooling exists. --- .gitea/workflows/ci.yml | 14 +++++- src/Install/Installer.cpp | 99 ++++++++++++++++++++++++++++++++++++--- src/Main.cpp | 7 +-- tests/FullV1Tests.cpp | 21 +++++++++ 4 files changed, 129 insertions(+), 12 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index bee1eb0..68adfa1 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -317,7 +317,12 @@ jobs: echo "retrying vbs install (${fmt}) in '${build_dir}'..." >&2 done } - for fmt in tar sh zip deb rpm wix dmg nuget; do + for fmt in tar sh zip deb rpm wix msi dmg nuget; do + if [ "${fmt}" = "msi" ] && ! command -v wixl >/dev/null 2>&1 && + ! command -v candle >/dev/null 2>&1; then + echo "skipping msi: wixl or the WiX toolset is not installed" + continue + fi case "${fmt}" in tar) ext=tar ;; wix) ext=wxs ;; @@ -388,7 +393,12 @@ jobs: prefix="$(mktemp -d)" mkdir -p "${out}" build_dir="build/selfhost-windows-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT:-1}" - for fmt in tar zip nuget wix; do + for fmt in tar zip nuget wix msi; do + if [ "${fmt}" = "msi" ] && ! command -v wixl >/dev/null 2>&1 && + ! command -v candle >/dev/null 2>&1; then + echo "skipping msi: wixl or the WiX toolset is not installed" + continue + fi case "${fmt}" in tar) ext=tar ;; wix) ext=wxs ;; diff --git a/src/Install/Installer.cpp b/src/Install/Installer.cpp index 4b5384b..27c58da 100644 --- a/src/Install/Installer.cpp +++ b/src/Install/Installer.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -13,6 +14,7 @@ #include #include +#include #include #include #include @@ -451,10 +453,9 @@ std::string wix_xml_escape(std::string_view text) { return out; } -// WiX v3 source (the CPack WIX model): consumed by candle/light on Windows to produce an MSI. -Void::Result::Result -write_wix_source(const std::filesystem::path &output, const InstallOptions &options, - const std::vector &entries) { +std::string render_wix_source(const InstallOptions &options, + const std::vector &entries, + const std::filesystem::path &source_root) { const std::string product_guid = wix_guid_from("product:" + options.package_name); const std::string upgrade_guid = wix_guid_from("upgrade:" + options.package_name); const std::string manufacturer = @@ -467,6 +468,9 @@ write_wix_source(const std::filesystem::path &output, const InstallOptions &opti const auto rel = std::filesystem::path{entry.archive_path}; files_by_dir[rel.parent_path().generic_string()].push_back(rel.filename().string()); } + const auto source_of = [&source_root](const std::string &rel) { + return source_root.empty() ? rel : (source_root / rel).generic_string(); + }; std::string xml = "\n" @@ -498,7 +502,7 @@ write_wix_source(const std::filesystem::path &output, const InstallOptions &opti xml += " \n" " \n" " \n"; } @@ -521,10 +525,85 @@ write_wix_source(const std::filesystem::path &output, const InstallOptions &opti xml += " \n" " \n" "\n"; - - return Platform::atomic_write_file(output, xml, true); + return xml; } +// WiX v3 source (the CPack WIX model): consumed by candle/light on Windows to produce an MSI. +Void::Result::Result +write_wix_source(const std::filesystem::path &output, const InstallOptions &options, + const std::vector &entries) { + return Platform::atomic_write_file(output, render_wix_source(options, entries, {}), true); +} + +// Compiles the WiX source into an MSI with wixl (msitools) or the WiX toolset. +Void::Result::Result +write_msi_package(const std::filesystem::path &output, const InstallOptions &options, + const std::vector &entries, + const std::filesystem::path &source_root) { + const auto wxs = output.parent_path() / (output.stem().string() + ".wxs"); + if (auto written = + Platform::atomic_write_file(wxs, render_wix_source(options, entries, source_root), + false); + !written) { + return written; + } + std::error_code ec; + const auto cleanup = Void::Scope::on_exit([&] { std::filesystem::remove(wxs, ec); }); + + const auto run_tool = [](const std::filesystem::path &tool, + const std::vector &arguments, + std::string_view what) -> Void::Result::Result { + Platform::ProcessRequest req; + req.executable = tool; + req.arguments = arguments; + req.timeout = std::chrono::minutes{10}; + auto res = Platform::run_supervised(req); + if (!res) { + return std::unexpected{res.error()}; + } + if (!res->succeeded()) { + return std::unexpected{make_error( + Void::System::SystemErrorCode::io_error, + std::format("{} failed (exit {}): {}{}", what, res->exit_code, + res->stdout_data, res->stderr_data))}; + } + return {}; + }; + + if (const auto wixl = Platform::resolve_executable("wixl"); wixl) { + if (auto r = run_tool(*wixl, {"-o", output.string(), wxs.string()}, "wixl"); !r) { + return r; + } + } else if (const auto candle = Platform::resolve_executable("candle"); candle) { + const auto light = Platform::resolve_executable("light"); + if (!light) { + return std::unexpected{make_error( + Void::System::SystemErrorCode::not_found, + "msi packaging requires wixl or the WiX toolset (candle and light)")}; + } + const auto wixobj = output.parent_path() / (output.stem().string() + ".wixobj"); + if (auto r = run_tool(*candle, {"-o", wixobj.string(), wxs.string()}, "candle"); !r) { + return r; + } + auto linked = run_tool(*light, {"-o", output.string(), wixobj.string()}, "light"); + std::filesystem::remove(wixobj, ec); + if (!linked) { + return linked; + } + } else { + return std::unexpected{make_error( + Void::System::SystemErrorCode::not_found, + "msi packaging requires wixl or the WiX toolset (candle and light)")}; + } + if (!std::filesystem::exists(output, ec)) { + return std::unexpected{make_error( + Void::System::SystemErrorCode::io_error, + std::format("msi packaging produced no '{}'", output.string()))}; + } + return {}; +} + + // ── UDIF (DMG) trailer ───────────────────────────────────────────────────────────────────── // A DMG is a data fork (the disk image payload) followed by a 512-byte "koly" trailer. This // writer produces a valid UDIF container whose payload is the deterministic tar of the package; @@ -1205,6 +1284,12 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build !packed) { return std::unexpected{packed.error()}; } + } else if (options.archive_format == "msi") { + if (auto packed = write_msi_package(*options.archive_path, options, archive_entries, + prefix_abs); + !packed) { + return std::unexpected{packed.error()}; + } } else if (options.archive_format == "dmg") { const auto payload = stage_root / "installer-payload.tar"; auto archived = diff --git a/src/Main.cpp b/src/Main.cpp index 92cf9be..38cee8b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -2639,9 +2639,10 @@ int execute_install_command(const InstallCmdOptions &opts) { if (opts.archive_format_arg != "tar" && opts.archive_format_arg != "sh" && opts.archive_format_arg != "zip" && opts.archive_format_arg != "deb" && opts.archive_format_arg != "rpm" && opts.archive_format_arg != "wix" && - opts.archive_format_arg != "dmg" && opts.archive_format_arg != "nuget") { + opts.archive_format_arg != "msi" && opts.archive_format_arg != "dmg" && + opts.archive_format_arg != "nuget") { std::cerr << "vbs install: unsupported --archive-format '" << opts.archive_format_arg - << "' (expected tar, sh, zip, deb, rpm, wix, dmg or nuget)\n"; + << "' (expected tar, sh, zip, deb, rpm, wix, msi, dmg or nuget)\n"; return 2; } if (opts.archive_arg && !opts.archive_arg->empty()) { @@ -3966,7 +3967,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), sh, zip, deb, rpm, wix, dmg or nuget", + "Installer archive format: tar (default), sh, zip, deb, rpm, wix, msi, dmg or nuget", install_opts.archive_format_arg, "tar") .option("--signing-key", "", "Ed25519 seed file; signs the archive and writes .sha256/.sig/.pub", diff --git a/tests/FullV1Tests.cpp b/tests/FullV1Tests.cpp index f6e5e77..1447500 100644 --- a/tests/FullV1Tests.cpp +++ b/tests/FullV1Tests.cpp @@ -1100,6 +1100,27 @@ void build(Void::Build::Project &p) { Void::Testing::expect(wix_text->find("ComponentGroup Id=\"ProductComponents\"") != std::string::npos); + // MSI compiled from the WiX source, when wixl or the WiX toolset is available. + if (Platform::resolve_executable("wixl").has_value() || + Platform::resolve_executable("candle").has_value()) { + const auto msi_archive = tmp / "cli_hi.msi"; + auto msi_req = inst_req; + for (auto &arg : msi_req.arguments) { + if (arg == installer_archive.string()) { + arg = msi_archive.string(); + } + } + msi_req.arguments.push_back("--archive-format"); + msi_req.arguments.push_back("msi"); + auto msi_res = Platform::run_supervised(msi_req); + Void::Testing::expect(msi_res.has_value() && msi_res->succeeded()); + auto msi_bytes = Void::FileSystem::read_file(msi_archive); + Void::Testing::require(msi_bytes.has_value() && msi_bytes->size() > 8); + // OLE compound file magic (the MSI container). + Void::Testing::expect(msi_bytes->substr(0, 8) == + std::string("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1", 8)); + } + // UDIF (DMG-style) container: tar payload followed by a 512-byte koly trailer. const auto dmg_archive = tmp / "cli_hi.dmg"; auto dmg_req = inst_req;