Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2604,13 +2604,13 @@ jobs:

# dist-apk ON A HOST THAT IS NOT LINUX (0.24.0). Every tool the member
# runs is a native program (`aapt2`, `zipalign`) or a jar on the JDK's
# `java`, and its helper is a Java source file, so no step needs a shell
# and a Windows host packs what a Linux host does. On Windows the NDK's
# `java`, and each step of more than one command is a step program
# (0.25.0, `tools-steps`), so no step needs a shell and a Windows host
# packs what a Linux host does. On Windows the NDK's
# libc++ module sources come from `xim:android-ndk-libcxx-modules`,
# which `xim:android-ndk`'s windows entry depends on. The criteria are the
# level-0 step's on the Linux job, plus a level-1 package whose dex holds
# the activity: that is the helper's `run-and-stamp`, `run-d8` and
# `copy-then-jar` all having run.
# the activity: that is the javac, d8 and libs scripts all having run.
- name: dist-apk packs a signed APK on this host, level 0 and level 1
if: ${{ !cancelled() }}
working-directory: tests/apk-consumer
Expand Down Expand Up @@ -2653,7 +2653,7 @@ jobs:
grep -q "org.mcpp.apkconsumer.$c;" dexdump.log \
|| { echo "FAIL: the dex does not hold org.mcpp.apkconsumer.$c"; exit 1; }
done
echo "ok: level 1 -- javac, d8 and the helper ran on this host, and the dex holds the activity and the generated class"
echo "ok: level 1 -- the javac, d8 and libs scripts ran on this host, and the dex holds the activity and the generated class"

- name: the rule declared its own compiler
working-directory: tests/spirv-consumer
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module name the member declares, and configures it there.

```toml
[build-dependencies.mcpp]
plugins = { version = "0.24.0", features = ["rules-spirv"], host-module = true }
plugins = { version = "0.25.0", features = ["rules-spirv"], host-module = true }
```

