diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59dba96..5e49137 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1283,6 +1283,53 @@ jobs: # the compiled build program's actual behaviour under the exact # environment contract `--target aarch64-ios-sim --format app` and the # device row would set, run directly rather than through mcpp. + - name: dist-deb and dist-rpm produce packages that carry the program, reproducibly + working-directory: tests/linux-package-consumer + run: | + # A plain build has no distribution edge, yet both formats are known. + "$MCPP" build + if find target -name '*.deb' -o -name '*.rpm' | grep -q .; then + echo "FAIL: a plain build produced a package"; exit 1 + fi + set +e + se=$("$MCPP" pack --pkg-format bogus 2>&1 >/dev/null) + set -e + grep -qE 'available in this build: .*\bdeb\b' <<<"$se" && grep -qE 'available in this build: .*\brpm\b' <<<"$se" \ + || { echo "FAIL: the refusal does not name deb and rpm"; echo "$se"; exit 1; } + + "$MCPP" pack --pkg-format deb | tee pack-deb.log + "$MCPP" pack --pkg-format rpm | tee pack-rpm.log + deb=$(find target -name 'linux-package-consumer_0.4.0_*.deb' | head -1) + rpm=$(find target -name 'linux-package-consumer-0.4.0-1.*.rpm' | head -1) + test -n "$deb" && test -n "$rpm" || { echo "FAIL: no package was produced"; exit 1; } + + # The control fields come from [package], and the dependency the project stated is recorded. + dpkg-deb --field "$deb" Package Version Maintainer Depends | tee fields.log + grep -q '^Maintainer: mcpp-community <' fields.log && grep -q '^Depends: bash' fields.log \ + || { echo "FAIL: the deb's control fields"; exit 1; } + rpm -qp --requires "$rpm" | grep -qx bash || { echo "FAIL: the rpm does not require bash"; exit 1; } + + # The same files in both, and the installed program runs through /usr/bin. + dpkg-deb --contents "$deb" | awk '{print $6}' | sed 's|^\./|/|' | grep -v '/$' | sort > deb-files.txt + rpm -qlp "$rpm" | sort > rpm-files.txt + diff deb-files.txt rpm-files.txt || { echo "FAIL: deb and rpm carry different files"; exit 1; } + for f in /usr/bin/linux-package-consumer /usr/share/applications/linux-package-consumer.desktop \ + /usr/share/icons/hicolor/scalable/apps/linux-package-consumer.svg; do + grep -qx "$f" deb-files.txt || { echo "FAIL: $f is not in the package"; exit 1; } + done + sudo dpkg -i "$deb" + linux-package-consumer | tee run.log + grep -q '^linux-package-consumer ok' run.log || { echo "FAIL: the installed program did not run"; exit 1; } + sudo dpkg -r linux-package-consumer + + # Re-staging an unchanged program gives the same bytes. + before=$(sha256sum "$deb" "$rpm") + touch src/main.cpp + "$MCPP" pack --pkg-format deb > /dev/null + "$MCPP" pack --pkg-format rpm > /dev/null + [ "$before" = "$(sha256sum "$deb" "$rpm")" ] || { echo "FAIL: repacking changed the packages"; exit 1; } + echo "ok: deb and rpm" + - name: dist-apple's iOS row, checked at the plan level working-directory: tests/ios-app-consumer run: MCPP="$MCPP" ./check-ios-plan.sh diff --git a/README.md b/README.md index 228af8e..e086052 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ module name the member declares, and configures it there. ```toml [build-dependencies.mcpp] -plugins = { version = "0.22.1", features = ["rules-spirv"], host-module = true } +plugins = { version = "0.23.0", features = ["rules-spirv"], host-module = true } ``` ```cpp @@ -76,6 +76,8 @@ mcpp 2026.11.7.1 or later; cross configuration requires CMake 3.19 or later. | `tools-embed` | `mcpp.tools.embed` | 2026.9.5.4 | Writes a data file into a header the program compiles in. | [tools-embed](docs/tools-embed.md) | | `tools-island` | `mcpp.tools.island` | 2026.9.7.1 | Generates the `extern "C"` boundary and the C++ module of a code island. | [tools-island](docs/tools-island.md) | | `dist-appimage` | `mcpp.dist.appimage` | 2026.10.1.3 | Turns the tree `mcpp pack` stages into an AppImage (Linux). | [dist](docs/dist.md#dist-appimage) | +| `dist-deb` | `mcpp.dist.deb` | 2026.10.30.1 | Installs the staged tree under `/opt/` with a launcher, a desktop entry and an icon, as a Debian package (Linux targets). | [dist](docs/dist.md#dist-deb-and-dist-rpm) | +| `dist-rpm` | `mcpp.dist.rpm` | 2026.10.30.1 | The same installation as an RPM package (Linux targets). | [dist](docs/dist.md#dist-deb-and-dist-rpm) | | `dist-wix` | `mcpp.dist.wix` | 2026.10.1.3 | Builds an MSI of the staged tree, and a Burn bundle chaining it (Windows). | [dist](docs/dist.md#dist-wix) | | `dist-apple` | `mcpp.dist.apple` | 2026.9.14.2 | Lays out a macOS or iOS application bundle, signs it and writes a disk image. | [dist-apple](docs/dist-apple.md) | | `dist-web` | `mcpp.dist.web` | 2026.9.13.1 | Copies a `wasm32-emscripten` program and its files into a web directory with an `index.html`. | [dist](docs/dist.md#dist-web) | diff --git a/dist/deb.cppm b/dist/deb.cppm new file mode 100644 index 0000000..75ae0fd --- /dev/null +++ b/dist/deb.cppm @@ -0,0 +1,33 @@ +// mcpp.dist.deb -- a staged program becomes a Debian package for Debian, Ubuntu, and their derivatives. +// +// The layout and the writer are shared with the other Linux package format in +// `mcpp.dist.linux_package`: the staged closure under `/opt/`, a +// launcher in `/usr/bin`, a desktop entry and an icon, written by nfpm from +// the `xim:nfpm` payload, so the host needs no `dpkg-deb`. + +export module mcpp.dist.deb; + +import std; +export import mcpp.dist.linux_package; + +export namespace mcpp::dist::deb { + +using options = mcpp::dist::linux_package::options; +using plan = mcpp::dist::linux_package::plan; + +// What `generate` would submit for `mcpp pack --format deb`, without submitting it. +inline plan plan_for(options opt = {}) { + return mcpp::dist::linux_package::plan_for("deb", std::move(opt)); +} + +inline bool submit(const plan& p) { + return mcpp::dist::linux_package::submit(p); +} + +// The one call a build program makes: declares the `deb` format in every pass +// and submits the package action when `mcpp pack --format deb` asked for it. +inline bool generate(options opt = {}) { + return mcpp::dist::linux_package::generate("deb", std::move(opt)); +} + +} // namespace mcpp::dist::deb diff --git a/dist/linux-package.cppm b/dist/linux-package.cppm new file mode 100644 index 0000000..c09a2a4 --- /dev/null +++ b/dist/linux-package.cppm @@ -0,0 +1,425 @@ +// mcpp.dist.linux_package -- a staged program becomes a deb or an rpm. +// +// ONE MODULE FOR TWO FORMATS, BECAUSE THE TWO DIFFER ONLY IN THE WRITER. +// `dist-deb` and `dist-rpm` place the same files at the same paths; what a +// Debian package and an RPM package disagree about -- the archive layout, the +// control fields' spelling, the architecture's name -- is the packaging +// tool's business, not the member's. The tool is nfpm, which writes both from +// one description, so neither member depends on the host's `dpkg-deb` or +// `rpmbuild` and both run on every host the `xim:nfpm` payload exists for. +// +// THE CLOSURE GOES UNDER A PRIVATE PREFIX. `mcpp pack` stages the program, +// the libraries it loads, and its launcher as one relocatable tree. The +// package installs that tree as it is below `/opt/` and adds +// `/usr/bin/`, which execs the tree's launcher, a desktop entry, and +// an icon. Distribution-style packaging -- one file per FHS directory and +// dependencies on the distribution's own library packages -- needs a mapping +// from each staged library to the package that provides it on each +// distribution, which nothing here can know; the project states the packages +// it relies on in `options::depends` instead. +// +// EVERY FILE IS LISTED, WITH ITS MODE AND TIME STATED. nfpm's `tree` entry +// keeps each source file's mtime and permissions, and measured on nfpm +// 2.49.0 its top-level `mtime` does not reach a tree's files, so a package +// built from a re-staged tree differs byte for byte from the last one. The +// member therefore writes one entry per staged file with an explicit mode and +// `SOURCE_DATE_EPOCH` (or a fixed time), and the same tree gives the same +// package. + +export module mcpp.dist.linux_package; + +import std; +import mcpp; +import mcpp.plugins; +import mcpp.plugins.tool; + +export namespace mcpp::dist::linux_package { + +// ─── Options ─────────────────────────────────────────────────────────────── + +struct options { + // The program target the package installs. Empty means the package name. + std::string target; + + // The package's own name, which is also `/opt/`, `/usr/bin/`, + // and the desktop entry's file name. Empty derives it from `[package] + // name`: lowercase, with every character a Debian package name cannot + // carry replaced by `-`. + std::string name; + + // Control fields. Each empty one comes from `[package]`. + std::string version; // default: `[package] version` + std::string description; // default: `[package] description` + std::string maintainer; // default: the first of `[package] authors` + std::string license; // default: `[package] license` + std::string homepage; // default: `[package] repo` + + // Packages the machine provides and the program needs, by the name the + // target distribution gives them, such as `libgtk-4-1` for a deb or + // `gtk4` for an rpm. The staged closure carries what it vendored; what it + // left to the machine is listed in the staged `mcpp-package.json`. + std::vector depends; + + // The desktop entry. `desktop = false` installs none, for a program that + // is not started from a desktop. + bool desktop = true; + std::string app_name; // `Name=`; default: the package name + std::vector categories; // default: `Utility` + bool terminal = false; + // A PNG or SVG. Empty installs no icon file and the entry names the + // package, which a desktop resolves to its generic icon. + std::string icon; + + // The install prefix of the staged tree. Empty means `/opt/`. + std::string prefix; + + // `nfpm`. Default: the `xim:nfpm` payload this feature declares. + mcpp::plugins::tool::choice tool; + + // Where the produced package lands. Empty means + // `/__.deb` or + // `/--1..rpm`. + std::string output; + std::string out_dir = std::string(mcpp::out_dir()); +}; + +// What the member would submit, without submitting it: `generate()` is +// exactly `submit(plan_for())`, so a project-specific edit is an edit to the +// plan rather than a copy of this member. +struct plan { + bool applies = false; + std::string reason; + std::string format; + std::string output; + std::string config; + std::vector argv; + std::vector inputs; + explicit operator bool() const { return applies; } +}; + +// ─── Internals ───────────────────────────────────────────────────────────── + +inline bool is_file(const std::string& p) { + std::error_code ec; + return !p.empty() && std::filesystem::is_regular_file(p, ec); +} + +// Written only when the bytes differ, so an unchanged pack leaves the +// declared inputs' mtimes alone and the action stays up to date. +inline bool write_if_different(const std::filesystem::path& path, std::string_view bytes) { + std::error_code ec; + std::filesystem::create_directories(path.parent_path(), ec); + if (std::ifstream in(path, std::ios::binary); in) { + std::string old((std::istreambuf_iterator(in)), std::istreambuf_iterator()); + if (old == bytes) return true; + } + std::ofstream out(path, std::ios::binary | std::ios::trunc); + if (!out) return false; + out.write(bytes.data(), static_cast(bytes.size())); + return static_cast(out); +} + +inline std::string text_or(const std::string& value, const char* fallback) { + if (!value.empty()) return value; + return (fallback && *fallback) ? std::string(fallback) : std::string(); +} + +inline std::string target_for(const options& opt) { + return text_or(opt.target, mcpp::package_name()); +} + +// A Debian package name: lowercase letters, digits, `+`, `-`, `.`, starting +// with a letter or digit. RPM accepts every such name, so one rule serves both. +inline std::string package_name_for(const options& opt) { + const std::string source = text_or(opt.name, mcpp::package_name()); + std::string name; + for (char c : source) { + const auto u = static_cast(c); + if (std::isalnum(u)) name += static_cast(std::tolower(u)); + else if (c == '+' || c == '.' || c == '-') name += c; + else name += '-'; + } + while (!name.empty() && !std::isalnum(static_cast(name.front()))) name.erase(0, 1); + return name; +} + +inline std::string maintainer_for(const options& opt) { + if (!opt.maintainer.empty()) return opt.maintainer; + if (const char* authors = mcpp::package_authors(); authors && *authors) { + std::string first(authors); + first = first.substr(0, first.find(';')); + if (!first.empty()) return first; + } + return {}; +} + +// nfpm's architecture vocabulary is Go's; it renames for each format itself. +inline std::string nfpm_arch_for() { + const std::string arch = mcpp::target_arch(); + if (arch == "x86_64") return "amd64"; + if (arch == "aarch64") return "arm64"; + return arch; +} + +inline std::string file_arch_for(std::string_view format) { + const std::string arch = mcpp::target_arch(); + if (format == "deb") return arch == "x86_64" ? "amd64" : arch == "aarch64" ? "arm64" : arch; + return arch; +} + +// A YAML double-quoted scalar. +inline std::string yaml_string(std::string_view value) { + std::string out = "\""; + for (char c : value) { + if (c == '\\' || c == '"') out += '\\'; + if (c == '\n') { out += "\\n"; continue; } + out += c; + } + return out + "\""; +} + +// The time every file in the package carries: `SOURCE_DATE_EPOCH` when the +// build states one, otherwise a fixed time, so two packs of one tree agree. +inline std::string mtime_for() { + long long seconds = 946684800; // 2000-01-01T00:00:00Z + if (const char* epoch = std::getenv("SOURCE_DATE_EPOCH"); epoch && *epoch) { + long long parsed = 0; + const std::string_view text(epoch); + if (std::from_chars(text.data(), text.data() + text.size(), parsed).ec == std::errc{}) seconds = parsed; + } + const std::chrono::sys_seconds at{std::chrono::seconds{seconds}}; + return std::format("{:%Y-%m-%dT%H:%M:%SZ}", at); +} + +inline const mcpp::plugins::tool::spec& nfpm_spec() { + static const mcpp::plugins::tool::spec s{ + .who = "mcpp.dist.linux_package", .package = "nfpm", + .programs = {"nfpm"}, .bin_dirs = {"", "bin"}, .option = "options::tool" }; + return s; +} + +// The staged tree's launcher, which `/usr/bin/` execs. `mcpp pack` +// names it after the program; under `--mode static` it is the program itself. +inline std::string launcher_in(const std::string& stage, const std::string& target) { + for (auto candidate : {stage + "/" + target, stage + "/bin/" + target, stage + "/run.sh"}) + if (is_file(candidate)) return candidate; + return {}; +} + +inline std::string desktop_entry(const options& opt, const std::string& name) { + std::string categories; + if (opt.categories.empty()) categories = "Utility;"; + else for (auto const& c : opt.categories) categories += c + ";"; + const std::string comment = text_or(opt.description, mcpp::package_description()); + std::string text = "[Desktop Entry]\nType=Application\n"; + text += std::format("Name={}\n", opt.app_name.empty() ? name : opt.app_name); + if (!comment.empty()) text += std::format("Comment={}\n", comment); + text += std::format("Exec={}\n", name); + text += std::format("Icon={}\n", name); + text += std::format("Categories={}\n", categories); + text += std::format("Terminal={}\n", opt.terminal ? "true" : "false"); + return text; +} + +inline std::string file_entry(const std::string& src, const std::string& dst, std::string_view mode, + const std::string& mtime) { + return std::format(" - src: {}\n dst: {}\n file_info: {{ mode: {}, mtime: {} }}\n", + yaml_string(src), yaml_string(dst), mode, yaml_string(mtime)); +} + +// ─── Plan ────────────────────────────────────────────────────────────────── + +inline plan plan_for(std::string_view format, options opt = {}) { + plan p; + p.format = std::string(format); + const std::string who = std::format("mcpp.dist.{}", format); + + const std::string requested = mcpp::pack_format(); + if (requested != format) { + p.reason = requested.empty() ? "this build is not packaging" + : std::format("--format {} was requested, not {}", requested, format); + return p; + } + if (const std::string os = mcpp::target_os(); os != "linux") { + std::cerr << std::format("{}: a {} package installs on Linux, and this build targets '{}'.\n" + " use: --format tar, or build for a Linux target", + who, format, os.empty() ? "unknown" : os) << '\n'; + p.reason = "not a Linux target"; + return p; + } + const std::string stage = mcpp::pack_stage_dir(); + if (stage.empty()) { + std::cerr << who << ": mcpp reported no staged tree.\n"; + p.reason = "no staged tree"; + return p; + } + const std::string target = target_for(opt); + const std::string name = package_name_for(opt); + if (target.empty() || name.empty()) { + std::cerr << who << ": no package name. Set `options::target` and `options::name`.\n"; + p.reason = "no name"; + return p; + } + const std::string version = text_or(opt.version, mcpp::package_version()); + if (version.empty() || !std::isdigit(static_cast(version.front()))) { + std::cerr << std::format("{}: the package version '{}' does not start with a digit, which both formats " + "require. Set `[package] version` or `options::version`.", who, version) << '\n'; + p.reason = "version"; + return p; + } + const std::string maintainer = maintainer_for(opt); + if (maintainer.empty()) { + std::cerr << who << ": no maintainer. Set `[package] authors` or `options::maintainer`; a deb requires " + "the field and a guessed one would publish someone else's name.\n"; + p.reason = "no maintainer"; + return p; + } + + const auto found = mcpp::plugins::tool::resolve(nfpm_spec(), opt.tool); + if (found.program.empty()) { + if (!found.pending()) std::cerr << mcpp::plugins::tool::describe_missing(nfpm_spec(), found) << '\n'; + p.reason = found.pending() ? "nfpm requested" : "nfpm not found"; + return p; + } + + const std::string launcher = launcher_in(stage, target); + if (launcher.empty()) { + std::cerr << std::format("{0}: the staged tree at {1} carries no launcher for target '{2}'.\n" + " expected one of: {1}/{2}, {1}/bin/{2}, {1}/run.sh", + who, stage, target) << '\n'; + p.reason = "no launcher in the staged tree"; + return p; + } + const std::string prefix = opt.prefix.empty() ? "/opt/" + name : opt.prefix; + const std::string mtime = mtime_for(); + const auto work = std::filesystem::path(opt.out_dir) / "linux-package" / p.format; + + // The staged tree, one entry per file, in a stable order. + std::vector staged; + std::error_code ec; + for (auto const& entry : std::filesystem::recursive_directory_iterator(stage, ec)) { + if (ec) break; + if (entry.is_regular_file(ec) || entry.is_symlink(ec)) staged.push_back(entry.path().string()); + } + std::ranges::sort(staged); + if (staged.empty()) { + std::cerr << std::format("{}: the staged tree at {} is empty", who, stage) << '\n'; + p.reason = "empty staged tree"; + return p; + } + + std::string contents; + for (auto const& file : staged) { + const std::string relative = mcpp::plugins::names::relative_to(file, stage); + const std::string destination = prefix + "/" + relative; + if (std::filesystem::is_symlink(file, ec)) { + contents += std::format(" - src: {}\n dst: {}\n type: symlink\n", + yaml_string(std::filesystem::read_symlink(file, ec).string()), yaml_string(destination)); + continue; + } + const auto perms = std::filesystem::status(file, ec).permissions(); + const bool executable = (perms & std::filesystem::perms::owner_exec) != std::filesystem::perms::none; + contents += file_entry(file, destination, executable ? "0755" : "0644", mtime); + } + + const auto launcher_file = work / "launcher"; + const std::string launcher_rel = mcpp::plugins::names::relative_to(launcher, stage); + bool wrote = write_if_different(launcher_file, + std::format("#!/bin/sh\n# Generated by mcpp.dist.{}. Do not edit.\nexec {} \"$@\"\n", + format, yaml_string(prefix + "/" + launcher_rel))); + contents += file_entry(launcher_file.string(), "/usr/bin/" + name, "0755", mtime); + p.inputs.push_back(launcher_file.string()); + + if (opt.desktop) { + const auto desktop_file = work / (name + ".desktop"); + wrote = wrote && write_if_different(desktop_file, desktop_entry(opt, name)); + contents += file_entry(desktop_file.string(), "/usr/share/applications/" + name + ".desktop", "0644", mtime); + p.inputs.push_back(desktop_file.string()); + if (!opt.icon.empty()) { + std::string extension = std::filesystem::path(opt.icon).extension().string(); + for (char& c : extension) c = static_cast(std::tolower(static_cast(c))); + if (extension != ".png" && extension != ".svg") { + const std::string message = std::format( + "{}: the icon {} is neither a .png nor an .svg, the two formats a desktop reads.", who, opt.icon); + std::cerr << message << '\n'; + mcpp::warning(message.c_str()); + p.reason = "icon format"; + return p; + } + if (!is_file(opt.icon)) { + std::cerr << std::format("{}: cannot read the icon {}", who, opt.icon) << '\n'; + p.reason = "icon unreadable"; + return p; + } + // An SVG scales; a PNG of unknown size belongs in the unsized location. + const std::string destination = extension == ".svg" + ? "/usr/share/icons/hicolor/scalable/apps/" + name + ".svg" + : "/usr/share/pixmaps/" + name + ".png"; + contents += file_entry(std::filesystem::absolute(opt.icon, ec).string(), destination, "0644", mtime); + p.inputs.push_back(opt.icon); + } + } + + std::string config = std::format( + "# Generated by mcpp.dist.{}. Do not edit.\n" + "name: {}\narch: {}\nplatform: linux\nversion: {}\nrelease: \"1\"\nmaintainer: {}\ndescription: {}\n", + format, yaml_string(name), yaml_string(nfpm_arch_for()), yaml_string(version), yaml_string(maintainer), + yaml_string(text_or(opt.description, mcpp::package_description()))); + if (const std::string license = text_or(opt.license, mcpp::package_license()); !license.empty()) + config += std::format("license: {}\n", yaml_string(license)); + if (const std::string homepage = text_or(opt.homepage, mcpp::package_repo()); !homepage.empty()) + config += std::format("homepage: {}\n", yaml_string(homepage)); + if (!opt.depends.empty()) { + config += "depends:\n"; + for (auto const& dependency : opt.depends) config += std::format(" - {}\n", yaml_string(dependency)); + } + config += std::format("mtime: {}\ncontents:\n", yaml_string(mtime)) + contents; + + const auto config_file = work / "nfpm.yaml"; + if (!(wrote && write_if_different(config_file, config))) { + std::cerr << std::format("{}: cannot write the package description into {}", who, work.string()) << '\n'; + p.reason = "cannot write the package description"; + return p; + } + std::filesystem::permissions(launcher_file, + std::filesystem::perms::owner_exec | std::filesystem::perms::group_exec | std::filesystem::perms::others_exec, + std::filesystem::perm_options::add, ec); + + p.output = !opt.output.empty() ? opt.output + : (std::filesystem::path(opt.out_dir) / + (format == "deb" ? std::format("{}_{}_{}.deb", name, version, file_arch_for(format)) + : std::format("{}-{}-1.{}.rpm", name, version, file_arch_for(format)))).string(); + p.config = config_file.string(); + p.argv = {found.program, "package", "--config", p.config, "--packager", p.format, "--target", p.output}; + p.inputs.push_back(std::format("${{mcpp.target_file:{}}}", target)); + p.inputs.push_back(p.config); + p.applies = true; + return p; +} + +// ─── Submit ──────────────────────────────────────────────────────────────── + +inline bool submit(const plan& p) { + if (!p.applies) return true; + mcpp::action a; + const std::string id = "mcpp.dist." + p.format; + std::string description = p.format; + for (char& c : description) c = static_cast(std::toupper(static_cast(c))); + a.id = id.c_str(); + a.role = "artifact"; + a.description = description.c_str(); + for (auto const& token : p.argv) a.arg(token.c_str()); + for (auto const& input : p.inputs) a.input(input.c_str()); + a.output(p.output.c_str()); + a.submit(); + return true; +} + +// Declare unconditionally, submit conditionally: the declaration is what lets +// `mcpp pack --format` name the formats a graph provides. +inline bool generate(std::string_view format, options opt = {}) { + mcpp::provides_pack_format(std::string(format).c_str()); + return submit(plan_for(format, std::move(opt))); +} + +} // namespace mcpp::dist::linux_package diff --git a/dist/rpm.cppm b/dist/rpm.cppm new file mode 100644 index 0000000..36a4051 --- /dev/null +++ b/dist/rpm.cppm @@ -0,0 +1,33 @@ +// mcpp.dist.rpm -- a staged program becomes an RPM package for Fedora, RHEL, openSUSE, and their derivatives. +// +// The layout and the writer are shared with the other Linux package format in +// `mcpp.dist.linux_package`: the staged closure under `/opt/`, a +// launcher in `/usr/bin`, a desktop entry and an icon, written by nfpm from +// the `xim:nfpm` payload, so the host needs no `rpmbuild`. + +export module mcpp.dist.rpm; + +import std; +export import mcpp.dist.linux_package; + +export namespace mcpp::dist::rpm { + +using options = mcpp::dist::linux_package::options; +using plan = mcpp::dist::linux_package::plan; + +// What `generate` would submit for `mcpp pack --format rpm`, without submitting it. +inline plan plan_for(options opt = {}) { + return mcpp::dist::linux_package::plan_for("rpm", std::move(opt)); +} + +inline bool submit(const plan& p) { + return mcpp::dist::linux_package::submit(p); +} + +// The one call a build program makes: declares the `rpm` format in every pass +// and submits the package action when `mcpp pack --format rpm` asked for it. +inline bool generate(options opt = {}) { + return mcpp::dist::linux_package::generate("rpm", std::move(opt)); +} + +} // namespace mcpp::dist::rpm diff --git a/docs/dist.md b/docs/dist.md index dbb2669..67d3ddf 100644 --- a/docs/dist.md +++ b/docs/dist.md @@ -1,4 +1,4 @@ -# `dist-appimage`, `dist-wix` and `dist-web` +# `dist-appimage`, `dist-deb`, `dist-rpm`, `dist-wix` and `dist-web` Three `dist-*` members that turn the tree `mcpp pack` stages into an installable form: an AppImage on Linux, an MSI or a Burn bundle on Windows, and a web directory for `wasm32-emscripten`. `dist-apple` and `dist-apk` have pages of their own ([dist-apple.md](dist-apple.md), [dist-apk.md](dist-apk.md)). @@ -8,6 +8,14 @@ Module `mcpp.dist.appimage`; engine floor: 2026.10.1.3 (0.19.0, mcpp#755; 2026.9 **Needs and behaviour.** `xim:appimagetool`, which this feature declares on the `cfg(linux)` axis. Linux only. Turns the tree `mcpp pack` staged into one AppImage: the staged bundle is already an AppDir bar three files, so the member writes an `AppRun`, a `.desktop` entry and an icon into it and invokes one tool -- it never copies or re-lays-out a tree that can be hundreds of megabytes. From 0.11.1 `options::icon` may be an SVG as well as a PNG: the image carries `.svg`, because the desktop entry names the icon without an extension and a reader finds it by the file's, and any other format is refused by name +## `dist-deb` and `dist-rpm` + +Modules `mcpp.dist.deb` and `mcpp.dist.rpm`, both on `mcpp.dist.linux_package` (feature `dist-linux-package`, which each implies); engine floor: 2026.10.30.1. Their `xim:nfpm` (2.49.0 or newer) is installed when a pack asks for it (`provision = "on-request"`), so an ordinary build downloads none. From 0.23.0. + +**Needs and behaviour.** `xim:nfpm`, declared on the `cfg(linux)` axis; no `dpkg-deb` or `rpmbuild` on the host. Linux targets only; another target is refused by name. `--pkg-format deb` or `--pkg-format rpm` installs the tree `mcpp pack` staged, unchanged, under `/opt/`, adds `/usr/bin/` that execs the tree's launcher, and, unless `options::desktop` is false, a desktop entry in `/usr/share/applications` and the icon `options::icon` names (an SVG in `hicolor/scalable/apps`, a PNG in `/usr/share/pixmaps`). The control fields come from `[package]`: name, version, description, licence, repository, and the first author as maintainer; a package without a maintainer is refused rather than published under a guessed one. `options::depends` lists packages the machine provides, by the target distribution's names; the staged `mcpp-package.json` says what the tree left to the machine. + +**Reproducible.** Every staged file is listed with an explicit mode and time (`SOURCE_DATE_EPOCH`, or 2000-01-01 when unset), because nfpm's `tree` entries keep each source file's mtime and its top-level `mtime` does not reach them; packing a re-staged, unchanged tree gives byte-identical packages. `tests/linux-package-consumer` packs both formats and reads them back. + ## `dist-wix` Module `mcpp.dist.wix`; engine floor: 2026.10.1.3 (0.19.0, mcpp#755; 2026.9.11.1 before). diff --git a/docs/plugin-development.md b/docs/plugin-development.md index f352c72..da152a3 100644 --- a/docs/plugin-development.md +++ b/docs/plugin-development.md @@ -52,7 +52,7 @@ mcpp-index refuses such a package. ```toml [build-dependencies.mcpp] -plugins = { version = "0.22.1", features = ["plugins-core"], host-module = true, reexport = true } +plugins = { version = "0.23.0", features = ["plugins-core"], host-module = true, reexport = true } ``` `reexport = true` is needed when the plugin's consumers import L2 modules in diff --git a/mcpp.toml b/mcpp.toml index e45fccc..4d52fb0 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,7 +1,7 @@ [package] name = "plugins" namespace = "mcpp" -version = "0.22.1" +version = "0.23.0" # The first mcpp release that speaks protocol 17 (SPEC-013, mcpp#847): the # platform's directives `mcpp.plugins.platform` states (`link_driver`, # `link_input`, `artifact_name`, `seal`, `run_host`), the `platform` phase, and @@ -275,6 +275,22 @@ implies = ["plugins-core"] sources = ["dist/apk.cppm"] implies = ["plugins-core"] +# `dist-deb` AND `dist-rpm` (0.23.0) SHARE ONE UNIT AND ONE TOOL. Both install +# the staged closure under `/opt/` with a launcher, a desktop entry and an +# icon, and nfpm writes either format from one description, so the layout lives +# in `dist/linux-package.cppm` behind a feature of its own that both imply. +[features.dist-linux-package] +sources = ["dist/linux-package.cppm"] +implies = ["plugins-core"] + +[features.dist-deb] +sources = ["dist/deb.cppm"] +implies = ["dist-linux-package"] + +[features.dist-rpm] +sources = ["dist/rpm.cppm"] +implies = ["dist-linux-package"] + # `dist-apk` WITH THE KOTLIN COMPILER, AND WITH THE MAVEN RESOLVER (0.11.0). # Features of their own rather than payloads of `dist-apk`, for the reason # `dist-appimage` gives below about downloads: provisioning runs before the @@ -570,6 +586,16 @@ implies = ["plugins-core"] [target.'cfg(linux)'.feature-xlings.dist-appimage] "xim:appimagetool" = { version = ">=1.9.1", provision = "on-request" } +# ── The tool `dist-deb` and `dist-rpm` need ─────────────────────────────── +# +# nfpm writes both formats without `dpkg-deb` or `rpmbuild`, so a package for +# a Linux target can be produced on any host the payload exists for, and the +# produced bytes do not depend on which distribution tools the host carries. +# Asked for while planning the pack, as `dist-appimage` asks for its tool, so a +# build that packs nothing downloads nothing. +[target.'cfg(linux)'.feature-xlings.dist-linux-package] +"xim:nfpm" = { version = ">=2.49.0", provision = "on-request" } + # WiX IS A PAYLOAD, AND FOR A WHILE THIS FILE SAID IT COULD NOT BE. The # toolset is under the Microsoft Reciprocal License and its own licence text # permits redistribution (see the header of dist/wix.cppm); `xim:wix` carries diff --git a/src/plugins.cppm b/src/plugins.cppm index 5dfded0..877010e 100644 --- a/src/plugins.cppm +++ b/src/plugins.cppm @@ -46,7 +46,7 @@ export namespace mcpp::plugins { // // One package, one version: the number lives in mcpp.toml, and the CI step // `the collection states its own version` compares the two. -inline constexpr std::string_view version = "0.22.1"; +inline constexpr std::string_view version = "0.23.0"; } // namespace mcpp::plugins diff --git a/tests/all-rules-compile/build.mcpp b/tests/all-rules-compile/build.mcpp index ff571b5..8bc64ed 100644 --- a/tests/all-rules-compile/build.mcpp +++ b/tests/all-rules-compile/build.mcpp @@ -21,6 +21,8 @@ import mcpp.dist.wix; import mcpp.dist.apple; import mcpp.dist.web; import mcpp.dist.apk; +import mcpp.dist.deb; +import mcpp.dist.rpm; import mcpp.deps; import mcpp.deps.vcpkg; import mcpp.deps.cmake; @@ -73,6 +75,10 @@ int main() { ok = ok && !applePlan.applies; auto webPlan = mcpp::dist::web::plan_for(); ok = ok && !webPlan.applies; + auto debPlan = mcpp::dist::deb::plan_for(); + ok = ok && !debPlan.applies; + auto rpmPlan = mcpp::dist::rpm::plan_for(); + ok = ok && !rpmPlan.applies; // `dist-apk`'s own gate is the target ENVIRONMENT (`cfg(env = "android")` // on its payload table, `mcpp::target_env() != "android"` in // `plan_for` itself), not `pack_format()` alone -- this fixture's host diff --git a/tests/all-rules-compile/mcpp.toml b/tests/all-rules-compile/mcpp.toml index 08290a2..08916ff 100644 --- a/tests/all-rules-compile/mcpp.toml +++ b/tests/all-rules-compile/mcpp.toml @@ -43,7 +43,7 @@ plugins = { path = "../..", features = [ "rules-spirv", "rules-swift", "rules-sycl", "tools-embed", "tools-island", "dist-appimage", "dist-wix", "dist-apple", "dist-web", "dist-apk", - "dist-apk-kotlin", "dist-apk-maven", + "dist-apk-kotlin", "dist-apk-maven", "dist-linux-package", "dist-deb", "dist-rpm", "deps-archive", "deps-cmake", "deps-vcpkg", ], host-module = true } @@ -63,6 +63,9 @@ plugins = { path = "../..", features = [ # member whose macOS and Windows compile is never attempted -- which is exactly # the failure the two platform-specific members are here to catch. # +# `dist-deb` and `dist-rpm` ask for `xim:nfpm` only while planning a pack of +# their own format, so this fixture, which packs nothing, downloads nothing for them. +# # `rules-qt` declares no SDK: the rule compiles without one, and the SDK -- # hundreds of megabytes on every host -- is a project's own declaration. The CI # step that reads this list requires every member that carries SOURCES; a diff --git a/tests/linux-package-consumer/assets/icon.svg b/tests/linux-package-consumer/assets/icon.svg new file mode 100644 index 0000000..5d23a8c --- /dev/null +++ b/tests/linux-package-consumer/assets/icon.svg @@ -0,0 +1 @@ + diff --git a/tests/linux-package-consumer/build.mcpp b/tests/linux-package-consumer/build.mcpp new file mode 100644 index 0000000..83803a2 --- /dev/null +++ b/tests/linux-package-consumer/build.mcpp @@ -0,0 +1,17 @@ +import std; +import mcpp; +import mcpp.dist.deb; +import mcpp.dist.rpm; + +int main() { + // Both members declare their format in every pass and act only in the pass + // that asked for it, so one program serves `--format deb` and `--format rpm`. + mcpp::dist::linux_package::options opt; + opt.target = "linux-package-consumer"; + opt.categories = {"Development"}; + opt.terminal = true; + opt.icon = "assets/icon.svg"; + // A package the machine provides, which CI reads back from the package. + opt.depends = {"bash"}; + return mcpp::dist::deb::generate(opt) && mcpp::dist::rpm::generate(opt) ? 0 : 1; +} diff --git a/tests/linux-package-consumer/mcpp.toml b/tests/linux-package-consumer/mcpp.toml new file mode 100644 index 0000000..262b1e1 --- /dev/null +++ b/tests/linux-package-consumer/mcpp.toml @@ -0,0 +1,23 @@ +# Fixture: a program that ships as a deb and as an rpm. +# +# One fixture for both formats, because they share the layout and the writer: +# `mcpp pack --format deb` and `mcpp pack --format rpm` each run the build +# program a second time over the staged closure and submit one nfpm action. +[package] +name = "linux-package-consumer" +version = "0.4.0" +description = "Fixture: packages a program as a deb and an rpm" +license = "Apache-2.0" +authors = ["mcpp-community "] + +[language] +standard = "c++23" +modules = true +import_std = true + +[build-dependencies.mcpp] +plugins = { path = "../..", features = ["dist-deb", "dist-rpm"], host-module = true } + +[targets.linux-package-consumer] +kind = "bin" +main = "src/main.cpp" diff --git a/tests/linux-package-consumer/src/main.cpp b/tests/linux-package-consumer/src/main.cpp new file mode 100644 index 0000000..57b2f0a --- /dev/null +++ b/tests/linux-package-consumer/src/main.cpp @@ -0,0 +1,6 @@ +import std; + +int main() { + std::cout << "linux-package-consumer ok\n"; + return 0; +}