diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8ccd8c..e98e573 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/README.md b/README.md index 81dc845..cf58eb2 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.24.0", features = ["rules-spirv"], host-module = true } +plugins = { version = "0.25.0", features = ["rules-spirv"], host-module = true } ``` ```cpp @@ -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/` 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) | diff --git a/dist/apk.cppm b/dist/apk.cppm index fb725b0..fde7348 100644 --- a/dist/apk.cppm +++ b/dist/apk.cppm @@ -102,6 +102,7 @@ import std; import mcpp; import mcpp.plugins; import mcpp.plugins.tool; +import mcpp.tools.steps; // `std::format` is header-only and used throughout; `std::println` is not -- // see `rules/spirv.cppm` for the libc++-on-macOS-14 measurement that this @@ -204,6 +205,10 @@ struct options { // `platform` is a root carrying `android.jar`; `keystore_package` above // stays the way a keystore package is named. mcpp::plugins::tool::choice build_tools, platform, jdk, bundletool_dir, kotlin, coursier; + // 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 when a package is planned, or a program named here. + mcpp::plugins::tool::choice cmake; std::string keystore_alias; // The NAME of an environment variable `apksigner` itself reads // (`--ks-pass env:`) -- this member never reads the secret; only @@ -348,206 +353,6 @@ inline std::string host_program(const fs::path& dir, std::string_view name) { } inline const char* class_path_separator() { return host_is_windows() ? ";" : ":"; } -// THE PIPELINE'S HELPER, ONE PROGRAM FOR EVERY HOST (0.24.0). Four steps need -// more than one command or a file set known only when they run; until 0.24.0 -// each was a `#!/bin/sh` script, which a Windows host cannot start. The JDK -// this member already requires runs a single Java source file directly -// (`java DistApk.java ...`, JEP 330, JDK 11), so the helper is that -// file, and its commands do what the scripts did: -// -// copy-then-jar [--dex ] [--stored ] ... -// Copies the linked archive and adds the staged `lib/`, `assets/` and -// the dex with `jar`: aapt2 has no flag for native libraries. -// `--dex ` adds every `classes*.dex` d8 wrote there: a package -// whose classes pass the 64K-method limit of one dex gets -// `classes2.dex` and on, and which of them exist is known only when d8 -// has run. `--stored ` adds an entry uncompressed, which -// native libraries loaded in place must be. -// run-and-stamp ... -// Runs the command, then touches the stamp: javac's and kotlinc's own -// output sets are not knowable at plan time. -// run-d8 ... --inputs ... --options ... -// `d8` DOES NOT ACCEPT A DIRECTORY, MEASURED (2026-09-12, d8 9.2.4, -// `xim:android-build-tools` 37.0.0): `d8 --output ` -// fails in the tool itself, `Unsupported source file type`, one frame -// into `BaseCommand$Builder.addProgramFiles`. So a directory is -// expanded to its `.class` files here, at command time; an archive -// (a JAR, an AAR's classes.jar, the Kotlin stdlib) is passed as it is. -// Earlier dex files are removed first, so a package that shrinks below -// the multidex limit does not keep a stale `classes2.dex`. -// make-module -// THE BASE MODULE OF AN APP BUNDLE. `aapt2 link --proto-format` writes -// the manifest at the archive's root beside `resources.pb` and `res/`; -// bundletool reads a module whose manifest is under `manifest/`, whose -// dex is under `dex/` and whose native libraries and assets are under -// `lib/` and `assets/`. A level-0 package has no dex, which the fourth -// argument states as `-`: an empty argument does not survive the -// action's argv. -// -// A failing tool's exit status is the helper's, and the tool's own output -// reaches the build's, as it did through `set -e`. -inline constexpr std::string_view helper_source = R"java(// mcpp.dist.apk helper. Do not edit. -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.FileTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class DistApk { - static final class Failure extends RuntimeException { - final int status; - Failure(int status) { super(null, null, false, false); this.status = status; } - } - - static Failure fail(String message) { - System.err.println("DistApk: " + message); - return new Failure(1); - } - - static void run(List command, Path directory) throws IOException, InterruptedException { - ProcessBuilder builder = new ProcessBuilder(command).inheritIO(); - if (directory != null) builder.directory(directory.toFile()); - int status = builder.start().waitFor(); - if (status != 0) throw new Failure(status); - } - - static List list(String... items) { return new ArrayList<>(Arrays.asList(items)); } - - static List dexFiles(Path directory) throws IOException { - try (Stream files = Files.list(directory)) { - return files.map(f -> f.getFileName().toString()) - .filter(n -> n.startsWith("classes") && n.endsWith(".dex")) - .sorted().collect(Collectors.toList()); - } - } - - static void copyTree(Path from, Path to) throws IOException { - try (Stream files = Files.walk(from)) { - for (Path f : files.sorted().collect(Collectors.toList())) { - Path target = to.resolve(from.relativize(f).toString()); - if (Files.isDirectory(f)) Files.createDirectories(target); - else Files.copy(f, target, StandardCopyOption.REPLACE_EXISTING); - } - } - } - - static void deleteTree(Path root) throws IOException { - if (!Files.exists(root)) return; - try (Stream files = Files.walk(root)) { - for (Path f : files.sorted((a, b) -> b.compareTo(a)).collect(Collectors.toList())) Files.delete(f); - } - } - - static void copyThenJar(List a) throws Exception { - if (a.size() < 3) throw fail("copy-then-jar ..."); - Path dst = Paths.get(a.get(1)).toAbsolutePath(); - String jar = a.get(2); - int i = 3; - String dex = null, storedDir = null, stored = null; - if (i + 1 < a.size() && a.get(i).equals("--dex")) { dex = a.get(i + 1); i += 2; } - if (i + 2 < a.size() && a.get(i).equals("--stored")) { storedDir = a.get(i + 1); stored = a.get(i + 2); i += 3; } - Files.copy(Paths.get(a.get(0)), dst, StandardCopyOption.REPLACE_EXISTING); - if (stored != null) { - run(list(jar, "--update", "--no-compress", "--file", dst.toString(), "-C", storedDir, stored), null); - } - if (i < a.size()) { - List update = list(jar, "uf", dst.toString()); - update.addAll(a.subList(i, a.size())); - run(update, null); - } - if (dex != null) { - List names = dexFiles(Paths.get(dex)); - if (names.isEmpty()) throw fail("no classes*.dex in " + dex); - List update = list(jar, "uf", dst.toString()); - update.addAll(names); - run(update, Paths.get(dex)); - } - } - - static void runAndStamp(List a) throws Exception { - if (a.size() < 2) throw fail("run-and-stamp ..."); - run(a.subList(1, a.size()), null); - Path stamp = Paths.get(a.get(0)); - if (stamp.getParent() != null) Files.createDirectories(stamp.getParent()); - if (Files.exists(stamp)) Files.setLastModifiedTime(stamp, FileTime.fromMillis(System.currentTimeMillis())); - else Files.createFile(stamp); - } - - static void runD8(List a) throws Exception { - int inputsAt = a.indexOf("--inputs"), optionsAt = a.indexOf("--options"); - if (inputsAt < 1 || optionsAt < inputsAt) throw fail("run-d8 ... --inputs ... --options