```cpp
Expand Down Expand Up @@ -75,6 +75,7 @@ mcpp 2026.11.7.1 or later; cross configuration requires CMake 3.19 or later.
| `rules-sycl` | `mcpp.rules.sycl` | 2026.10.1.3 | Compiles SYCL (`*.sycl`) with DPC++. | [rules](docs/rules.md#rules-sycl) |
| `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) |
| `tools-steps` | `mcpp.tools.steps` | 2026.10.1.3 | Describes an action whose work is more than one command as portable operations a backend runs; implied by `dist-apk` and `dist-apple`. | [tools-steps](docs/tools-steps.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/<name>` 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) |
Expand Down
367 changes: 110 additions & 257 deletions dist/apk.cppm

Large diffs are not rendered by default.

97 changes: 58 additions & 39 deletions dist/apple.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ export module mcpp.dist.apple;
import std;
import mcpp;
import mcpp.plugins;
import mcpp.plugins.tool;
import mcpp.tools.steps;

// Nothing here uses `std::println`, and that is not a style choice: both of
// its overloads reach into the libc++ dylib for symbols macOS 14 does not
Expand Down Expand Up @@ -335,6 +337,12 @@ struct options {
std::string volume_name;
std::string dmg;

// The runner of the steps of more than one command (0.25.0,
// `mcpp.tools.steps`; `cmake` until mcpp#955): the `xim:cmake` payload,
// asked for only when a plan copies a framework or stages a disk image,
// or a program named here.
mcpp::plugins::tool::choice cmake;

std::string out_dir = std::string(mcpp::out_dir());
};

Expand Down Expand Up @@ -424,13 +432,22 @@ inline plan& refuse(plan& p, std::string reason, const std::string& message) {
return p;
}

// A helper script, written into `<out_dir>/dist-apple/` at plan time when its
// bytes differ, and run by `/bin/sh` so that no permission bit is needed.
inline std::string helper_script(const std::string& out_dir, const char* name,
std::string_view body) {
const auto path = std::filesystem::path(out_dir) / "dist-apple" / name;
write_if_different(path, body);
return path.string();
// A step of more than one command (0.25.0): a step program
// (`mcpp.tools.steps`) written into `<out_dir>/dist-apple/steps/`, so no step
// is a shell script. The runner and the written program join the step's inputs.
// `name` is used as a file name; anything but letters, digits, `-` and `.`
// becomes `_`.
inline void attach(step& s, const std::string& runner, const std::string& out_dir,
const std::string& name, const mcpp::tools::steps::program& program) {
std::string file = name;
for (std::size_t i = 0; i < file.size(); ++i) {
const unsigned char c = static_cast<unsigned char>(file[i]);
if (!std::isalnum(c) && c != '-' && c != '.') file[i] = '_';
}
const auto how = mcpp::tools::steps::command(
runner, std::filesystem::path(out_dir) / "dist-apple" / "steps" / file, "mcpp.dist.apple", program);
s.argv = how.argv;
s.inputs.insert(s.inputs.end(), how.inputs.begin(), how.inputs.end());
}

inline std::string target_for(const options& opt) {
Expand Down Expand Up @@ -1290,36 +1307,45 @@ inline plan plan_for(options opt = {}) {
}
}

// `cmake` runs the steps of more than one command (0.25.0): a framework's
// copy and signature, and a disk image's staging. Asked for only when the
// plan has one.
namespace steps = mcpp::tools::steps;
std::string runner;
if (!frameworks.empty() || dmg) {
const auto runnerSpec = steps::runner_spec("mcpp.dist.apple");
const auto runnerTool = mcpp::plugins::tool::resolve(runnerSpec, opt.cmake);
if (runnerTool.pending()) { p.reason = "cmake requested"; return p; }
if (!runnerTool) {
return refuse(p, "cmake not found",
mcpp::plugins::tool::describe_missing(runnerSpec, runnerTool)
+ "\n So this plan bundles nothing.");
}
runner = runnerTool.program;
}

// THE FRAMEWORKS: each copied from the staged tree and, when the bundle is
// signed, signed before the bundle is -- a bundle signature seals nested
// code that is already signed.
// code that is already signed. An ad-hoc signature (`-`) carries no
// timestamp.
if (!frameworks.empty()) {
const std::string copyFramework = helper_script(opt.out_dir, "copy-framework.sh",
"#!/bin/sh\n"
"# mcpp.dist.apple helper. Do not edit.\n"
"# copy-framework.sh <source> <destination> sign|nosign [identity]\n"
"set -e\n"
"src=\"$1\"; dst=\"$2\"; mode=\"$3\"; identity=\"$4\"\n"
"mkdir -p \"$(dirname \"$dst\")\"\n"
"ditto \"$src\" \"$dst\"\n"
"if [ \"$mode\" = sign ]; then\n"
" if [ \"$identity\" = - ]; then\n"
" codesign --force --sign - \"$dst\"\n"
" else\n"
" codesign --force --sign \"$identity\" --timestamp \"$dst\"\n"
" fi\n"
"fi\n");
for (auto const& rel : frameworks) {
const std::string source = (std::filesystem::path(stage) / "bin" / rel).string();
const std::string dest = frameworksDir + "/" + rel;
step fw;
fw.id = "mcpp.dist.apple.framework." + rel;
fw.role = "artifact";
fw.description = "APP FRAMEWORK " + rel;
fw.argv = { "/bin/sh", copyFramework, source, dest };
if (signs) { fw.argv.push_back("sign"); fw.argv.push_back(signingIdentity); }
else { fw.argv.push_back("nosign"); }
steps::program copy;
copy.mkdir(std::filesystem::path(dest).parent_path().generic_string())
.run({ "ditto", source, dest });
if (signs) {
copy.run(signingIdentity == "-"
? std::vector<std::string>{ "codesign", "--force", "--sign", "-", dest }
: std::vector<std::string>{ "codesign", "--force", "--sign", signingIdentity, "--timestamp", dest });
}
fw.inputs = { source, "${mcpp.stage_dir}" };
attach(fw, runner, opt.out_dir, "framework-" + rel, copy);
fw.outputs = { dest };
p.steps.push_back(fw);
assembled.push_back(dest);
Expand Down Expand Up @@ -1449,24 +1475,17 @@ inline plan plan_for(options opt = {}) {
const std::string dmgPath = !opt.dmg.empty() ? opt.dmg
: (std::filesystem::path(opt.out_dir) / (name + ".dmg")).string();
const std::string dmgStage = (std::filesystem::path(opt.out_dir) / "dist-apple" / "dmg").string();
const std::string stageDmg = helper_script(opt.out_dir, "stage-dmg.sh",
"#!/bin/sh\n"
"# mcpp.dist.apple helper. Do not edit.\n"
"# stage-dmg.sh <bundle> <staging directory> <bundle name>\n"
"set -e\n"
"bundle=\"$1\"; stage=\"$2\"; name=\"$3\"\n"
"rm -rf \"$stage\"\n"
"mkdir -p \"$stage\"\n"
"ditto \"$bundle\" \"$stage/$name\"\n"
"ln -s /Applications \"$stage/Applications\"\n");

step staging;
staging.id = "mcpp.dist.apple.dmg-stage";
staging.role = "artifact";
staging.description = "DMG STAGE";
staging.argv = { "/bin/sh", stageDmg, bundlePath, dmgStage,
std::filesystem::path(bundlePath).filename().string() };
const std::string staged = dmgStage + "/" + std::filesystem::path(bundlePath).filename().string();
staging.inputs = { bundlePath };
attach(staging, runner, opt.out_dir, "dmg-stage",
steps::program{}.remove(dmgStage)
.mkdir(dmgStage)
.run({ "ditto", bundlePath, staged })
.symlink("/Applications", dmgStage + "/Applications"));
staging.outputs = { dmgStage };
p.steps.push_back(staging);

Expand Down
Loading
Loading