Crafter.Build/project.cpp

368 lines
22 KiB
C++
Raw Normal View History

2026-07-23 01:24:42 +02:00
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
2026-04-27 07:04:42 +02:00
import std;
import Crafter.Build;
#pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.LintRules.git"
import Crafter.LintRules;
2026-04-27 07:04:42 +02:00
namespace fs = std::filesystem;
using namespace Crafter;
feat(packaging): `run flatpak` and `run install` for a local Flatpak The local Flatpak build was one long flatpak-builder line in AGENTS.md, with its state wherever the caller happened to stand, and installing the result was not written down anywhere. It is not a rare chore: the development box compiles with the distro's clang and the Flatpak with its bundled LLVM, a major version apart at the moment, so anything toolchain-sensitive has to be tried in the Flatpak too. Both are now scripts in project.cpp, the first users of cfg.scripts. `run flatpak` builds the manifest as it is, from the working tree, and ends with `crafter-build --version` from inside the result. Its state is build/flatpak/ (state/, repo/, build-dir/). That is a fixed name and not a BuildDir() on purpose: the Flatpak is compiled by the toolchain in the sandbox, so it does not depend on the host variant, and a variant-keyed directory would strand the LLVM cache on every host compiler update. The manifest already skips build/ when it copies the sources. flatpak-builder keys its cache on the manifest's path, so the manifest is never rewritten into a copy the way CI stamps the version in, and a local build reports 0.0.0-dev. The only argument accepted is --jobs=<N>: anything that ends the run without a build would leave the smoke test checking the previous one. `run install` installs the last export as branch `local` from a user remote of its own and makes it current, leaving the published branch installed. It does not build first: flatpak-builder never caches a `type: dir` module, so every build reruns build.sh and the suite. remote-add --if-not-exists is followed by remote-modify --url, because the remote may exist and point at another checkout. Both refuse to run from the Flatpak build of crafter-build, which has no flatpak to drive. The smoke test goes through `flatpak build` and not `<builder> --run`, which is what CI uses. flatpak-builder 1.4.9 run as the org.flatpak.Builder app exits 1 when the command it ran succeeded and 0 when it failed (`true` gives 1, `exit 3` gives 0), so the script reported a good build as a failure. Measured on the 56-core box with LLVM and the WASI sysroot cached: 260 seconds, the crafter-build module only, 29 tests passing in the sandbox. A second `run install` after a rebuild moved the installed commit. `clean` now also drops that state, about 2 GB and a cold LLVM build. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 18:29:32 +02:00
// The local Flatpak: `crafter-build run flatpak` builds it from this checkout
// and `crafter-build run install` installs that build. The development box
// compiles with its own clang, the shipped artifact with the LLVM bundled in
// the Flatpak, so this is how a change is tried against the real thing.
namespace {
struct FlatpakPaths {
fs::path manifest;
// flatpak-builder's downloads, ccache and per-module cache. The
// LLVM build lives here: about 3 GB in all after a first run,
// which takes about 30 minutes with 56 CPU threads.
feat(packaging): `run flatpak` and `run install` for a local Flatpak The local Flatpak build was one long flatpak-builder line in AGENTS.md, with its state wherever the caller happened to stand, and installing the result was not written down anywhere. It is not a rare chore: the development box compiles with the distro's clang and the Flatpak with its bundled LLVM, a major version apart at the moment, so anything toolchain-sensitive has to be tried in the Flatpak too. Both are now scripts in project.cpp, the first users of cfg.scripts. `run flatpak` builds the manifest as it is, from the working tree, and ends with `crafter-build --version` from inside the result. Its state is build/flatpak/ (state/, repo/, build-dir/). That is a fixed name and not a BuildDir() on purpose: the Flatpak is compiled by the toolchain in the sandbox, so it does not depend on the host variant, and a variant-keyed directory would strand the LLVM cache on every host compiler update. The manifest already skips build/ when it copies the sources. flatpak-builder keys its cache on the manifest's path, so the manifest is never rewritten into a copy the way CI stamps the version in, and a local build reports 0.0.0-dev. The only argument accepted is --jobs=<N>: anything that ends the run without a build would leave the smoke test checking the previous one. `run install` installs the last export as branch `local` from a user remote of its own and makes it current, leaving the published branch installed. It does not build first: flatpak-builder never caches a `type: dir` module, so every build reruns build.sh and the suite. remote-add --if-not-exists is followed by remote-modify --url, because the remote may exist and point at another checkout. Both refuse to run from the Flatpak build of crafter-build, which has no flatpak to drive. The smoke test goes through `flatpak build` and not `<builder> --run`, which is what CI uses. flatpak-builder 1.4.9 run as the org.flatpak.Builder app exits 1 when the command it ran succeeded and 0 when it failed (`true` gives 1, `exit 3` gives 0), so the script reported a good build as a failure. Measured on the 56-core box with LLVM and the WASI sysroot cached: 260 seconds, the crafter-build module only, 29 tests passing in the sandbox. A second `run install` after a rebuild moved the installed commit. `clean` now also drops that state, about 2 GB and a cold LLVM build. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 18:29:32 +02:00
fs::path state;
// The OSTree repo the build is exported to; `install` reads it.
fs::path repo;
fs::path buildDir;
};
// Everything under <project>/build/flatpak, and a fixed name on purpose
// instead of a BuildDir(): the Flatpak is compiled by the toolchain
// inside the sandbox, so it does not depend on the host variant, and a
// variant-keyed directory would strand the LLVM cache on every host
// compiler update. The manifest's `skip: build` keeps it out of the
// sources the sandbox copies. flatpak-builder keys its cache on the
// manifest's absolute path, so the manifest is used where it is, never
// through a rewritten copy the way CI stamps the version in; a local
// build therefore reports version 0.0.0-dev.
FlatpakPaths FlatpakLayout(const fs::path& projectDir) {
const fs::path root = projectDir / "build" / "flatpak";
return {
.manifest = projectDir / "packaging" / "flatpak" / "net.catcrafts.CrafterBuild.yaml",
.state = root / "state",
.repo = root / "repo",
.buildDir = root / "build-dir",
};
}
// Both scripts drive the host's flatpak, and the sandbox crafter-build
// itself runs in as a Flatpak has none.
bool RefusedInSandbox(std::string_view script) {
if (!fs::exists("/.flatpak-info")) return false;
std::println(std::cerr, "run {0}: runs flatpak itself, which the Flatpak build of crafter-build does not have (its install and bundle verbs reach the host's through flatpak-spawn instead). Use a native build: ./build.sh, then ./bin/crafter-build run {0}", script);
feat(packaging): `run flatpak` and `run install` for a local Flatpak The local Flatpak build was one long flatpak-builder line in AGENTS.md, with its state wherever the caller happened to stand, and installing the result was not written down anywhere. It is not a rare chore: the development box compiles with the distro's clang and the Flatpak with its bundled LLVM, a major version apart at the moment, so anything toolchain-sensitive has to be tried in the Flatpak too. Both are now scripts in project.cpp, the first users of cfg.scripts. `run flatpak` builds the manifest as it is, from the working tree, and ends with `crafter-build --version` from inside the result. Its state is build/flatpak/ (state/, repo/, build-dir/). That is a fixed name and not a BuildDir() on purpose: the Flatpak is compiled by the toolchain in the sandbox, so it does not depend on the host variant, and a variant-keyed directory would strand the LLVM cache on every host compiler update. The manifest already skips build/ when it copies the sources. flatpak-builder keys its cache on the manifest's path, so the manifest is never rewritten into a copy the way CI stamps the version in, and a local build reports 0.0.0-dev. The only argument accepted is --jobs=<N>: anything that ends the run without a build would leave the smoke test checking the previous one. `run install` installs the last export as branch `local` from a user remote of its own and makes it current, leaving the published branch installed. It does not build first: flatpak-builder never caches a `type: dir` module, so every build reruns build.sh and the suite. remote-add --if-not-exists is followed by remote-modify --url, because the remote may exist and point at another checkout. Both refuse to run from the Flatpak build of crafter-build, which has no flatpak to drive. The smoke test goes through `flatpak build` and not `<builder> --run`, which is what CI uses. flatpak-builder 1.4.9 run as the org.flatpak.Builder app exits 1 when the command it ran succeeded and 0 when it failed (`true` gives 1, `exit 3` gives 0), so the script reported a good build as a failure. Measured on the 56-core box with LLVM and the WASI sysroot cached: 260 seconds, the crafter-build module only, 29 tests passing in the sandbox. A second `run install` after a rebuild moved the installed commit. `clean` now also drops that state, about 2 GB and a cold LLVM build. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 18:29:32 +02:00
return true;
}
// flatpak-builder as a host package, else the org.flatpak.Builder app.
// Empty when neither is installed.
std::string FlatpakBuilder() {
if (RunCommandWithTimeout("flatpak-builder --version", std::chrono::seconds(10)).exitCode == 0) return "flatpak-builder";
if (RunCommandWithTimeout("flatpak info org.flatpak.Builder", std::chrono::seconds(10)).exitCode == 0) return "flatpak run org.flatpak.Builder";
return "";
}
// A repo path as the file:// URL of a remote. Percent-encoded, because
// `remote-modify --url=` stores what it is given as it is.
std::string FileUrl(const fs::path& path) {
std::string url = "file://";
for (const char c : path.string()) {
const bool plain = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || std::string_view("/-._~").contains(c);
if (plain) url.push_back(c);
else url += std::format("%{:02X}", static_cast<std::uint8_t>(c));
}
return url;
}
std::int32_t BuildFlatpak(ScriptContext& ctx) {
if (RefusedInSandbox("flatpak")) return 1;
// Nothing else is passed through: a flag such as --stop-at or
// --download-only would end the run without a build and leave the
// smoke test below running against the previous one.
std::string jobs;
for (const std::string& arg : ctx.args) {
const std::string_view count = arg.starts_with("--jobs=") ? std::string_view(arg).substr(7) : std::string_view();
if (count.empty() || !std::ranges::all_of(count, [](char c) { return c >= '0' && c <= '9'; })) {
std::println(std::cerr, "run flatpak: unknown argument '{}' (only --jobs=<N> is accepted)", arg);
return 1;
}
jobs = std::format(" --jobs={}", count);
}
const std::string builder = FlatpakBuilder();
if (builder.empty()) {
std::println(std::cerr, "run flatpak: neither flatpak-builder nor the org.flatpak.Builder app is installed (flatpak install flathub org.flatpak.Builder)");
return 1;
}
const FlatpakPaths paths = FlatpakLayout(ctx.projectDir);
const std::string buildDir = ShellQuote(paths.buildDir.string());
if (const std::int32_t code = ctx.Run(std::format("{}{} --user --force-clean --ccache --state-dir={} --repo={} --default-branch=local {} {}", builder, jobs, ShellQuote(paths.state.string()), ShellQuote(paths.repo.string()), buildDir, ShellQuote(paths.manifest.string()))); code != 0) return code;
// The smoke test CI runs on its build, but through `flatpak build`
// and not `<builder> --run`: the org.flatpak.Builder app (1.4.9)
// exits 1 when the command it ran succeeded and 0 when it failed,
// and --run also wants the state dir again or it drops a
// .flatpak-builder/ into the working directory.
return ctx.Run(std::format("flatpak build {} crafter-build --version", buildDir));
}
std::int32_t InstallFlatpak(ScriptContext& ctx) {
if (RefusedInSandbox("install")) return 1;
if (!ctx.args.empty()) {
std::println(std::cerr, "run install: takes no arguments (got '{}')", ctx.args.front());
return 1;
}
const FlatpakPaths paths = FlatpakLayout(ctx.projectDir);
// Deliberately not built from here: flatpak-builder never caches a
// `type: dir` module, so every build reruns build.sh and the whole
// suite inside the sandbox. Installing is the cheap half.
if (!fs::exists(paths.repo / "config")) {
std::println(std::cerr, "run install: nothing built yet, run: crafter-build run flatpak");
return 1;
}
const std::string url = ShellQuote(FileUrl(paths.repo));
// Its own branch from its own remote, next to whichever published
// branch is installed. The remote may already exist and point at
// another checkout's repo; --if-not-exists would keep that silently.
if (const std::int32_t code = ctx.Run(std::format("flatpak remote-add --user --if-not-exists --no-gpg-verify crafter-build-local {}", url)); code != 0) return code;
if (const std::int32_t code = ctx.Run(std::format("flatpak remote-modify --user --url={} crafter-build-local", url)); code != 0) return code;
if (const std::int32_t code = ctx.Run("flatpak install --user --noninteractive --or-update crafter-build-local net.catcrafts.CrafterBuild//local"); code != 0) return code;
// Only a first install becomes the branch `flatpak run` starts; an
// update leaves that choice where it was.
if (const std::int32_t code = ctx.Run("flatpak make-current --user net.catcrafts.CrafterBuild local"); code != 0) return code;
std::println(
R"(
`flatpak run net.catcrafts.CrafterBuild` now starts this build.
Back to a published branch, keeping this one installed:
flatpak make-current --user net.catcrafts.CrafterBuild <branch>
Remove it (do this before `crafter-build clean`, which deletes the repo the remote points at):
flatpak uninstall --user net.catcrafts.CrafterBuild//local
flatpak remote-delete --user crafter-build-local)");
return 0;
}
}
2026-04-27 07:04:42 +02:00
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
Configuration* math = GitProject({ .source = { "https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git" } });
Configuration* asset = GitProject({ .source = { "https://forgejo.catcrafts.net/Catcrafts/Crafter.Asset.git" } });
2026-05-12 01:16:40 +02:00
2026-07-23 01:24:42 +02:00
static auto CrafterBuildLib = std::make_unique<Configuration>();
CrafterBuildLib->path = "./";
CrafterBuildLib->name = "crafter.build-lib";
CrafterBuildLib->outputName = "crafter-build";
ApplyStandardArgs(*CrafterBuildLib, args);
refactor: drop Windows host support crafter-build is moving to a single Flatpak distribution, and there is no Windows host in that picture: no build.cmd, no MSVC or mingw host build, no DLL plus launcher. Delete every host-Windows path instead of leaving it to rot unverified: the cmd.exe command runner and quoting, the LOCALAPPDATA cache, the MSVC and mingw-host LoadProject variants with their LIBCXX_DIR and CRAFTER_MINGW_DIR plumbing, the winsock port probe, the LoadLibrary libclang loader, the console-width and isatty shims, and the preprocessor guards around the Linux bodies. The x86_64-w64-mingw32 cross-compile target stays. It is target logic (output names, -femulated-tls, the libstdc++ link extras, copying a dependency DLL next to a mingw exe, wine as the runner) and did not depend on any of the removed code. The msvc target goes with the host that was the only thing able to use it. Three target-path warts fixed on the way: ExpectedOutput named a mingw static library <name>.lib while the archive step wrote lib<name>.a, so those libraries relinked on every run; the import lib is no longer copied next to a mingw exe, since the dependency's own bin dir is already on the link line; and llvm-ar now writes every archive, not only the LTO ones, so Debug and Release archives are made the same way. CRAFTER_API and Crafter.Build-Api.h existed only for the DLL boundary. Nothing downstream used them, so they are removed rather than kept as an empty macro nobody can verify. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 21:56:38 +02:00
// Monolithic: project.so resolves Crafter:: symbols from the running
// executable, so the library is only ever linked statically into it.
CrafterBuildLib->type = ConfigurationType::LibraryStatic;
2026-07-23 01:24:42 +02:00
CrafterBuildLib->dependencies = { math, asset };
CrafterBuildLib->defines.push_back({"CRAFTER_BUILD_HAS_ASSET", ""});
feat(toolchain): resolve the compiler in one place Every clang++, clang and llvm-ar the tool spawned was a bare name on PATH, the std module source was /usr/share/libc++/v1/std.cppm, the WASI sysroot /usr/share/wasi-sysroot and the mingw headers /usr/x86_64-w64-mingw32, spelled out at eighteen call sites. A toolchain installed anywhere else, which is what the Flatpak ships under /app, had no way in. Crafter.Build:Toolchain resolves all of it once per process: CRAFTER_BUILD_LLVM_DIR, else a clang++ installed beside crafter-build (<prefix>/bin, found through the same walk GetCrafterBuildHome does), else PATH. What sits beside the compiler is used when present: its libclang.so, its clang-c headers, its std module source, its WASI sysroot. An explicit prefix without a clang++ is an error rather than a fallback, for the same reason CRAFTER_BUILD_LIBCLANG was already exclusive. CRAFTER_BUILD_LIBCXX_DIR points at a libc++ install other than the compiler's own, and CRAFTER_MINGW_DIR now does what its help line always claimed: it is passed as --sysroot for the mingw target. Binaries linked by a toolchain outside /usr get an rpath to its lib dir, since its libc++.so.1 is not on the loader's default path. HostTarget() is the resolved clang's -print-target-triple. A clang built without a vendor reports x86_64-unknown-linux-gnu where Arch's reports x86_64-pc-linux-gnu, so target equality that decides whether a test runs locally and which targets a bare `test` sweeps goes through SameTarget, which ignores the vendor field. The strings themselves are never rewritten: clang rejects a PCM whose triple differs from the importing unit's. The examples and README stop hardcoding the host triple; the default is already the host. `crafter-build --version` prints the version baked in at build time (CRAFTER_BUILD_VERSION, else `git describe`, else 0.0.0-dev), the compiler and the host triple, and is answered before any argument is forwarded to project.cpp. The version is a define on the library, so each version is its own library variant and relinks the executable and tests once per commit. build.sh gains a shebang and `set -eu`, honours CRAFTER_BUILD_LLVM_DIR and CRAFTER_BUILD_VERSION, skips the glslang clone when it is already there, and writes a fresh archive instead of appending to one that may hold members from an older layout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 22:26:31 +02:00
// Crafter.Build-Lint includes libclang's clang-c/Index.h, which is only
// on the default include path for a toolchain installed in /usr.
if (const fs::path& llvmInclude = GetToolchain().llvmIncludeDir; !llvmInclude.empty()) {
CrafterBuildLib->compileFlags.push_back(std::format("-I{}", llvmInclude.string()));
musl host support: bootstrap and run on Alpine (x86_64-alpine-linux-musl) The Linux host code paths were gated on the x86_64_pc_linux_gnu target define alone, and LoadProject hardcoded --target=x86_64-pc-linux-gnu when compiling project.cpp and the module PCMs. Both break on musl hosts: the glibc release launcher cannot run there at all (no glibc loader; gcompat lacks libgcc_s and the __isoc23_* symbols), and a musl-built launcher would still compile project.cpp for the wrong libc. - The host gates test clang's __linux__ instead of one triple's define: they mean "Linux host", whatever the libc (or, later, the CPU). - LoadProject derives the host triple from HostTarget() (clang's -print-target-triple), which is also more correct on glibc distros whose triple isn't x86_64-pc-linux-gnu. - project.cpp / the cmake libc++ flags treat any *-linux-gnu or *-linux-musl target as Linux. - build.sh targets the host toolchain's triple (CRAFTER_BUILD_TARGET overrides) and derives the per-target define from it. On Arch this is byte-for-byte the previous behaviour. - CI: a release-musl job bootstraps on alpine:edge, runs the tests, and attaches crafter-build-linux-x86_64-musl-v2.tar.gz to the rolling latest release (via the API, so the glibc assets survive). Dynamic against musl libc++: the launcher dlopens project.so, so it cannot be fully static. First consumer: imsd's package CI, which cross-compiles for aarch64 from an Alpine container. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 23:49:00 +02:00
}
feat(ci): drop beta and latest, release signed tags on master A push to master published the `beta` branch and moved the rolling `latest` tag and its "Latest master build" prerelease, and a pushed X.Y.Z tag made the release and published `stable`. The owner wants a release for every push to master, made by the signed tag that goes with it, and nothing for a push without one. So `beta`, `latest` and the branch trigger are gone: the workflow runs for pushed tags, pull requests and manual runs only, and the `latest` tag and its prerelease have been deleted from the forge. `beta` gets no more builds, and its installations would not hear of it: the release notes ship in stable builds only. The Publish step marks beta's last build end-of-life, once, with a reason that names stable, and the next `flatpak update` of a beta installation prints it. The reason also names the branch, because a non-interactive update prints only the app's name with it. Before building, a tag run now checks the tag: it has to be annotated and signed by the owner as Forgejo verifies it, its commit has to be on master, its version has to be X.Y.Z and newer than every release the forge has published, its own included (a later tag whose run still queues does not count), and the metainfo's newest <release> entry has to be that version. The tag run checked only the last of these. It reads the tag from the forge's API, because the checkout fetches a pushed tag again as a plain ref to its commit, so the job's clone never has the annotated tag, and Forgejo verifies a signed tag's own signature but falls back to the commit's for an unsigned one, so the step also requires that the verdict covers the tag's payload. The metainfo's entry is read once, as the first <release> element: the Version step takes its version and renders its notes into release-notes.md with the renderer the Release notes step had, and stops the run when they come out empty, so a comment or another attribute order cannot give a release one entry's version and another's notes. It does so on every run, pull requests and manual runs included, so a broken entry shows before a release. Release runs share a concurrency group, so they queue one behind another; a pull request still cancels its own outdated run. A failed release run can be re-run while no newer release exists, since its tag is still on its commit; a release that an attempt left half made has to be deleted first. The release step runs without `override`, which would delete a tag that has moved off the run's commit since the Version step and tag the old commit instead. A manual run no longer publishes anything; it used to publish `beta` and move `latest` from whichever branch it was started on. No step pushes to git, so the checkout keeps no credentials. git describe in build.sh, project.cpp and the workflow has no `latest` tag left to exclude.
2026-11-02 11:42:58 +01:00
// The version the binary reports: CI sets it, a checkout describes
// itself, anything else is a development build. A define on the
// library, so each version is its own library variant.
feat(toolchain): resolve the compiler in one place Every clang++, clang and llvm-ar the tool spawned was a bare name on PATH, the std module source was /usr/share/libc++/v1/std.cppm, the WASI sysroot /usr/share/wasi-sysroot and the mingw headers /usr/x86_64-w64-mingw32, spelled out at eighteen call sites. A toolchain installed anywhere else, which is what the Flatpak ships under /app, had no way in. Crafter.Build:Toolchain resolves all of it once per process: CRAFTER_BUILD_LLVM_DIR, else a clang++ installed beside crafter-build (<prefix>/bin, found through the same walk GetCrafterBuildHome does), else PATH. What sits beside the compiler is used when present: its libclang.so, its clang-c headers, its std module source, its WASI sysroot. An explicit prefix without a clang++ is an error rather than a fallback, for the same reason CRAFTER_BUILD_LIBCLANG was already exclusive. CRAFTER_BUILD_LIBCXX_DIR points at a libc++ install other than the compiler's own, and CRAFTER_MINGW_DIR now does what its help line always claimed: it is passed as --sysroot for the mingw target. Binaries linked by a toolchain outside /usr get an rpath to its lib dir, since its libc++.so.1 is not on the loader's default path. HostTarget() is the resolved clang's -print-target-triple. A clang built without a vendor reports x86_64-unknown-linux-gnu where Arch's reports x86_64-pc-linux-gnu, so target equality that decides whether a test runs locally and which targets a bare `test` sweeps goes through SameTarget, which ignores the vendor field. The strings themselves are never rewritten: clang rejects a PCM whose triple differs from the importing unit's. The examples and README stop hardcoding the host triple; the default is already the host. `crafter-build --version` prints the version baked in at build time (CRAFTER_BUILD_VERSION, else `git describe`, else 0.0.0-dev), the compiler and the host triple, and is answered before any argument is forwarded to project.cpp. The version is a define on the library, so each version is its own library variant and relinks the executable and tests once per commit. build.sh gains a shebang and `set -eu`, honours CRAFTER_BUILD_LLVM_DIR and CRAFTER_BUILD_VERSION, skips the glslang clone when it is already there, and writes a fresh archive instead of appending to one that may hold members from an older layout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 22:26:31 +02:00
std::string version;
if (const char* env = std::getenv("CRAFTER_BUILD_VERSION"); env && *env) {
version = env;
} else {
feat(ci): drop beta and latest, release signed tags on master A push to master published the `beta` branch and moved the rolling `latest` tag and its "Latest master build" prerelease, and a pushed X.Y.Z tag made the release and published `stable`. The owner wants a release for every push to master, made by the signed tag that goes with it, and nothing for a push without one. So `beta`, `latest` and the branch trigger are gone: the workflow runs for pushed tags, pull requests and manual runs only, and the `latest` tag and its prerelease have been deleted from the forge. `beta` gets no more builds, and its installations would not hear of it: the release notes ship in stable builds only. The Publish step marks beta's last build end-of-life, once, with a reason that names stable, and the next `flatpak update` of a beta installation prints it. The reason also names the branch, because a non-interactive update prints only the app's name with it. Before building, a tag run now checks the tag: it has to be annotated and signed by the owner as Forgejo verifies it, its commit has to be on master, its version has to be X.Y.Z and newer than every release the forge has published, its own included (a later tag whose run still queues does not count), and the metainfo's newest <release> entry has to be that version. The tag run checked only the last of these. It reads the tag from the forge's API, because the checkout fetches a pushed tag again as a plain ref to its commit, so the job's clone never has the annotated tag, and Forgejo verifies a signed tag's own signature but falls back to the commit's for an unsigned one, so the step also requires that the verdict covers the tag's payload. The metainfo's entry is read once, as the first <release> element: the Version step takes its version and renders its notes into release-notes.md with the renderer the Release notes step had, and stops the run when they come out empty, so a comment or another attribute order cannot give a release one entry's version and another's notes. It does so on every run, pull requests and manual runs included, so a broken entry shows before a release. Release runs share a concurrency group, so they queue one behind another; a pull request still cancels its own outdated run. A failed release run can be re-run while no newer release exists, since its tag is still on its commit; a release that an attempt left half made has to be deleted first. The release step runs without `override`, which would delete a tag that has moved off the run's commit since the Version step and tag the old commit instead. A manual run no longer publishes anything; it used to publish `beta` and move `latest` from whichever branch it was started on. No step pushes to git, so the checkout keeps no credentials. git describe in build.sh, project.cpp and the workflow has no `latest` tag left to exclude.
2026-11-02 11:42:58 +01:00
auto described = RunCommandWithTimeout("git describe --tags --always --dirty 2>/dev/null", std::chrono::seconds(10));
feat(toolchain): resolve the compiler in one place Every clang++, clang and llvm-ar the tool spawned was a bare name on PATH, the std module source was /usr/share/libc++/v1/std.cppm, the WASI sysroot /usr/share/wasi-sysroot and the mingw headers /usr/x86_64-w64-mingw32, spelled out at eighteen call sites. A toolchain installed anywhere else, which is what the Flatpak ships under /app, had no way in. Crafter.Build:Toolchain resolves all of it once per process: CRAFTER_BUILD_LLVM_DIR, else a clang++ installed beside crafter-build (<prefix>/bin, found through the same walk GetCrafterBuildHome does), else PATH. What sits beside the compiler is used when present: its libclang.so, its clang-c headers, its std module source, its WASI sysroot. An explicit prefix without a clang++ is an error rather than a fallback, for the same reason CRAFTER_BUILD_LIBCLANG was already exclusive. CRAFTER_BUILD_LIBCXX_DIR points at a libc++ install other than the compiler's own, and CRAFTER_MINGW_DIR now does what its help line always claimed: it is passed as --sysroot for the mingw target. Binaries linked by a toolchain outside /usr get an rpath to its lib dir, since its libc++.so.1 is not on the loader's default path. HostTarget() is the resolved clang's -print-target-triple. A clang built without a vendor reports x86_64-unknown-linux-gnu where Arch's reports x86_64-pc-linux-gnu, so target equality that decides whether a test runs locally and which targets a bare `test` sweeps goes through SameTarget, which ignores the vendor field. The strings themselves are never rewritten: clang rejects a PCM whose triple differs from the importing unit's. The examples and README stop hardcoding the host triple; the default is already the host. `crafter-build --version` prints the version baked in at build time (CRAFTER_BUILD_VERSION, else `git describe`, else 0.0.0-dev), the compiler and the host triple, and is answered before any argument is forwarded to project.cpp. The version is a define on the library, so each version is its own library variant and relinks the executable and tests once per commit. build.sh gains a shebang and `set -eu`, honours CRAFTER_BUILD_LLVM_DIR and CRAFTER_BUILD_VERSION, skips the glslang clone when it is already there, and writes a fresh archive instead of appending to one that may hold members from an older layout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 22:26:31 +02:00
version = described.output;
while (!version.empty() && (version.back() == '\n' || version.back() == '\r')) version.pop_back();
if (described.exitCode != 0 || version.empty()) version = "0.0.0-dev";
}
// Backslash-escaped quotes: the define travels through the shell before
// it reaches clang, which must still see a string literal.
CrafterBuildLib->defines.push_back({"CRAFTER_BUILD_VERSION", std::format("\\\"{}\\\"", version)});
{
feat(build): run a build's steps on one worker per hardware thread Build() started a thread for every stale shader, asset, C, CUDA and C++ unit, and Module::Compile one more for every stale partition, and nothing bounded how many of them ran their step at once. Jorijn asked for the amount of parallelism to be limited by the amount of threads instead of just starting one per file; the threads are taken here to be the machine's hardware threads. The new :Jobs partition holds the two pieces. JobPool is worker threads behind one queue, started as jobs need them up to a fixed number, and JobPool::Process() is the pool of the process: at most a worker per hardware thread, one where std::thread::hardware_concurrency does not know. JobGroup is the jobs of one build on a pool. A job starts once the jobs it was added after have finished; the first job to fail keeps the ones that have not started from starting, and Wait() returns its error. No job waits for another job, and a JobGroup made on a worker of its own pool throws: a worker that waited for a job still in the queue would hold the thread that job needs. Build() adds what it did on those threads to a JobGroup instead, and the group's first error replaces the buildCancelled and buildError pair the threads set. The module units no longer block on the `compiled` flag of the units they import: Schedule() replaces Compile() on Module, ModulePartition and Implementation and adds a unit's jobs after the jobs that write the BMIs it imports. An interface unit is two jobs, its BMI and then its object from the BMI, so the units importing it start when the first is done, as they did when one thread ran both commands and raised the flag in between. A primary interface now waits for the BMIs of its partitions and no longer for their objects. Each of the two jobs has a progress line, "Precompiling X.cppm" and "Compiling X.cppm" for every interface unit, where a module and its partitions shared one "Compiling interface X". RunBuildCommand runs its command on a worker of the process's pool: on the calling thread when that is one, otherwise it waits for one. A link, an archive, the std module's precompile and project.cpp's compile are steps under the limit that way. The threads Build() starts per dependency and per external dependency stay: one of the first runs the dependency's own Build(), or waits for the thread that does, and one of the second runs git and cmake. With the BMI and the object as two jobs, a build that fails between them has written the BMI and skips the object, and Check, which reads staleness off the BMI, would call the unit built from then on. Schedule() therefore adds the object job alone for a unit whose BMI is up to date and whose object is missing or older than the BMI. A build interrupted between the two commands, or one whose second command failed, left the same behind before, and it stayed: the link took the object of the source before the edit, or failed on the missing one. ImportCycleError is now what keeps Schedule() from following a round of imports without end. The limit is on steps. Outside it, as AGENTS.template.md lists: an ExternalDependency's cmake --build, which keeps its own --parallel of as many jobs as there are hardware threads; the tests RunTests runs, --jobs= of them at once as before; the Crafter.Build modules EnsureCrafterBuildPcms precompiles one after another; and the threads a step starts for itself, which lld does for a link and Crafter.Asset's GDeflate compressor for an asset. The pool is one process's. The --help text says what a build runs at once and that test --jobs= counts tests. ConcurrentDependencyReset read the `compiled` flag, which is gone. It asserts on `checked` and `scheduled` instead, the state a reset from another build's thread would clear now, with a unit scheduled twice as the result, and the comment in its fixture says what the implementation unit comes after now. TransitiveInterfaceChange's comment names Schedule() where it named Compile() as what honours a partition's imports. Two comments in :Platform that spoke of worker threads, a word that now means the pool's, name the threads they mean. The bug-prover lens's section said shaders compile on a thread of their own each, and describes the pool now.
2026-11-13 17:59:55 +01:00
std::array<fs::path, 16> interfaces = {
"interfaces/Crafter.Build",
feat(toolchain): resolve the compiler in one place Every clang++, clang and llvm-ar the tool spawned was a bare name on PATH, the std module source was /usr/share/libc++/v1/std.cppm, the WASI sysroot /usr/share/wasi-sysroot and the mingw headers /usr/x86_64-w64-mingw32, spelled out at eighteen call sites. A toolchain installed anywhere else, which is what the Flatpak ships under /app, had no way in. Crafter.Build:Toolchain resolves all of it once per process: CRAFTER_BUILD_LLVM_DIR, else a clang++ installed beside crafter-build (<prefix>/bin, found through the same walk GetCrafterBuildHome does), else PATH. What sits beside the compiler is used when present: its libclang.so, its clang-c headers, its std module source, its WASI sysroot. An explicit prefix without a clang++ is an error rather than a fallback, for the same reason CRAFTER_BUILD_LIBCLANG was already exclusive. CRAFTER_BUILD_LIBCXX_DIR points at a libc++ install other than the compiler's own, and CRAFTER_MINGW_DIR now does what its help line always claimed: it is passed as --sysroot for the mingw target. Binaries linked by a toolchain outside /usr get an rpath to its lib dir, since its libc++.so.1 is not on the loader's default path. HostTarget() is the resolved clang's -print-target-triple. A clang built without a vendor reports x86_64-unknown-linux-gnu where Arch's reports x86_64-pc-linux-gnu, so target equality that decides whether a test runs locally and which targets a bare `test` sweeps goes through SameTarget, which ignores the vendor field. The strings themselves are never rewritten: clang rejects a PCM whose triple differs from the importing unit's. The examples and README stop hardcoding the host triple; the default is already the host. `crafter-build --version` prints the version baked in at build time (CRAFTER_BUILD_VERSION, else `git describe`, else 0.0.0-dev), the compiler and the host triple, and is answered before any argument is forwarded to project.cpp. The version is a define on the library, so each version is its own library variant and relinks the executable and tests once per commit. build.sh gains a shebang and `set -eu`, honours CRAFTER_BUILD_LLVM_DIR and CRAFTER_BUILD_VERSION, skips the glslang clone when it is already there, and writes a fresh archive instead of appending to one that may hold members from an older layout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 22:26:31 +02:00
"interfaces/Crafter.Build-Toolchain",
"interfaces/Crafter.Build-Shader",
"interfaces/Crafter.Build-Platform",
feat: lay an executable out as the files/ of a Flatpak A Linux executable built by the Flatpak crafter-build links the libc++, libc++abi and libunwind in its /app/lib and the Sdk's glibc, so it runs inside crafter-build's sandbox and practically nowhere else: a host needs glibc 2.38 or newer and all three LLVM libraries, which not even Arch has. A program built here is meant to run in a Flatpak, so it can now be laid out as one: with cfg.packaging = Packaging::Flatpak, or --packaging=flatpak where the project.cpp crafter-build was pointed at calls ApplyStandardArgs, its BinDir() holds files/, what becomes /app in the app's sandbox, and -r runs the program there against the libraries the app carries. The program is linked into files/bin, where its shaders, files and assets land too (ProgramDir()), with $ORIGIN/../lib as its one run path, and the new :Flatpak partition writes the rest of files/: files/lib with the LLVM runtime libraries, located one by one through clang, and whatever else the program needs, read with llvm-readelf, that the directories of the shared libraries it is built on hold, the ones an unpackaged link records as run paths, or the toolchain's own lib dir, /app/lib in crafter-build's Flatpak, which the link searches too; and the desktop entry, metainfo and icons under the app-id in files/share, the entry refused when its Icon= is not the app-id or desktop-file-validate, where there is one, rejects it, and an icon that is not an .svg or a square .png. The metadata and export/ of a build directory are flatpak build-finish's to write, and crafter-build keeps no copy of its rules: what a permission means and what the host sees of an app change with flatpak's releases, and a copy would have to follow every one. The writer copies a file only when its content differs, compared a block at a time so that a large file costs no more memory than a small one, and writes one only when what it would write differs, never deciding by an mtime, which ostree sets to 0 for every file of /app, and works the program's libraries out on every write, which reads only their dynamic sections, since a library replaced in place, as by a toolchain update, can need others, which FlatpakLibraryChange checks; it prunes from files/bin each top-level entry an earlier build put there and this one does not, reporting those the program wrote there itself. What cannot be a Flatpak is refused before anything is built, saying why: a Windows or wasm executable, a build against a sysroot or for musl, another architecture than the runtime's, a build against CRAFTER_BUILD_LIBCXX_DIR, whose libc++ the Flatpak would not carry, and a build by a native crafter-build, which links the host's glibc: a native process knows no Flatpak runtime, from /.flatpak-info, unless CRAFTER_BUILD_FLATPAK_INFO, the tests' hook, names a file with one. Default stays the executable as linked for now, RunTests runs every test as linked, whatever its Configuration asks for, and RunLint works out its compile command so, and a forwarded --packaging= leaves a dependency's executables alone, since consumers run them by path. A dependency that packages its own executable gets its desktop file, metainfo and icons rebased by the loader as its cfg.files are, so they are its own whatever directory the consumer builds from. Only a Flatpak is keyed into VariantId, so every other configuration keeps its directory, but for one given --packaging=, which was a project arg, hashed into VariantId, and is a standard arg now, a dependency's included. The app-id and what a Flatpak is installed as are not keyed: they change files/share, never what is compiled. The asset name map, kept three times, twice in Build() and once for the browser runtime's files.json, is one function now, CompressedAssetName; CompressAsset, in Crafter.Build-Asset.cpp, keeps the list of the extensions it loads, which has to agree with it. Each copy a Flatpak build makes into the program's directory, of its shaders, assets, cfg.files and what its dependencies forward, records the top-level name it places there, the names of what a directory holds for one copied into it itself ("data/", "data/."), and those are what the writer keeps in files/bin; a build that fails after copying adds them to the writer's record all the same, so the next write removes what no build places any more. SharedLibraryRuns now also packages its program as a Flatpak, whose files/lib has to carry libgreet.so for it to start.
2026-11-01 19:20:55 +01:00
"interfaces/Crafter.Build-Flatpak",
feat(build): run a build's steps on one worker per hardware thread Build() started a thread for every stale shader, asset, C, CUDA and C++ unit, and Module::Compile one more for every stale partition, and nothing bounded how many of them ran their step at once. Jorijn asked for the amount of parallelism to be limited by the amount of threads instead of just starting one per file; the threads are taken here to be the machine's hardware threads. The new :Jobs partition holds the two pieces. JobPool is worker threads behind one queue, started as jobs need them up to a fixed number, and JobPool::Process() is the pool of the process: at most a worker per hardware thread, one where std::thread::hardware_concurrency does not know. JobGroup is the jobs of one build on a pool. A job starts once the jobs it was added after have finished; the first job to fail keeps the ones that have not started from starting, and Wait() returns its error. No job waits for another job, and a JobGroup made on a worker of its own pool throws: a worker that waited for a job still in the queue would hold the thread that job needs. Build() adds what it did on those threads to a JobGroup instead, and the group's first error replaces the buildCancelled and buildError pair the threads set. The module units no longer block on the `compiled` flag of the units they import: Schedule() replaces Compile() on Module, ModulePartition and Implementation and adds a unit's jobs after the jobs that write the BMIs it imports. An interface unit is two jobs, its BMI and then its object from the BMI, so the units importing it start when the first is done, as they did when one thread ran both commands and raised the flag in between. A primary interface now waits for the BMIs of its partitions and no longer for their objects. Each of the two jobs has a progress line, "Precompiling X.cppm" and "Compiling X.cppm" for every interface unit, where a module and its partitions shared one "Compiling interface X". RunBuildCommand runs its command on a worker of the process's pool: on the calling thread when that is one, otherwise it waits for one. A link, an archive, the std module's precompile and project.cpp's compile are steps under the limit that way. The threads Build() starts per dependency and per external dependency stay: one of the first runs the dependency's own Build(), or waits for the thread that does, and one of the second runs git and cmake. With the BMI and the object as two jobs, a build that fails between them has written the BMI and skips the object, and Check, which reads staleness off the BMI, would call the unit built from then on. Schedule() therefore adds the object job alone for a unit whose BMI is up to date and whose object is missing or older than the BMI. A build interrupted between the two commands, or one whose second command failed, left the same behind before, and it stayed: the link took the object of the source before the edit, or failed on the missing one. ImportCycleError is now what keeps Schedule() from following a round of imports without end. The limit is on steps. Outside it, as AGENTS.template.md lists: an ExternalDependency's cmake --build, which keeps its own --parallel of as many jobs as there are hardware threads; the tests RunTests runs, --jobs= of them at once as before; the Crafter.Build modules EnsureCrafterBuildPcms precompiles one after another; and the threads a step starts for itself, which lld does for a link and Crafter.Asset's GDeflate compressor for an asset. The pool is one process's. The --help text says what a build runs at once and that test --jobs= counts tests. ConcurrentDependencyReset read the `compiled` flag, which is gone. It asserts on `checked` and `scheduled` instead, the state a reset from another build's thread would clear now, with a unit scheduled twice as the result, and the comment in its fixture says what the implementation unit comes after now. TransitiveInterfaceChange's comment names Schedule() where it named Compile() as what honours a partition's imports. Two comments in :Platform that spoke of worker threads, a word that now means the pool's, name the threads they mean. The bug-prover lens's section said shaders compile on a thread of their own each, and describes the pool now.
2026-11-13 17:59:55 +01:00
"interfaces/Crafter.Build-Jobs",
"interfaces/Crafter.Build-Interface",
"interfaces/Crafter.Build-Implementation",
"interfaces/Crafter.Build-External",
feat(agents): keep dependencies' AGENTS.consumer.md in AGENTS.md An agent working on a crafter-build project reads its AGENTS.md, and learns nothing there about the libraries the project builds against unless someone copied that in by hand. This repository shows the cost: the code style section of its AGENTS.md restates what Crafter.LintRules enforces, and goes stale whenever the rules change. A library now ships those notes itself, as AGENTS.consumer.md beside its project.cpp; nothing in its project.cpp changes. When a consumer has an AGENTS.md beside its own project.cpp, `crafter-build` and `crafter-build test` keep a section in it, between two marker comments, holding its dependencies' notes. The section is appended the first time and rewritten in place after that. The file is written only when the section changes, and an AGENTS.md is never created. lint, format, run and clean leave it alone. The update runs after loading, which has just fetched every dependency, and before compiling, so a build that fails still has the notes. cfg.dependencyNotes picks the dependencies. Transitive, the default, follows `dependencies` all the way down from the project's own configurations, its tests and its `#pragma crafter dependency` tooling; Direct stops at the first loaded project on each path; None removes the section. A dependency's own pragma tooling never counts: it is about how that dependency is built, not how it is used, and being no `dependencies` edge it is never reached. Nor are a dependency's tests: nothing builds them for the consumer, and their configurations can point at a local their project file has since moved out of. The walk has to know which Configurations belong to another project, and where that project lives, and cfg.path cannot say: only the Configuration GitProject and LocalProject return is rebased, so a dependency's internal configurations keep "./", which resolves to the consumer. The loader records it instead, LoadedProjectOf beside the project cache, and keeps what the root's pragmas resolved to past the frame LoadProject pops, PragmaDependencies. Neither is exported. The markers count only as whole lines outside fenced code blocks, so documentation can quote them. Unbalanced markers and a document ending inside a code block leave the file alone with a warning: guessing which part of someone's file is generated would overwrite their text, and missing the section would add another one on every build. A note that would break the section when it is read back, through a marker line of its own or a code block it never closes, is left out with a warning. The file is replaced through a temporary renamed onto the symlink's target, so a linked AGENTS.md stays a link and a write cut short leaves the old file rather than part of the new one. The code is a new partition, Crafter.Build:Agents, listed in build.sh, CrafterBuildModules, project.cpp and the umbrella. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 03:18:06 +01:00
"interfaces/Crafter.Build-Agents",
"interfaces/Crafter.Build-Clang",
"interfaces/Crafter.Build-Test",
2026-07-23 01:24:42 +02:00
"interfaces/Crafter.Build-Lint",
feat(script): scripts in project.cpp, run with `crafter-build run` A project.cpp could describe how a project is built, tested and linted, but not the chores around it: packaging, installing, publishing. Those stayed shell lines in a README or in someone's history. Configuration gains `scripts`, a plain list like `defines`. A Script is a name and a C++ callback, as a lint rule is; there is no script language and no config file. The callback gets a ScriptContext (the project, the project file's directory, the arguments) and returns the exit status. ctx.Run runs a shell command with the terminal attached and returns its status. It is only stored when project.cpp loads, which happens for every verb and for every project that depends on this one. `crafter-build run <name> [args...]` runs one, a bare `run` lists them. Only the scripts of the project crafter-build was pointed at are runnable, never a dependency's. Everything after the script's name is handed to the script untouched. The two branches that do this sit ahead of every other branch of the parse loop, --version and --help included. Below the verbs, `run package clean` would delete build/, and any other word would land in the project's args and so in the variant hash, moving the build to another directory. Options before the name keep their meaning, so project args go there. The driver is its own partition, :Script. It refuses a project with no scripts, a name that is empty or starts with '-' (it could never be typed), a name declared twice (running either would be a guess) and an unknown name, each with exit 1 and without running anything. A script that throws exits 1. A return value outside 0..255 becomes 1: an exit status is eight bits, and a raw wait status such as 256 would otherwise wrap to success. Two helpers in :Platform: - RunCommandAttached runs a command with inherited stdio. Every helper so far captured through popen, which is right for a compile step and useless for a command that runs for half an hour or asks a question. It reads the wait status through DecodeWaitStatus, which RunCommandChecked and RunCommandWithTimeout now share. - ShellQuote is exported. It existed twice, as ShellQuote in :External and ShellQuoteSh in :Test, with the same behaviour; both are gone. A script that puts a path into a command needs it too. Not included: a string shorthand for one-command scripts (a one-line lambda covers it) and a ctx.Build() helper (Build() is already exported). A new partition and new exported symbols: run ./build.sh. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 18:16:00 +02:00
"interfaces/Crafter.Build-Script",
2026-04-29 03:27:11 +02:00
"interfaces/Crafter.Build-Progress",
2026-05-12 01:16:40 +02:00
"interfaces/Crafter.Build-Asset",
};
feat(build): run a build's steps on one worker per hardware thread Build() started a thread for every stale shader, asset, C, CUDA and C++ unit, and Module::Compile one more for every stale partition, and nothing bounded how many of them ran their step at once. Jorijn asked for the amount of parallelism to be limited by the amount of threads instead of just starting one per file; the threads are taken here to be the machine's hardware threads. The new :Jobs partition holds the two pieces. JobPool is worker threads behind one queue, started as jobs need them up to a fixed number, and JobPool::Process() is the pool of the process: at most a worker per hardware thread, one where std::thread::hardware_concurrency does not know. JobGroup is the jobs of one build on a pool. A job starts once the jobs it was added after have finished; the first job to fail keeps the ones that have not started from starting, and Wait() returns its error. No job waits for another job, and a JobGroup made on a worker of its own pool throws: a worker that waited for a job still in the queue would hold the thread that job needs. Build() adds what it did on those threads to a JobGroup instead, and the group's first error replaces the buildCancelled and buildError pair the threads set. The module units no longer block on the `compiled` flag of the units they import: Schedule() replaces Compile() on Module, ModulePartition and Implementation and adds a unit's jobs after the jobs that write the BMIs it imports. An interface unit is two jobs, its BMI and then its object from the BMI, so the units importing it start when the first is done, as they did when one thread ran both commands and raised the flag in between. A primary interface now waits for the BMIs of its partitions and no longer for their objects. Each of the two jobs has a progress line, "Precompiling X.cppm" and "Compiling X.cppm" for every interface unit, where a module and its partitions shared one "Compiling interface X". RunBuildCommand runs its command on a worker of the process's pool: on the calling thread when that is one, otherwise it waits for one. A link, an archive, the std module's precompile and project.cpp's compile are steps under the limit that way. The threads Build() starts per dependency and per external dependency stay: one of the first runs the dependency's own Build(), or waits for the thread that does, and one of the second runs git and cmake. With the BMI and the object as two jobs, a build that fails between them has written the BMI and skips the object, and Check, which reads staleness off the BMI, would call the unit built from then on. Schedule() therefore adds the object job alone for a unit whose BMI is up to date and whose object is missing or older than the BMI. A build interrupted between the two commands, or one whose second command failed, left the same behind before, and it stayed: the link took the object of the source before the edit, or failed on the missing one. ImportCycleError is now what keeps Schedule() from following a round of imports without end. The limit is on steps. Outside it, as AGENTS.template.md lists: an ExternalDependency's cmake --build, which keeps its own --parallel of as many jobs as there are hardware threads; the tests RunTests runs, --jobs= of them at once as before; the Crafter.Build modules EnsureCrafterBuildPcms precompiles one after another; and the threads a step starts for itself, which lld does for a link and Crafter.Asset's GDeflate compressor for an asset. The pool is one process's. The --help text says what a build runs at once and that test --jobs= counts tests. ConcurrentDependencyReset read the `compiled` flag, which is gone. It asserts on `checked` and `scheduled` instead, the state a reset from another build's thread would clear now, with a unit scheduled twice as the result, and the comment in its fixture says what the implementation unit comes after now. TransitiveInterfaceChange's comment names Schedule() where it named Compile() as what honours a partition's imports. Two comments in :Platform that spoke of worker threads, a word that now means the pool's, name the threads they mean. The bug-prover lens's section said shaders compile on a thread of their own each, and describes the pool now.
2026-11-13 17:59:55 +01:00
std::array<fs::path, 15> implementations = {
feat(toolchain): resolve the compiler in one place Every clang++, clang and llvm-ar the tool spawned was a bare name on PATH, the std module source was /usr/share/libc++/v1/std.cppm, the WASI sysroot /usr/share/wasi-sysroot and the mingw headers /usr/x86_64-w64-mingw32, spelled out at eighteen call sites. A toolchain installed anywhere else, which is what the Flatpak ships under /app, had no way in. Crafter.Build:Toolchain resolves all of it once per process: CRAFTER_BUILD_LLVM_DIR, else a clang++ installed beside crafter-build (<prefix>/bin, found through the same walk GetCrafterBuildHome does), else PATH. What sits beside the compiler is used when present: its libclang.so, its clang-c headers, its std module source, its WASI sysroot. An explicit prefix without a clang++ is an error rather than a fallback, for the same reason CRAFTER_BUILD_LIBCLANG was already exclusive. CRAFTER_BUILD_LIBCXX_DIR points at a libc++ install other than the compiler's own, and CRAFTER_MINGW_DIR now does what its help line always claimed: it is passed as --sysroot for the mingw target. Binaries linked by a toolchain outside /usr get an rpath to its lib dir, since its libc++.so.1 is not on the loader's default path. HostTarget() is the resolved clang's -print-target-triple. A clang built without a vendor reports x86_64-unknown-linux-gnu where Arch's reports x86_64-pc-linux-gnu, so target equality that decides whether a test runs locally and which targets a bare `test` sweeps goes through SameTarget, which ignores the vendor field. The strings themselves are never rewritten: clang rejects a PCM whose triple differs from the importing unit's. The examples and README stop hardcoding the host triple; the default is already the host. `crafter-build --version` prints the version baked in at build time (CRAFTER_BUILD_VERSION, else `git describe`, else 0.0.0-dev), the compiler and the host triple, and is answered before any argument is forwarded to project.cpp. The version is a define on the library, so each version is its own library variant and relinks the executable and tests once per commit. build.sh gains a shebang and `set -eu`, honours CRAFTER_BUILD_LLVM_DIR and CRAFTER_BUILD_VERSION, skips the glslang clone when it is already there, and writes a fresh archive instead of appending to one that may hold members from an older layout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 22:26:31 +02:00
"implementations/Crafter.Build-Toolchain",
"implementations/Crafter.Build-Shader",
"implementations/Crafter.Build-Platform",
feat: lay an executable out as the files/ of a Flatpak A Linux executable built by the Flatpak crafter-build links the libc++, libc++abi and libunwind in its /app/lib and the Sdk's glibc, so it runs inside crafter-build's sandbox and practically nowhere else: a host needs glibc 2.38 or newer and all three LLVM libraries, which not even Arch has. A program built here is meant to run in a Flatpak, so it can now be laid out as one: with cfg.packaging = Packaging::Flatpak, or --packaging=flatpak where the project.cpp crafter-build was pointed at calls ApplyStandardArgs, its BinDir() holds files/, what becomes /app in the app's sandbox, and -r runs the program there against the libraries the app carries. The program is linked into files/bin, where its shaders, files and assets land too (ProgramDir()), with $ORIGIN/../lib as its one run path, and the new :Flatpak partition writes the rest of files/: files/lib with the LLVM runtime libraries, located one by one through clang, and whatever else the program needs, read with llvm-readelf, that the directories of the shared libraries it is built on hold, the ones an unpackaged link records as run paths, or the toolchain's own lib dir, /app/lib in crafter-build's Flatpak, which the link searches too; and the desktop entry, metainfo and icons under the app-id in files/share, the entry refused when its Icon= is not the app-id or desktop-file-validate, where there is one, rejects it, and an icon that is not an .svg or a square .png. The metadata and export/ of a build directory are flatpak build-finish's to write, and crafter-build keeps no copy of its rules: what a permission means and what the host sees of an app change with flatpak's releases, and a copy would have to follow every one. The writer copies a file only when its content differs, compared a block at a time so that a large file costs no more memory than a small one, and writes one only when what it would write differs, never deciding by an mtime, which ostree sets to 0 for every file of /app, and works the program's libraries out on every write, which reads only their dynamic sections, since a library replaced in place, as by a toolchain update, can need others, which FlatpakLibraryChange checks; it prunes from files/bin each top-level entry an earlier build put there and this one does not, reporting those the program wrote there itself. What cannot be a Flatpak is refused before anything is built, saying why: a Windows or wasm executable, a build against a sysroot or for musl, another architecture than the runtime's, a build against CRAFTER_BUILD_LIBCXX_DIR, whose libc++ the Flatpak would not carry, and a build by a native crafter-build, which links the host's glibc: a native process knows no Flatpak runtime, from /.flatpak-info, unless CRAFTER_BUILD_FLATPAK_INFO, the tests' hook, names a file with one. Default stays the executable as linked for now, RunTests runs every test as linked, whatever its Configuration asks for, and RunLint works out its compile command so, and a forwarded --packaging= leaves a dependency's executables alone, since consumers run them by path. A dependency that packages its own executable gets its desktop file, metainfo and icons rebased by the loader as its cfg.files are, so they are its own whatever directory the consumer builds from. Only a Flatpak is keyed into VariantId, so every other configuration keeps its directory, but for one given --packaging=, which was a project arg, hashed into VariantId, and is a standard arg now, a dependency's included. The app-id and what a Flatpak is installed as are not keyed: they change files/share, never what is compiled. The asset name map, kept three times, twice in Build() and once for the browser runtime's files.json, is one function now, CompressedAssetName; CompressAsset, in Crafter.Build-Asset.cpp, keeps the list of the extensions it loads, which has to agree with it. Each copy a Flatpak build makes into the program's directory, of its shaders, assets, cfg.files and what its dependencies forward, records the top-level name it places there, the names of what a directory holds for one copied into it itself ("data/", "data/."), and those are what the writer keeps in files/bin; a build that fails after copying adds them to the writer's record all the same, so the next write removes what no build places any more. SharedLibraryRuns now also packages its program as a Flatpak, whose files/lib has to carry libgreet.so for it to start.
2026-11-01 19:20:55 +01:00
"implementations/Crafter.Build-Flatpak",
feat(build): run a build's steps on one worker per hardware thread Build() started a thread for every stale shader, asset, C, CUDA and C++ unit, and Module::Compile one more for every stale partition, and nothing bounded how many of them ran their step at once. Jorijn asked for the amount of parallelism to be limited by the amount of threads instead of just starting one per file; the threads are taken here to be the machine's hardware threads. The new :Jobs partition holds the two pieces. JobPool is worker threads behind one queue, started as jobs need them up to a fixed number, and JobPool::Process() is the pool of the process: at most a worker per hardware thread, one where std::thread::hardware_concurrency does not know. JobGroup is the jobs of one build on a pool. A job starts once the jobs it was added after have finished; the first job to fail keeps the ones that have not started from starting, and Wait() returns its error. No job waits for another job, and a JobGroup made on a worker of its own pool throws: a worker that waited for a job still in the queue would hold the thread that job needs. Build() adds what it did on those threads to a JobGroup instead, and the group's first error replaces the buildCancelled and buildError pair the threads set. The module units no longer block on the `compiled` flag of the units they import: Schedule() replaces Compile() on Module, ModulePartition and Implementation and adds a unit's jobs after the jobs that write the BMIs it imports. An interface unit is two jobs, its BMI and then its object from the BMI, so the units importing it start when the first is done, as they did when one thread ran both commands and raised the flag in between. A primary interface now waits for the BMIs of its partitions and no longer for their objects. Each of the two jobs has a progress line, "Precompiling X.cppm" and "Compiling X.cppm" for every interface unit, where a module and its partitions shared one "Compiling interface X". RunBuildCommand runs its command on a worker of the process's pool: on the calling thread when that is one, otherwise it waits for one. A link, an archive, the std module's precompile and project.cpp's compile are steps under the limit that way. The threads Build() starts per dependency and per external dependency stay: one of the first runs the dependency's own Build(), or waits for the thread that does, and one of the second runs git and cmake. With the BMI and the object as two jobs, a build that fails between them has written the BMI and skips the object, and Check, which reads staleness off the BMI, would call the unit built from then on. Schedule() therefore adds the object job alone for a unit whose BMI is up to date and whose object is missing or older than the BMI. A build interrupted between the two commands, or one whose second command failed, left the same behind before, and it stayed: the link took the object of the source before the edit, or failed on the missing one. ImportCycleError is now what keeps Schedule() from following a round of imports without end. The limit is on steps. Outside it, as AGENTS.template.md lists: an ExternalDependency's cmake --build, which keeps its own --parallel of as many jobs as there are hardware threads; the tests RunTests runs, --jobs= of them at once as before; the Crafter.Build modules EnsureCrafterBuildPcms precompiles one after another; and the threads a step starts for itself, which lld does for a link and Crafter.Asset's GDeflate compressor for an asset. The pool is one process's. The --help text says what a build runs at once and that test --jobs= counts tests. ConcurrentDependencyReset read the `compiled` flag, which is gone. It asserts on `checked` and `scheduled` instead, the state a reset from another build's thread would clear now, with a unit scheduled twice as the result, and the comment in its fixture says what the implementation unit comes after now. TransitiveInterfaceChange's comment names Schedule() where it named Compile() as what honours a partition's imports. Two comments in :Platform that spoke of worker threads, a word that now means the pool's, name the threads they mean. The bug-prover lens's section said shaders compile on a thread of their own each, and describes the pool now.
2026-11-13 17:59:55 +01:00
"implementations/Crafter.Build-Jobs",
"implementations/Crafter.Build-Interface",
"implementations/Crafter.Build-Implementation",
"implementations/Crafter.Build-External",
feat(agents): keep dependencies' AGENTS.consumer.md in AGENTS.md An agent working on a crafter-build project reads its AGENTS.md, and learns nothing there about the libraries the project builds against unless someone copied that in by hand. This repository shows the cost: the code style section of its AGENTS.md restates what Crafter.LintRules enforces, and goes stale whenever the rules change. A library now ships those notes itself, as AGENTS.consumer.md beside its project.cpp; nothing in its project.cpp changes. When a consumer has an AGENTS.md beside its own project.cpp, `crafter-build` and `crafter-build test` keep a section in it, between two marker comments, holding its dependencies' notes. The section is appended the first time and rewritten in place after that. The file is written only when the section changes, and an AGENTS.md is never created. lint, format, run and clean leave it alone. The update runs after loading, which has just fetched every dependency, and before compiling, so a build that fails still has the notes. cfg.dependencyNotes picks the dependencies. Transitive, the default, follows `dependencies` all the way down from the project's own configurations, its tests and its `#pragma crafter dependency` tooling; Direct stops at the first loaded project on each path; None removes the section. A dependency's own pragma tooling never counts: it is about how that dependency is built, not how it is used, and being no `dependencies` edge it is never reached. Nor are a dependency's tests: nothing builds them for the consumer, and their configurations can point at a local their project file has since moved out of. The walk has to know which Configurations belong to another project, and where that project lives, and cfg.path cannot say: only the Configuration GitProject and LocalProject return is rebased, so a dependency's internal configurations keep "./", which resolves to the consumer. The loader records it instead, LoadedProjectOf beside the project cache, and keeps what the root's pragmas resolved to past the frame LoadProject pops, PragmaDependencies. Neither is exported. The markers count only as whole lines outside fenced code blocks, so documentation can quote them. Unbalanced markers and a document ending inside a code block leave the file alone with a warning: guessing which part of someone's file is generated would overwrite their text, and missing the section would add another one on every build. A note that would break the section when it is read back, through a marker line of its own or a code block it never closes, is left out with a warning. The file is replaced through a temporary renamed onto the symlink's target, so a linked AGENTS.md stays a link and a write cut short leaves the old file rather than part of the new one. The code is a new partition, Crafter.Build:Agents, listed in build.sh, CrafterBuildModules, project.cpp and the umbrella. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 03:18:06 +01:00
"implementations/Crafter.Build-Agents",
"implementations/Crafter.Build-Clang",
"implementations/Crafter.Build-Test",
2026-07-23 01:24:42 +02:00
"implementations/Crafter.Build-Lint",
feat(script): scripts in project.cpp, run with `crafter-build run` A project.cpp could describe how a project is built, tested and linted, but not the chores around it: packaging, installing, publishing. Those stayed shell lines in a README or in someone's history. Configuration gains `scripts`, a plain list like `defines`. A Script is a name and a C++ callback, as a lint rule is; there is no script language and no config file. The callback gets a ScriptContext (the project, the project file's directory, the arguments) and returns the exit status. ctx.Run runs a shell command with the terminal attached and returns its status. It is only stored when project.cpp loads, which happens for every verb and for every project that depends on this one. `crafter-build run <name> [args...]` runs one, a bare `run` lists them. Only the scripts of the project crafter-build was pointed at are runnable, never a dependency's. Everything after the script's name is handed to the script untouched. The two branches that do this sit ahead of every other branch of the parse loop, --version and --help included. Below the verbs, `run package clean` would delete build/, and any other word would land in the project's args and so in the variant hash, moving the build to another directory. Options before the name keep their meaning, so project args go there. The driver is its own partition, :Script. It refuses a project with no scripts, a name that is empty or starts with '-' (it could never be typed), a name declared twice (running either would be a guess) and an unknown name, each with exit 1 and without running anything. A script that throws exits 1. A return value outside 0..255 becomes 1: an exit status is eight bits, and a raw wait status such as 256 would otherwise wrap to success. Two helpers in :Platform: - RunCommandAttached runs a command with inherited stdio. Every helper so far captured through popen, which is right for a compile step and useless for a command that runs for half an hour or asks a question. It reads the wait status through DecodeWaitStatus, which RunCommandChecked and RunCommandWithTimeout now share. - ShellQuote is exported. It existed twice, as ShellQuote in :External and ShellQuoteSh in :Test, with the same behaviour; both are gone. A script that puts a path into a command needs it too. Not included: a string shorthand for one-command scripts (a one-line lambda covers it) and a ctx.Build() helper (Build() is already exported). A new partition and new exported symbols: run ./build.sh. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 18:16:00 +02:00
"implementations/Crafter.Build-Script",
2026-04-29 03:27:11 +02:00
"implementations/Crafter.Build-Progress",
2026-05-12 01:16:40 +02:00
"implementations/Crafter.Build-Asset",
};
2026-07-23 01:24:42 +02:00
CrafterBuildLib->GetInterfacesAndImplementations(interfaces, implementations);
}
2026-07-23 01:24:42 +02:00
ExternalDependency& glslang = CrafterBuildLib->externalDependencies.emplace_back();
2026-04-27 07:04:42 +02:00
glslang.name = "glslang";
glslang.source.url = "https://github.com/KhronosGroup/glslang.git";
glslang.source.branch = "main";
glslang.builder = ExternalBuilder::CMake;
glslang.options = { "-DENABLE_OPT=OFF" };
glslang.includeDirs = { "" };
glslang.libs = { "SPIRV", "GenericCodeGen", "glslang", "OSDependent", "MachineIndependent", "glslang-default-resource-limits" };
Configuration cfg;
cfg.path = "./";
cfg.name = "crafter.build-exe";
cfg.outputName = "crafter-build";
2026-04-29 18:59:01 +02:00
ApplyStandardArgs(cfg, args);
cfg.type = ConfigurationType::Executable;
2026-07-23 01:24:42 +02:00
cfg.dependencies = { CrafterBuildLib.get() };
{
std::array<fs::path, 0> interfaces = {};
std::array<fs::path, 1> implementations = { "implementations/main" };
cfg.GetInterfacesAndImplementations(interfaces, implementations);
}
musl host support: bootstrap and run on Alpine (x86_64-alpine-linux-musl) The Linux host code paths were gated on the x86_64_pc_linux_gnu target define alone, and LoadProject hardcoded --target=x86_64-pc-linux-gnu when compiling project.cpp and the module PCMs. Both break on musl hosts: the glibc release launcher cannot run there at all (no glibc loader; gcompat lacks libgcc_s and the __isoc23_* symbols), and a musl-built launcher would still compile project.cpp for the wrong libc. - The host gates test clang's __linux__ instead of one triple's define: they mean "Linux host", whatever the libc (or, later, the CPU). - LoadProject derives the host triple from HostTarget() (clang's -print-target-triple), which is also more correct on glibc distros whose triple isn't x86_64-pc-linux-gnu. - project.cpp / the cmake libc++ flags treat any *-linux-gnu or *-linux-musl target as Linux. - build.sh targets the host toolchain's triple (CRAFTER_BUILD_TARGET overrides) and derives the per-target define from it. On Arch this is byte-for-byte the previous behaviour. - CI: a release-musl job bootstraps on alpine:edge, runs the tests, and attaches crafter-build-linux-x86_64-musl-v2.tar.gz to the rolling latest release (via the API, so the glibc assets survive). Dynamic against musl libc++: the launcher dlopens project.so, so it cannot be fully static. First consumer: imsd's package CI, which cross-compiles for aarch64 from an Alpine container. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 23:49:00 +02:00
// Linux hosts, glibc or musl (Alpine): -ldl is a libc stub on musl, harmless.
const bool linuxTarget = cfg.target.ends_with("-linux-gnu") || cfg.target.ends_with("-linux-musl");
if (linuxTarget) {
V2: WASI, -r flag, CI pipeline, examples & tests cleanup WASI / wasm32 target support - Auto-detect /usr/share/wasi-sysroot on Linux when target starts_with("wasm32") - Skip -march/-mtune for wasm (clang rejects them) - Apply -fno-exceptions -fno-c++-static-destructors -mllvm -wasm-enable-sjlj -D_WASI_EMULATED_SIGNAL to wasm builds (compile + std PCM, kept in sync) - .wasm output extension in expectedOutputFor and link command - EnableWasiBrowserRuntime(cfg): opt-in helper that drops index.html + runtime.js next to the .wasm; runtime.js reads window.CRAFTER_WASM_URL set in the templated index.html so a single shim handles any output name -r run flag in the CLI: build then exec the artifact (host targets only; rejects libraries; auto .exe/.wasm extension handling) CI pipeline (.forgejo/workflows/ci.yaml) - Triggers: PR/push to master + manual dispatch - Single arch-latest container job: install deps, bootstrap, self-rebuild, run tests, cross-compile mingw, package both archives, upload artifacts - Rolling 'latest' release published only on push/dispatch to master mingw cross-compile from Linux now works end-to-end: - ExternalDependency cache key includes target so per-target glslang builds don't collide; CMAKE_BUILD_TYPE=Release pinned (otherwise glslang appends 'd' to lib names and breaks linking); cross-compile cmake flags (CMAKE_SYSTEM_NAME=Windows, CMAKE_*_COMPILER_TARGET=...) - project.cpp accepts --target=<triple>; Linux-only -Wl,--export-dynamic and -ldl are gated; mingw glslang skips the standalone exe (its libgcc_eh link pulls pthread which mingw doesn't link by default) - mingw compile uses -femulated-tls so std::__once_callable etc reference the same emutls symbols libstdc++ provides - mingw link auto-adds -lstdc++exp -lpthread GetCrafterBuildHome() exposed from the Platform module; LoadProject (Linux + Windows) now both use it instead of duplicating the resolution. Examples reorg: hello-world, library, with-module, wasi, tests — each with its own README. Tests reorg: per-test directory with inner/ fixture, no shared tests/fixtures/ tree. New Wasi test verifies .wasm magic bytes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-28 23:24:46 +02:00
cfg.linkFlags.push_back("-Wl,--export-dynamic");
cfg.linkFlags.push_back("-ldl");
}
2026-05-27 19:45:05 +02:00
// Self-tests link the local crafter-build library and exercise it in
// process. The harness (whichever crafter-build invokes `test`) compiles
// these against the *installed* share/crafter-build .cppm files, then
2026-07-23 01:24:42 +02:00
// links each test exe against CrafterBuildLib built from the local
2026-05-27 19:45:05 +02:00
// sources — so the code under test is whatever's in this checkout.
// Mirrors how downstream consumers link their own libraries into tests.
musl host support: bootstrap and run on Alpine (x86_64-alpine-linux-musl) The Linux host code paths were gated on the x86_64_pc_linux_gnu target define alone, and LoadProject hardcoded --target=x86_64-pc-linux-gnu when compiling project.cpp and the module PCMs. Both break on musl hosts: the glibc release launcher cannot run there at all (no glibc loader; gcompat lacks libgcc_s and the __isoc23_* symbols), and a musl-built launcher would still compile project.cpp for the wrong libc. - The host gates test clang's __linux__ instead of one triple's define: they mean "Linux host", whatever the libc (or, later, the CPU). - LoadProject derives the host triple from HostTarget() (clang's -print-target-triple), which is also more correct on glibc distros whose triple isn't x86_64-pc-linux-gnu. - project.cpp / the cmake libc++ flags treat any *-linux-gnu or *-linux-musl target as Linux. - build.sh targets the host toolchain's triple (CRAFTER_BUILD_TARGET overrides) and derives the per-target define from it. On Arch this is byte-for-byte the previous behaviour. - CI: a release-musl job bootstraps on alpine:edge, runs the tests, and attaches crafter-build-linux-x86_64-musl-v2.tar.gz to the rolling latest release (via the API, so the glibc assets survive). Dynamic against musl libc++: the launcher dlopens project.so, so it cannot be fully static. First consumer: imsd's package CI, which cross-compiles for aarch64 from an Alpine container. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 23:49:00 +02:00
if (linuxTarget) {
2026-07-23 01:24:42 +02:00
cfg.AddTest("HelloWorld").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("StaticLib").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("StaticLibSourceRemoved").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("LinkManyObjects").Dependencies({ CrafterBuildLib.get() });
2026-07-23 01:24:42 +02:00
cfg.AddTest("ModuleInterface").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("DependencyLink").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("SharedLibraryRuns").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("IncludeWalkOutputs").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("IncrementalInterfaceChange").Dependencies({ CrafterBuildLib.get() });
fix: track what a primary module interface imports A primary module interface unit — `export module Widget;`, no partitions — recorded nothing about what it imported. GetInterfacesAndImplementations registered the Module and then erased the file from the scan list, so the import pass only ever saw partitions, and Module had no vectors to hold an edge anyway. Two consequences, both reported as issue #26: Module::Check consulted only its own .cppm and its partitions. A data member added to an imported module left Widget.pcm, Widget.o and every consumer object untouched while the imported library rebuilt and both binaries relinked — one executable holding two class layouts, no diagnostic, and a crash somewhere unrelated. Wiping build/ was the only cure, so `crafter-build test` could not be trusted straight after an interface edit. Module::Compile waited on nothing. Two modules in one Configuration compile on concurrent threads, so a primary interface importing a sibling was a coin flip between working and "module 'Base' not found". Partitions never had either problem — they carry the same three vectors and Check/Compile honour them — which is why the gap only surfaced on a module whose interface is one flat unit. Module now carries moduleDependencies, externalModuleDependencies and pendingImports with the same meanings as on ModulePartition; primary units stay in the scan list so their imports land there; Check sees through them; Compile orders itself behind a local sibling; and ResolvePendingImports sweeps them so an edge survives dependencies being wired up afterwards. Build() now Checks every interface before spawning any compile thread — the `compiled` flag a waiter blocks on is raised either by a Compile that runs or by the Check that decides none is needed, so a Check still pending while another module's thread waits would have hung the build. Resolves #26 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 18:19:04 +00:00
cfg.AddTest("TransitiveInterfaceChange").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("IncrementalHeaderChange").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("IncrementalInterfaceObject").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("StdPcmRebuild").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("CompilerWarning").Dependencies({ CrafterBuildLib.get() });
fix: key the host PCM cache on source content, add clean, hash project args Three follow-ons to the stale-build report, all cases of an identity not capturing something that changes the output. The host PCM cache under <cache>/crafter.build/<target>-<march>/ is shared by every crafter-build on the machine, and freshness was a per-file mtime comparison. That cannot tell "this PCM is newer than my source" from "this PCM was built from different sources that happen to be newer", so a package install and a working checkout — or two checkouts of different versions — silently compiled their project.cpp against each other's declarations. Invalidation now keys on a stamp over the bytes of every module source, which also covers the case one file's mtime never could: the cached PCMs import each other, so a change to :Interface invalidates :Clang's PCM with Crafter.Build-Clang.cppm untouched. Project args ApplyStandardArgs does not itself interpret are now folded into VariantId. Such a flag typically decides what gets compiled or bundled — the report's example is --no-webgpu dropping entries from cfg.files — and without it both settings shared one bin dir and interleaved their outputs there, leaving a bundle matching neither. Sorted and deduplicated so flag order doesn't split the cache, and inherited by test Configurations. `crafter-build clean` removes the project's bin/ and build/ trees. It deliberately does not load project.cpp: cleaning is most often reached when something is already wrong, and a clean that first needs the project to compile is useless exactly then.
2026-07-30 17:43:09 +00:00
cfg.AddTest("CleanProject").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FormatCheckGlob").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
2026-07-23 01:24:42 +02:00
cfg.AddTest("ShaderCompile").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("ShaderVariantBuild").Dependencies({ CrafterBuildLib.get() });
fix: rebuild and relink on what changed, submodules at their revisions, and mingw found where it is - Shaders record the files glslang opened (a depfile) and their settings (source path, stage, entry point, defines, include directories) in the build directory, and rebuild when an included file or a setting changes, not only the shader's own source. - An executable relinks when its link command changed, not only when an object is newer: a link flag in project.cpp, or a dependency's library that moved (an ExternalDependency built into a new cache directory). The command is recorded beside the objects; its flags come from ordered sets, so the order the dependency threads finish in can't change it. - An external's newest artifact counts its libDirs and versioned .so names. - Submodules are checked out at the revisions the fetched commit records, from the URLs its .gitmodules gives, after every clone, switch, checkout and pull, so a pinned commit builds against its own submodules, and one moved by hand is put back; with no .gitmodules, git isn't asked. - Each external clone's fetch and build hold a file lock: parallel builds pulled into one clone at once ("cannot lock ref"). - mingw: - -stdlib=libstdc++ always; - the std module's source is found through libstdc++.modules.json in the mingw toolchain's own library directories (the generic lib/ holds the host's Linux one), asking the compiler once a run; - a toolchain that isn't there is a build error saying where it looked, not std::terminate; - CRAFTER_MINGW_DIR names the prefix, the directory holding x86_64-w64-mingw32/ and lib/gcc/; - inside the Flatpak the host's /usr mingw is used. - RunScript's exit-status check reads as the one range it is. - Tests: ConcurrentExternalFetch, ExternalArtifactTime, GitSubmodules, LinkFlagsChange, MingwMissing, ShaderIncludeChange; ShaderCompile and ToolchainResolve extended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 19:08:13 +02:00
cfg.AddTest("ShaderIncludeChange").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("CudaCompile").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("CudaMissing").Dependencies({ CrafterBuildLib.get() });
fix: rebuild and relink on what changed, submodules at their revisions, and mingw found where it is - Shaders record the files glslang opened (a depfile) and their settings (source path, stage, entry point, defines, include directories) in the build directory, and rebuild when an included file or a setting changes, not only the shader's own source. - An executable relinks when its link command changed, not only when an object is newer: a link flag in project.cpp, or a dependency's library that moved (an ExternalDependency built into a new cache directory). The command is recorded beside the objects; its flags come from ordered sets, so the order the dependency threads finish in can't change it. - An external's newest artifact counts its libDirs and versioned .so names. - Submodules are checked out at the revisions the fetched commit records, from the URLs its .gitmodules gives, after every clone, switch, checkout and pull, so a pinned commit builds against its own submodules, and one moved by hand is put back; with no .gitmodules, git isn't asked. - Each external clone's fetch and build hold a file lock: parallel builds pulled into one clone at once ("cannot lock ref"). - mingw: - -stdlib=libstdc++ always; - the std module's source is found through libstdc++.modules.json in the mingw toolchain's own library directories (the generic lib/ holds the host's Linux one), asking the compiler once a run; - a toolchain that isn't there is a build error saying where it looked, not std::terminate; - CRAFTER_MINGW_DIR names the prefix, the directory holding x86_64-w64-mingw32/ and lib/gcc/; - inside the Flatpak the host's /usr mingw is used. - RunScript's exit-status check reads as the one range it is. - Tests: ConcurrentExternalFetch, ExternalArtifactTime, GitSubmodules, LinkFlagsChange, MingwMissing, ShaderIncludeChange; ShaderCompile and ToolchainResolve extended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 19:08:13 +02:00
cfg.AddTest("MingwMissing").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("MingwSysroot").Dependencies({ CrafterBuildLib.get() });
fix: rebuild and relink on what changed, submodules at their revisions, and mingw found where it is - Shaders record the files glslang opened (a depfile) and their settings (source path, stage, entry point, defines, include directories) in the build directory, and rebuild when an included file or a setting changes, not only the shader's own source. - An executable relinks when its link command changed, not only when an object is newer: a link flag in project.cpp, or a dependency's library that moved (an ExternalDependency built into a new cache directory). The command is recorded beside the objects; its flags come from ordered sets, so the order the dependency threads finish in can't change it. - An external's newest artifact counts its libDirs and versioned .so names. - Submodules are checked out at the revisions the fetched commit records, from the URLs its .gitmodules gives, after every clone, switch, checkout and pull, so a pinned commit builds against its own submodules, and one moved by hand is put back; with no .gitmodules, git isn't asked. - Each external clone's fetch and build hold a file lock: parallel builds pulled into one clone at once ("cannot lock ref"). - mingw: - -stdlib=libstdc++ always; - the std module's source is found through libstdc++.modules.json in the mingw toolchain's own library directories (the generic lib/ holds the host's Linux one), asking the compiler once a run; - a toolchain that isn't there is a build error saying where it looked, not std::terminate; - CRAFTER_MINGW_DIR names the prefix, the directory holding x86_64-w64-mingw32/ and lib/gcc/; - inside the Flatpak the host's /usr mingw is used. - RunScript's exit-status check reads as the one range it is. - Tests: ConcurrentExternalFetch, ExternalArtifactTime, GitSubmodules, LinkFlagsChange, MingwMissing, ShaderIncludeChange; ShaderCompile and ToolchainResolve extended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 19:08:13 +02:00
cfg.AddTest("GitSubmodules").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("LinkFlagsChange").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("ExternalArtifactTime").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("ExternalReconfigure").Dependencies({ CrafterBuildLib.get() });
fix: rebuild and relink on what changed, submodules at their revisions, and mingw found where it is - Shaders record the files glslang opened (a depfile) and their settings (source path, stage, entry point, defines, include directories) in the build directory, and rebuild when an included file or a setting changes, not only the shader's own source. - An executable relinks when its link command changed, not only when an object is newer: a link flag in project.cpp, or a dependency's library that moved (an ExternalDependency built into a new cache directory). The command is recorded beside the objects; its flags come from ordered sets, so the order the dependency threads finish in can't change it. - An external's newest artifact counts its libDirs and versioned .so names. - Submodules are checked out at the revisions the fetched commit records, from the URLs its .gitmodules gives, after every clone, switch, checkout and pull, so a pinned commit builds against its own submodules, and one moved by hand is put back; with no .gitmodules, git isn't asked. - Each external clone's fetch and build hold a file lock: parallel builds pulled into one clone at once ("cannot lock ref"). - mingw: - -stdlib=libstdc++ always; - the std module's source is found through libstdc++.modules.json in the mingw toolchain's own library directories (the generic lib/ holds the host's Linux one), asking the compiler once a run; - a toolchain that isn't there is a build error saying where it looked, not std::terminate; - CRAFTER_MINGW_DIR names the prefix, the directory holding x86_64-w64-mingw32/ and lib/gcc/; - inside the Flatpak the host's /usr mingw is used. - RunScript's exit-status check reads as the one range it is. - Tests: ConcurrentExternalFetch, ExternalArtifactTime, GitSubmodules, LinkFlagsChange, MingwMissing, ShaderIncludeChange; ShaderCompile and ToolchainResolve extended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 19:08:13 +02:00
cfg.AddTest("ConcurrentExternalFetch").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("SharedExternalFetch").Dependencies({ CrafterBuildLib.get() });
2026-07-23 01:24:42 +02:00
cfg.AddTest("StandardArgs").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("TestRunnerSpec").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("VariantId").Dependencies({ CrafterBuildLib.get() });
feat(toolchain): resolve the compiler in one place Every clang++, clang and llvm-ar the tool spawned was a bare name on PATH, the std module source was /usr/share/libc++/v1/std.cppm, the WASI sysroot /usr/share/wasi-sysroot and the mingw headers /usr/x86_64-w64-mingw32, spelled out at eighteen call sites. A toolchain installed anywhere else, which is what the Flatpak ships under /app, had no way in. Crafter.Build:Toolchain resolves all of it once per process: CRAFTER_BUILD_LLVM_DIR, else a clang++ installed beside crafter-build (<prefix>/bin, found through the same walk GetCrafterBuildHome does), else PATH. What sits beside the compiler is used when present: its libclang.so, its clang-c headers, its std module source, its WASI sysroot. An explicit prefix without a clang++ is an error rather than a fallback, for the same reason CRAFTER_BUILD_LIBCLANG was already exclusive. CRAFTER_BUILD_LIBCXX_DIR points at a libc++ install other than the compiler's own, and CRAFTER_MINGW_DIR now does what its help line always claimed: it is passed as --sysroot for the mingw target. Binaries linked by a toolchain outside /usr get an rpath to its lib dir, since its libc++.so.1 is not on the loader's default path. HostTarget() is the resolved clang's -print-target-triple. A clang built without a vendor reports x86_64-unknown-linux-gnu where Arch's reports x86_64-pc-linux-gnu, so target equality that decides whether a test runs locally and which targets a bare `test` sweeps goes through SameTarget, which ignores the vendor field. The strings themselves are never rewritten: clang rejects a PCM whose triple differs from the importing unit's. The examples and README stop hardcoding the host triple; the default is already the host. `crafter-build --version` prints the version baked in at build time (CRAFTER_BUILD_VERSION, else `git describe`, else 0.0.0-dev), the compiler and the host triple, and is answered before any argument is forwarded to project.cpp. The version is a define on the library, so each version is its own library variant and relinks the executable and tests once per commit. build.sh gains a shebang and `set -eu`, honours CRAFTER_BUILD_LLVM_DIR and CRAFTER_BUILD_VERSION, skips the glslang clone when it is already there, and writes a fresh archive instead of appending to one that may hold members from an older layout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 22:26:31 +02:00
cfg.AddTest("ToolchainResolve").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("SysrootStdModule").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("SysrootCompileFlags").Dependencies({ CrafterBuildLib.get() });
feat(toolchain): resolve the compiler in one place Every clang++, clang and llvm-ar the tool spawned was a bare name on PATH, the std module source was /usr/share/libc++/v1/std.cppm, the WASI sysroot /usr/share/wasi-sysroot and the mingw headers /usr/x86_64-w64-mingw32, spelled out at eighteen call sites. A toolchain installed anywhere else, which is what the Flatpak ships under /app, had no way in. Crafter.Build:Toolchain resolves all of it once per process: CRAFTER_BUILD_LLVM_DIR, else a clang++ installed beside crafter-build (<prefix>/bin, found through the same walk GetCrafterBuildHome does), else PATH. What sits beside the compiler is used when present: its libclang.so, its clang-c headers, its std module source, its WASI sysroot. An explicit prefix without a clang++ is an error rather than a fallback, for the same reason CRAFTER_BUILD_LIBCLANG was already exclusive. CRAFTER_BUILD_LIBCXX_DIR points at a libc++ install other than the compiler's own, and CRAFTER_MINGW_DIR now does what its help line always claimed: it is passed as --sysroot for the mingw target. Binaries linked by a toolchain outside /usr get an rpath to its lib dir, since its libc++.so.1 is not on the loader's default path. HostTarget() is the resolved clang's -print-target-triple. A clang built without a vendor reports x86_64-unknown-linux-gnu where Arch's reports x86_64-pc-linux-gnu, so target equality that decides whether a test runs locally and which targets a bare `test` sweeps goes through SameTarget, which ignores the vendor field. The strings themselves are never rewritten: clang rejects a PCM whose triple differs from the importing unit's. The examples and README stop hardcoding the host triple; the default is already the host. `crafter-build --version` prints the version baked in at build time (CRAFTER_BUILD_VERSION, else `git describe`, else 0.0.0-dev), the compiler and the host triple, and is answered before any argument is forwarded to project.cpp. The version is a define on the library, so each version is its own library variant and relinks the executable and tests once per commit. build.sh gains a shebang and `set -eu`, honours CRAFTER_BUILD_LLVM_DIR and CRAFTER_BUILD_VERSION, skips the glslang clone when it is already there, and writes a fresh archive instead of appending to one that may hold members from an older layout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 22:26:31 +02:00
cfg.AddTest("VersionFlag").Dependencies({ CrafterBuildLib.get() });
2026-07-23 01:24:42 +02:00
cfg.AddTest("WasiBrowserRuntime").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("WasiBrowserRuntimeExit").Dependencies({ CrafterBuildLib.get() });
2026-07-23 01:24:42 +02:00
cfg.AddTest("WasmVariants").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("WasmHelloRuns").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("WasmTestRuns").Dependencies({ CrafterBuildLib.get() });
feat: lay an executable out as the files/ of a Flatpak A Linux executable built by the Flatpak crafter-build links the libc++, libc++abi and libunwind in its /app/lib and the Sdk's glibc, so it runs inside crafter-build's sandbox and practically nowhere else: a host needs glibc 2.38 or newer and all three LLVM libraries, which not even Arch has. A program built here is meant to run in a Flatpak, so it can now be laid out as one: with cfg.packaging = Packaging::Flatpak, or --packaging=flatpak where the project.cpp crafter-build was pointed at calls ApplyStandardArgs, its BinDir() holds files/, what becomes /app in the app's sandbox, and -r runs the program there against the libraries the app carries. The program is linked into files/bin, where its shaders, files and assets land too (ProgramDir()), with $ORIGIN/../lib as its one run path, and the new :Flatpak partition writes the rest of files/: files/lib with the LLVM runtime libraries, located one by one through clang, and whatever else the program needs, read with llvm-readelf, that the directories of the shared libraries it is built on hold, the ones an unpackaged link records as run paths, or the toolchain's own lib dir, /app/lib in crafter-build's Flatpak, which the link searches too; and the desktop entry, metainfo and icons under the app-id in files/share, the entry refused when its Icon= is not the app-id or desktop-file-validate, where there is one, rejects it, and an icon that is not an .svg or a square .png. The metadata and export/ of a build directory are flatpak build-finish's to write, and crafter-build keeps no copy of its rules: what a permission means and what the host sees of an app change with flatpak's releases, and a copy would have to follow every one. The writer copies a file only when its content differs, compared a block at a time so that a large file costs no more memory than a small one, and writes one only when what it would write differs, never deciding by an mtime, which ostree sets to 0 for every file of /app, and works the program's libraries out on every write, which reads only their dynamic sections, since a library replaced in place, as by a toolchain update, can need others, which FlatpakLibraryChange checks; it prunes from files/bin each top-level entry an earlier build put there and this one does not, reporting those the program wrote there itself. What cannot be a Flatpak is refused before anything is built, saying why: a Windows or wasm executable, a build against a sysroot or for musl, another architecture than the runtime's, a build against CRAFTER_BUILD_LIBCXX_DIR, whose libc++ the Flatpak would not carry, and a build by a native crafter-build, which links the host's glibc: a native process knows no Flatpak runtime, from /.flatpak-info, unless CRAFTER_BUILD_FLATPAK_INFO, the tests' hook, names a file with one. Default stays the executable as linked for now, RunTests runs every test as linked, whatever its Configuration asks for, and RunLint works out its compile command so, and a forwarded --packaging= leaves a dependency's executables alone, since consumers run them by path. A dependency that packages its own executable gets its desktop file, metainfo and icons rebased by the loader as its cfg.files are, so they are its own whatever directory the consumer builds from. Only a Flatpak is keyed into VariantId, so every other configuration keeps its directory, but for one given --packaging=, which was a project arg, hashed into VariantId, and is a standard arg now, a dependency's included. The app-id and what a Flatpak is installed as are not keyed: they change files/share, never what is compiled. The asset name map, kept three times, twice in Build() and once for the browser runtime's files.json, is one function now, CompressedAssetName; CompressAsset, in Crafter.Build-Asset.cpp, keeps the list of the extensions it loads, which has to agree with it. Each copy a Flatpak build makes into the program's directory, of its shaders, assets, cfg.files and what its dependencies forward, records the top-level name it places there, the names of what a directory holds for one copied into it itself ("data/", "data/."), and those are what the writer keeps in files/bin; a build that fails after copying adds them to the writer's record all the same, so the next write removes what no build places any more. SharedLibraryRuns now also packages its program as a Flatpak, whose files/lib has to carry libgreet.so for it to start.
2026-11-01 19:20:55 +01:00
cfg.AddTest("FlatpakOutput").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakToolchainLibrary").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakRefusals").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakDependencyExecutable").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("FlatpakLibcxxDir").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakTestsRaw").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakNative").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakIncremental").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakLibraryChange").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakDesktop").Dependencies({ CrafterBuildLib.get() });
feat: install a Flatpak's data under /app/share A program packaged as a Flatpak could only have its files beside it in files/bin, where cfg.files goes. One that finds its data at <its directory>/../share/<name>, as Crafter.Review finds its process/ directory, had no way to get it there: files/share belongs to the writer, which removes anything it did not put there, and a module of flatpak-builder's would have placed it only in the installed app, never under -r. cfg.flatpak.share lists files and directories of the project and the path under /app/share each goes to. The writer copies them into files/share with the desktop entry, metainfo and icons, keeps them while they are listed and removes them once they are not, as it does those. -r runs the program from files/bin, so the same ../share lookup finds them there. What is exported of them is flatpak build-finish's to decide, by its own rules, as for any app's files: the app's D-Bus services, MIME types, search providers and KRunner plugins, which have no field of their own, are placed like any other file. A library's are not passed on to the programs built on it, since data a library needs at run time already goes through cfg.files. A dependency that packages its own executable has the sources rebased by the loader, as its cfg.files are. Share entries change files/share and not what is compiled, so they are not keyed into VariantId, which its test checks. Every file bound for files/share, the desktop entry, metainfo and icons included, now goes through one placement check, which refuses two files for one path, a field's file among them, and a file where another needs a directory, naming both. A target that is absolute or leaves share/ is refused too. Any other place is open to a share entry, a second desktop entry, an add-on's metainfo and any icon included, as for any app's files: flatpak build-export refuses an exported icon that is not a square image and a D-Bus service that is not a key file, warns of the app's own desktop entry where desktop-file-validate rejects it or its Icon= is not the app's, and exports a second desktop entry, a MIME package or metainfo as it is. The app's own desktop entry, applications/<app-id>.desktop, is held to cfg.flatpak.desktopFile's checks whichever placed it: its Icon= and desktop-file-validate are keyed to that place now, not to the field. A source directory that holds what the build writes is refused as well, since it would be copied into itself, growing each time the app is built or exported: files/, and the app's directory, where install and bundle put another copy of files/ and the exported app, compared as written and where links lead, so that the project's own directory is refused where its bin/ is a link elsewhere too. So is one that lies in them, the build's own output, which the next build, install or bundle writes again. The loader leaves an empty source empty, as it does an empty desktop file. FlatpakShareLarge holds the writer to comparing an entry with its copy at constant memory, which the program's data, gigabytes of it in a game, needs on every build: it rewrites a files/ holding a 32 MiB entry, with nothing changed, in a child process whose address space may grow by 16 MiB, with a stand-in llvm-readelf, since the real one, which a write starts for the libraries, would not fit under that limit, and a change in the entry's last byte, in the short block a comparison reads last, is still copied.
2026-11-02 20:04:14 +01:00
cfg.AddTest("FlatpakShare").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakShareLarge").Dependencies({ CrafterBuildLib.get() });
feat: install and bundle a Flatpak through the host's flatpak An executable packaged as a Flatpak came out as the files/ of one, which only flatpak build-finish makes an app of, and getting it installed or onto another machine took flatpak commands on the host, typed by hand. Two verbs do it where the host's flatpak can be reached: `crafter-build install` builds the project and installs its app for this user, and `crafter-build bundle` builds it into bin/<variant>.flatpak, a single file for `flatpak install --user` that names Flathub's repository for the runtime. Inside crafter-build's Flatpak they need the org.freedesktop.Flatpak permission, which its manifest does not grant in this commit. Both put the app into the project's repo first, in build/flatpak-apps/<app-id>/ (FlatpakAppDir), one per app rather than per variant, since flatpak-builder's state there is its cache. Every variant exports into it, so the export and the install or bundle made from it hold a lock there, and another crafter-build exporting meanwhile waits rather than leave this one installing or bundling its program. The user remote an install re-points is every checkout's that builds the app-id, so re-pointing it and installing from it hold a second lock, which every crafter-build installing there takes, natively or in the Flatpak, whatever its XDG_CACHE_HOME: in ~/.cache/crafter.build/flatpak-remotes/, found by HOME, for the user's own installation, which flatpak hides from the sandbox behind a tmpfs of the sandbox's own, and in the directory of a private one, FLATPAK_USER_DIR, one lock for all of them where the sandbox shares that directory with the host. Without modules, the host's flatpak build-finish finishes build/flatpak-apps/<app-id>/build-dir, made afresh each time from a metadata naming the app, its runtime and the Sdk and a tree of hard links to the build's files/, copies where a link cannot be made, across filesystems or on one without links, vfat or exFAT: it writes the command, the sandbox's permissions and export/ by flatpak's own rules, those of whichever flatpak the host runs, and refuses a permission it does not know, and flatpak build-export puts the result into the repo. When cfg.flatpak.modules names flatpak-builder module files for what the app needs in /app besides the program, flatpak-builder does both, from a manifest that lists them and copies the built program in last, so nothing is compiled twice. That manifest keeps share/locale in the app ("separate-locales": false): flatpak-builder would split it into a .Locale extension by default, which a bundle, holding the app alone, leaves out. The loader rebases a dependency's module files as it does its cfg.files. install uses a user remote named after the app-id, re-pointed at the repo each time, and says how to remove both. The app's tree in build/flatpak-apps/<app-id>/build-dir, where flatpak-builder installs a module's files too, is left out of the include walk with every other build/, so the headers a module installed reach no compile. cfg.flatpak gets the runtime, the Platform or the Sdk at the branch crafter-build runs on, and the sandbox's permissions, finish-args as Flatpak spells them, which any configuration may declare: an executable gets its dependencies' first and its own last, so it can take one back. The build reads neither, and a change to either links nothing. install and bundle print the permissions, with where each came from, and hand them to build-finish, the one judge of what they mean, so a refusal can be traced to the configuration that declared it. FlatpakPermissions checks the order everywhere, and that a change to one neither moves the build to another directory nor links anything, and, where the host's flatpak runs, what build-finish makes of them and that it refuses a socket it does not have; FlatpakBundle that build-finish exports the desktop entry and the icon, and that the build's own files/ is left as it was; VariantId's test has the runtime, permissions and modules move no directory. The host's flatpak and flatpak-builder are reached only through HostCommand in :Platform, which builds the command lines of RunHostFlatpak, RunHostFlatpakBuilder and HostFlatpakUnavailable's probes: flatpak-spawn --host --watch-bus inside crafter-build's Flatpak, started in the host's / and passing FLATPAK_USER_DIR on, and the command itself natively. flatpak-spawn would otherwise start a command in crafter-build's own working directory, which the host need not have, and from /app, say, every host command would fail. HostFlatpakUnavailable says why the host cannot be reached: no org.freedesktop.Flatpak permission, no session bus (CI's build sandbox has neither), a host that does not see the project's bin/ and build/ where crafter-build does, as it does not in the sandbox's own /tmp, /var, /usr, /etc and /app or where a link leads into one, or no flatpak natively. That, and an executable that is not packaged as a Flatpak, install and bundle refuse as soon as the project is loaded, before anything is built; FlatpakVerbRefusal shows the second. The host is asked rather than the sandbox's paths modelled, which an override sharing a directory inside the sandbox's own would defeat: its flatpak is started in a directory just made in each of bin/ and build/ under a name no other has, which it enters only where it sees that very directory, and the directory is removed again. --help gets a section on both, and its Clean section says the repo an install points at goes with build/. FlatpakModules runs flatpak-builder only with a flatpak-builder program on the host, crafter-build falling back to the org.flatpak.Builder app, whose `flatpak run` would write ~/.var/app in the real home, and with the Platform and Sdk it builds the app with. The library's install function is InstallFlatpakApp because project.cpp files define an InstallFlatpak script of their own under `using namespace Crafter`, this repository's included, and a library InstallFlatpak would make the name an overload set, which the scripts table's std::function cannot be built from; BundleFlatpakApp is named to match. JsonQuote writes the manifest's strings, and variants.json's, which escaped quotes and backslashes only. FlatpakExport, FlatpakManifestText, ExportFlatpak and FlatpakPermission, which only :Clang uses, stay out of the API a project.cpp compiles against, as RecordFlatpakPlaced does, so their names cannot meet a project's own under `using namespace Crafter`; ExportFlatpak's comment names the app's lock, which its callers hold, beside HostFlatpakUnavailable.
2026-11-02 19:38:30 +01:00
cfg.AddTest("HostFlatpak").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakBundle").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakPermissions").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakInstall").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakModules").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("FlatpakVerbRefusal").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("WasmExceptions").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("WasiSysrootWithoutExceptions").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("WasmBuildRefusals").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("WasmSysrootKey").Dependencies({ CrafterBuildLib.get() });
2026-07-23 01:24:42 +02:00
cfg.AddTest("RunSingleTestExit").Dependencies({ CrafterBuildLib.get() });
test: several configurations from one project file BuildAll builds configurations the test makes itself, on a fresh copy of its fixture outside the checkout. A library, a program built on it and an unrelated program all come out built, each in the record of the pass under its PcmDir, and a list that names one configuration twice builds it from nothing, what the build before left of it being removed first, and leaves it in the record of the pass once. A library built on another library of its own name, path and type, so that the two are built into one directory, builds, with both archives in that directory; returned beside a program that is built on it, the pair is refused, both by name, before the program is built or anything is recorded. Two libraries that are each built on a configuration of the other's directory are refused by name, and nothing of them is built or recorded. A wasm32 library that names no sysroot and a program for the host built on it leave the library in the record once, under the directory it has after the pass, and its refusal comes back once; it is refused for its -fno-exceptions, so the case needs no WASI sysroot. Of two programs built on a library that does not compile and a third that has nothing to do with it, the third is built, the two are not, and the library's error comes back once. Two configurations that would be built into one directory are refused, and neither is built. With a wasm executable that declares a variant among them, a program of one source is linked no earlier than the program and library given before it; the wasm one is refused for its -fno-exceptions before it builds anything, so the case needs no WASI sysroot. ProjectConfigurations loads fixture project files staged outside the checkout. A file with CrafterBuildConfigurations comes back as the three configurations it returns, with the pointer the file took from the second to the first intact, and as two when its args say so; LoadProject refuses it. A file with CrafterBuildProject comes back as a list of one whose test still depends on that Configuration, and that test builds and passes. A file with both entry points, one with neither, and ones whose CrafterBuildConfigurations returns nothing, a null pointer or one configuration twice are refused, each with a message that says which. Then crafter-build's verbs, through Run() and RunTests, on the file of three: a build builds all three; -r refuses to pick between its two executables, and runs the one executable there is when the file returns two configurations; RunTests runs the tests of the first and the third configuration in one run, and when the first declares the third's test as well, that test fails for both, naming the two, and is not built, while the first's own test passes, and a list that names the first configuration twice runs its test once; with a fourth configuration of the third's name and path, a test run and a build are each refused for the two that would be built into one directory, and neither writes the AGENTS.md that a build which is not refused writes from the template the test puts beside the project file; `run` reaches a script of the first and of the third configuration and hands each the configuration that declares it; install refuses the project while none of the three is packaged, bundle refuses it when two are, and with one packaged executable beside the library bundle does not take the library for the app. SiblingConfigurations loads such a file as another project's sibling. A spec without `configuration` gets the first, a spec that names one gets that one, and the three specs share one load: the dependency of the second is the first as LocalProject returned it. All three are rebased onto the sibling's directory. A name the sibling does not have throws with the names it has, and a name that two configurations of another fixture share throws too, while a spec without a name still gets the first of those two. Building the second builds the first with it and leaves the third unbuilt. A file that returns something a sibling keeps to itself is refused when it is loaded, the configuration and the sibling named: the library the sibling's program is built on, the configuration of that program's test, and a helper only that test is built on, none of which the sibling's file returns. A project that returns the sibling's third configuration beside one of its own builds both, cannot run the sibling's script and runs its own, and its test run leaves the sibling's test alone. DependencyNotes gains a project of two configurations and a fixture, outer, that builds against lib: two Direct configurations give what each of them names; a project a Direct one names is followed when a Transitive one leads to it; a configuration under None keeps out what only it is built against; with both under None, AGENTS.md is the template's text; and a returned configuration of another project is one of the projects the notes come from, followed further only under Transitive, which is also what a file that made no configuration gets. For outer's own AGENTS.md, written from the Configuration LocalProject returned and outer's project file, outer's own setting selects: lib under Direct, lib and base under Transitive, nothing under None. Script runs a script of each of two configurations, each handed the configuration that declares it, refuses a name both declare without running anything, and, given a list that names one configuration twice, runs the script asked for, which a name declared twice would have kept it from. Lint formats the sources of two configurations in one run, counts a rule both register as one, and runs a rule only one of them registers over the sources of both. Of two returned configurations that register a rule under one name the earlier one's runs, over the sources of all three, though the configuration returned ahead of both depends on the later one.
2026-11-15 02:16:07 +01:00
// Loading a project file dlopens the project.so compiled from it,
// which references Crafter:: symbols (HostTarget, Configuration
// ctors) that have to be visible from the test exe — same wiring
// crafter-build itself uses for project.so.
2026-07-23 01:24:42 +02:00
cfg.AddTest("ConcurrentCacheRace").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
test: several configurations from one project file BuildAll builds configurations the test makes itself, on a fresh copy of its fixture outside the checkout. A library, a program built on it and an unrelated program all come out built, each in the record of the pass under its PcmDir, and a list that names one configuration twice builds it from nothing, what the build before left of it being removed first, and leaves it in the record of the pass once. A library built on another library of its own name, path and type, so that the two are built into one directory, builds, with both archives in that directory; returned beside a program that is built on it, the pair is refused, both by name, before the program is built or anything is recorded. Two libraries that are each built on a configuration of the other's directory are refused by name, and nothing of them is built or recorded. A wasm32 library that names no sysroot and a program for the host built on it leave the library in the record once, under the directory it has after the pass, and its refusal comes back once; it is refused for its -fno-exceptions, so the case needs no WASI sysroot. Of two programs built on a library that does not compile and a third that has nothing to do with it, the third is built, the two are not, and the library's error comes back once. Two configurations that would be built into one directory are refused, and neither is built. With a wasm executable that declares a variant among them, a program of one source is linked no earlier than the program and library given before it; the wasm one is refused for its -fno-exceptions before it builds anything, so the case needs no WASI sysroot. ProjectConfigurations loads fixture project files staged outside the checkout. A file with CrafterBuildConfigurations comes back as the three configurations it returns, with the pointer the file took from the second to the first intact, and as two when its args say so; LoadProject refuses it. A file with CrafterBuildProject comes back as a list of one whose test still depends on that Configuration, and that test builds and passes. A file with both entry points, one with neither, and ones whose CrafterBuildConfigurations returns nothing, a null pointer or one configuration twice are refused, each with a message that says which. Then crafter-build's verbs, through Run() and RunTests, on the file of three: a build builds all three; -r refuses to pick between its two executables, and runs the one executable there is when the file returns two configurations; RunTests runs the tests of the first and the third configuration in one run, and when the first declares the third's test as well, that test fails for both, naming the two, and is not built, while the first's own test passes, and a list that names the first configuration twice runs its test once; with a fourth configuration of the third's name and path, a test run and a build are each refused for the two that would be built into one directory, and neither writes the AGENTS.md that a build which is not refused writes from the template the test puts beside the project file; `run` reaches a script of the first and of the third configuration and hands each the configuration that declares it; install refuses the project while none of the three is packaged, bundle refuses it when two are, and with one packaged executable beside the library bundle does not take the library for the app. SiblingConfigurations loads such a file as another project's sibling. A spec without `configuration` gets the first, a spec that names one gets that one, and the three specs share one load: the dependency of the second is the first as LocalProject returned it. All three are rebased onto the sibling's directory. A name the sibling does not have throws with the names it has, and a name that two configurations of another fixture share throws too, while a spec without a name still gets the first of those two. Building the second builds the first with it and leaves the third unbuilt. A file that returns something a sibling keeps to itself is refused when it is loaded, the configuration and the sibling named: the library the sibling's program is built on, the configuration of that program's test, and a helper only that test is built on, none of which the sibling's file returns. A project that returns the sibling's third configuration beside one of its own builds both, cannot run the sibling's script and runs its own, and its test run leaves the sibling's test alone. DependencyNotes gains a project of two configurations and a fixture, outer, that builds against lib: two Direct configurations give what each of them names; a project a Direct one names is followed when a Transitive one leads to it; a configuration under None keeps out what only it is built against; with both under None, AGENTS.md is the template's text; and a returned configuration of another project is one of the projects the notes come from, followed further only under Transitive, which is also what a file that made no configuration gets. For outer's own AGENTS.md, written from the Configuration LocalProject returned and outer's project file, outer's own setting selects: lib under Direct, lib and base under Transitive, nothing under None. Script runs a script of each of two configurations, each handed the configuration that declares it, refuses a name both declare without running anything, and, given a list that names one configuration twice, runs the script asked for, which a name declared twice would have kept it from. Lint formats the sources of two configurations in one run, counts a rule both register as one, and runs a rule only one of them registers over the sources of both. Of two returned configurations that register a rule under one name the earlier one's runs, over the sources of all three, though the configuration returned ahead of both depends on the later one.
2026-11-15 02:16:07 +01:00
// Same wiring as ConcurrentCacheRace above.
fix: key the host PCM cache on source content, add clean, hash project args Three follow-ons to the stale-build report, all cases of an identity not capturing something that changes the output. The host PCM cache under <cache>/crafter.build/<target>-<march>/ is shared by every crafter-build on the machine, and freshness was a per-file mtime comparison. That cannot tell "this PCM is newer than my source" from "this PCM was built from different sources that happen to be newer", so a package install and a working checkout — or two checkouts of different versions — silently compiled their project.cpp against each other's declarations. Invalidation now keys on a stamp over the bytes of every module source, which also covers the case one file's mtime never could: the cached PCMs import each other, so a change to :Interface invalidates :Clang's PCM with Crafter.Build-Clang.cppm untouched. Project args ApplyStandardArgs does not itself interpret are now folded into VariantId. Such a flag typically decides what gets compiled or bundled — the report's example is --no-webgpu dropping entries from cfg.files — and without it both settings shared one bin dir and interleaved their outputs there, leaving a bundle matching neither. Sorted and deduplicated so flag order doesn't split the cache, and inherited by test Configurations. `crafter-build clean` removes the project's bin/ and build/ trees. It deliberately does not load project.cpp: cleaning is most often reached when something is already wrong, and a clean that first needs the project to compile is useless exactly then.
2026-07-30 17:43:09 +00:00
cfg.AddTest("HostCacheSourceStamp").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
fix: key PCM and project.so freshness on content, not installed mtimes std.pcm was rebuilt when it was older than std.cppm, and project.so when it was older than the crafter-build executable. Both inputs are installed files, and an OSTree deployment (the Flatpak) gives every installed file mtime 0: std.cppm and the executable always looked older than the cache, so a clang bump would never rebuild std.pcm and a crafter-build update would never recompile project.so. clang crashes on a PCM from another compiler instead of reporting it, so the failure would have been a backtrace on the user's first build after an update. Each artifact now has a one-line stamp beside it. std.pcm's covers the precompile command and the module source's bytes, which also catches a libc++ update under the same clang. project.so's covers the crafter-build version, the toolchain key, the module source stamp and the compile command; project.cpp's and the pre-dependency artifacts' mtimes remain inputs, since those live next to it with real timestamps. The module source stamp stands in for the executable: project.so resolves Crafter:: symbols from the running binary, so only declarations matter, and an implementation-only rebuild of crafter-build no longer recompiles it. The std.pcm stamp folds into the module cache stamp, so a rebuilt std.pcm rebuilds the PCMs that import it. The cache directory carries the toolchain key (<target>-<march>-<clang version>-<hash>), so a compiler bump starts cold instead of handing the new clang PCMs it will crash on. LoadProject and Build() now derive the directory from the same StdPcmDir. Old <target>-<march> directories are left behind; `clean` never touched the cache and still does not. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 22:32:35 +02:00
cfg.AddTest("HostCacheToolchainKey").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
feat: project.cpp declares its own dependencies with #pragma crafter dependency A project.cpp could only import std and Crafter.Build, so anything shared between build descriptions had to be a header every consumer copies. Now #pragma crafter dependency "<source>" [branch "<b>" | commit "<sha>"] [project "<file>"] names a sibling crafter-build project that project.cpp itself imports a module from. LoadProject scans for the directive, resolves it through GitProject (a URL) or LocalProject (a path relative to the project file), forces the result into host-tooling mode (the host triple LoadProject's own cache is keyed on, native march, no debug, -fPIC so the archive links into a shared object), builds it, and puts its BMIs and archive on the project.so command line. The dependency's own project.cpp goes through the same loader, so its directives resolve recursively; a cycle between project files is an error instead of unbounded recursion. The dependency is built on every load, fresh or not: clang crashes rather than erroring when it imports a BMI whose own imported PCM was rebuilt underneath it, and the module depfile — which Module::Check already reads — is what notices the host PCM cache was regenerated. Its artifact mtime is an input to project.so's staleness check, so editing the dependency recompiles project.cpp without touching it. The Linux link gains -fuse-ld=lld because release archives hold ThinLTO bitcode. ProjectDependency(name) hands the same Configuration* back from inside CrafterBuildProject, by configuration name or exported module name, so a test that links the module needn't spell the source twice. It reads a thread_local frame stack that an RAII guard keeps for the whole of LoadProject, which also provides the cycle check. ExpectedOutput() is the link gate's artifact-path lambda hoisted into the :Clang partition, so the staleness check and the -r runner share the one rule. Windows branches are wired identically but unverified. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 20:03:22 +02:00
cfg.AddTest("ProjectDependency").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("ProjectArgs").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("HostToolingSibling").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("PragmaSharedExternal").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("DuplicateModule").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("Script").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("DependencyNotes").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("SiblingOwnPointers").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
test: several configurations from one project file BuildAll builds configurations the test makes itself, on a fresh copy of its fixture outside the checkout. A library, a program built on it and an unrelated program all come out built, each in the record of the pass under its PcmDir, and a list that names one configuration twice builds it from nothing, what the build before left of it being removed first, and leaves it in the record of the pass once. A library built on another library of its own name, path and type, so that the two are built into one directory, builds, with both archives in that directory; returned beside a program that is built on it, the pair is refused, both by name, before the program is built or anything is recorded. Two libraries that are each built on a configuration of the other's directory are refused by name, and nothing of them is built or recorded. A wasm32 library that names no sysroot and a program for the host built on it leave the library in the record once, under the directory it has after the pass, and its refusal comes back once; it is refused for its -fno-exceptions, so the case needs no WASI sysroot. Of two programs built on a library that does not compile and a third that has nothing to do with it, the third is built, the two are not, and the library's error comes back once. Two configurations that would be built into one directory are refused, and neither is built. With a wasm executable that declares a variant among them, a program of one source is linked no earlier than the program and library given before it; the wasm one is refused for its -fno-exceptions before it builds anything, so the case needs no WASI sysroot. ProjectConfigurations loads fixture project files staged outside the checkout. A file with CrafterBuildConfigurations comes back as the three configurations it returns, with the pointer the file took from the second to the first intact, and as two when its args say so; LoadProject refuses it. A file with CrafterBuildProject comes back as a list of one whose test still depends on that Configuration, and that test builds and passes. A file with both entry points, one with neither, and ones whose CrafterBuildConfigurations returns nothing, a null pointer or one configuration twice are refused, each with a message that says which. Then crafter-build's verbs, through Run() and RunTests, on the file of three: a build builds all three; -r refuses to pick between its two executables, and runs the one executable there is when the file returns two configurations; RunTests runs the tests of the first and the third configuration in one run, and when the first declares the third's test as well, that test fails for both, naming the two, and is not built, while the first's own test passes, and a list that names the first configuration twice runs its test once; with a fourth configuration of the third's name and path, a test run and a build are each refused for the two that would be built into one directory, and neither writes the AGENTS.md that a build which is not refused writes from the template the test puts beside the project file; `run` reaches a script of the first and of the third configuration and hands each the configuration that declares it; install refuses the project while none of the three is packaged, bundle refuses it when two are, and with one packaged executable beside the library bundle does not take the library for the app. SiblingConfigurations loads such a file as another project's sibling. A spec without `configuration` gets the first, a spec that names one gets that one, and the three specs share one load: the dependency of the second is the first as LocalProject returned it. All three are rebased onto the sibling's directory. A name the sibling does not have throws with the names it has, and a name that two configurations of another fixture share throws too, while a spec without a name still gets the first of those two. Building the second builds the first with it and leaves the third unbuilt. A file that returns something a sibling keeps to itself is refused when it is loaded, the configuration and the sibling named: the library the sibling's program is built on, the configuration of that program's test, and a helper only that test is built on, none of which the sibling's file returns. A project that returns the sibling's third configuration beside one of its own builds both, cannot run the sibling's script and runs its own, and its test run leaves the sibling's test alone. DependencyNotes gains a project of two configurations and a fixture, outer, that builds against lib: two Direct configurations give what each of them names; a project a Direct one names is followed when a Transitive one leads to it; a configuration under None keeps out what only it is built against; with both under None, AGENTS.md is the template's text; and a returned configuration of another project is one of the projects the notes come from, followed further only under Transitive, which is also what a file that made no configuration gets. For outer's own AGENTS.md, written from the Configuration LocalProject returned and outer's project file, outer's own setting selects: lib under Direct, lib and base under Transitive, nothing under None. Script runs a script of each of two configurations, each handed the configuration that declares it, refuses a name both declare without running anything, and, given a list that names one configuration twice, runs the script asked for, which a name declared twice would have kept it from. Lint formats the sources of two configurations in one run, counts a rule both register as one, and runs a rule only one of them registers over the sources of both. Of two returned configurations that register a rule under one name the earlier one's runs, over the sources of all three, though the configuration returned ahead of both depends on the later one.
2026-11-15 02:16:07 +01:00
cfg.AddTest("ProjectConfigurations").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
cfg.AddTest("SiblingConfigurations").Dependencies({ CrafterBuildLib.get() })
.LinkFlag("-Wl,--export-dynamic").LinkFlag("-ldl");
2026-07-23 01:24:42 +02:00
cfg.AddTest("ConcurrentDependencyReset").Dependencies({ CrafterBuildLib.get() });
test(build): build many units at once and count the threads it takes JobLimit makes two projects and one more for every 32 hardware threads and builds them from nothing at once, each from a thread of its own, as RunTests builds its tests, while it counts the threads of its own process. A project is 69 sources: 64 that import nothing, half C and half C++, then a module of two partitions, one importing the other, with its implementation unit, and a main.cpp that imports the module. It is the same size on every machine, so that no command of its build grows with the machine. The builds together may add as many threads as the machine has hardware threads, and have to add at least two where there are two; every program is then run and has to print 995: what its 64 C and C++ functions return and the module's Top(), which is built on the two partitions' functions. On 5b75df3 it fails: on a machine with 56 hardware threads, "3 builds of 207 sources in all ran on 205 threads at once". The count sees the steps that are jobs. A link is none: its Build() runs it through RunBuildCommand from a thread that was there before the count, which does not tell whether the link waited for a worker. JobGroup drives pools of its own, of one to four workers. Twelve jobs on three workers run three at once and no more; a job starts after the ones it was added after, in a graph of four jobs and in one of 300; the first error keeps a job that comes after it and the jobs added later from starting, and so does Fail(); what a job throws is its error; a chain gets through one worker; Run() runs its work on a worker, on the calling thread when that is one, where a JobGroup is refused; and leaving a group's scope waits for the job that runs and starts no other. It also holds the process's pool to a worker per hardware thread.
2026-11-13 17:59:55 +01:00
cfg.AddTest("JobGroup").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("JobLimit").Dependencies({ CrafterBuildLib.get() });
cfg.AddTest("ImportCycle").Dependencies({ CrafterBuildLib.get() });
test: several configurations from one project file BuildAll builds configurations the test makes itself, on a fresh copy of its fixture outside the checkout. A library, a program built on it and an unrelated program all come out built, each in the record of the pass under its PcmDir, and a list that names one configuration twice builds it from nothing, what the build before left of it being removed first, and leaves it in the record of the pass once. A library built on another library of its own name, path and type, so that the two are built into one directory, builds, with both archives in that directory; returned beside a program that is built on it, the pair is refused, both by name, before the program is built or anything is recorded. Two libraries that are each built on a configuration of the other's directory are refused by name, and nothing of them is built or recorded. A wasm32 library that names no sysroot and a program for the host built on it leave the library in the record once, under the directory it has after the pass, and its refusal comes back once; it is refused for its -fno-exceptions, so the case needs no WASI sysroot. Of two programs built on a library that does not compile and a third that has nothing to do with it, the third is built, the two are not, and the library's error comes back once. Two configurations that would be built into one directory are refused, and neither is built. With a wasm executable that declares a variant among them, a program of one source is linked no earlier than the program and library given before it; the wasm one is refused for its -fno-exceptions before it builds anything, so the case needs no WASI sysroot. ProjectConfigurations loads fixture project files staged outside the checkout. A file with CrafterBuildConfigurations comes back as the three configurations it returns, with the pointer the file took from the second to the first intact, and as two when its args say so; LoadProject refuses it. A file with CrafterBuildProject comes back as a list of one whose test still depends on that Configuration, and that test builds and passes. A file with both entry points, one with neither, and ones whose CrafterBuildConfigurations returns nothing, a null pointer or one configuration twice are refused, each with a message that says which. Then crafter-build's verbs, through Run() and RunTests, on the file of three: a build builds all three; -r refuses to pick between its two executables, and runs the one executable there is when the file returns two configurations; RunTests runs the tests of the first and the third configuration in one run, and when the first declares the third's test as well, that test fails for both, naming the two, and is not built, while the first's own test passes, and a list that names the first configuration twice runs its test once; with a fourth configuration of the third's name and path, a test run and a build are each refused for the two that would be built into one directory, and neither writes the AGENTS.md that a build which is not refused writes from the template the test puts beside the project file; `run` reaches a script of the first and of the third configuration and hands each the configuration that declares it; install refuses the project while none of the three is packaged, bundle refuses it when two are, and with one packaged executable beside the library bundle does not take the library for the app. SiblingConfigurations loads such a file as another project's sibling. A spec without `configuration` gets the first, a spec that names one gets that one, and the three specs share one load: the dependency of the second is the first as LocalProject returned it. All three are rebased onto the sibling's directory. A name the sibling does not have throws with the names it has, and a name that two configurations of another fixture share throws too, while a spec without a name still gets the first of those two. Building the second builds the first with it and leaves the third unbuilt. A file that returns something a sibling keeps to itself is refused when it is loaded, the configuration and the sibling named: the library the sibling's program is built on, the configuration of that program's test, and a helper only that test is built on, none of which the sibling's file returns. A project that returns the sibling's third configuration beside one of its own builds both, cannot run the sibling's script and runs its own, and its test run leaves the sibling's test alone. DependencyNotes gains a project of two configurations and a fixture, outer, that builds against lib: two Direct configurations give what each of them names; a project a Direct one names is followed when a Transitive one leads to it; a configuration under None keeps out what only it is built against; with both under None, AGENTS.md is the template's text; and a returned configuration of another project is one of the projects the notes come from, followed further only under Transitive, which is also what a file that made no configuration gets. For outer's own AGENTS.md, written from the Configuration LocalProject returned and outer's project file, outer's own setting selects: lib under Direct, lib and base under Transitive, nothing under None. Script runs a script of each of two configurations, each handed the configuration that declares it, refuses a name both declare without running anything, and, given a list that names one configuration twice, runs the script asked for, which a name declared twice would have kept it from. Lint formats the sources of two configurations in one run, counts a rule both register as one, and runs a rule only one of them registers over the sources of both. Of two returned configurations that register a rule under one name the earlier one's runs, over the sources of all three, though the configuration returned ahead of both depends on the later one.
2026-11-15 02:16:07 +01:00
cfg.AddTest("BuildAll").Dependencies({ CrafterBuildLib.get() });
2026-07-23 01:24:42 +02:00
cfg.AddTest("Lint").Dependencies({ CrafterBuildLib.get() });
2026-05-27 19:45:05 +02:00
}
// Dogfood: the lite house rules, imported from their own repo through
// the pragma above. Lite is the house rules without the ones that only
// decide layout, whitespace and naming, which this tree keeps by hand:
// the full set's naming rule, for one, wants camelCase where this tree
// spells its statics and constants PascalCase. Report rules gate
// `crafter-build lint`; the two transforms also auto-fix under
// `crafter-build format`.
LintRules::AddLiteRules(cfg);
2026-07-23 01:24:42 +02:00
feat(packaging): `run flatpak` and `run install` for a local Flatpak The local Flatpak build was one long flatpak-builder line in AGENTS.md, with its state wherever the caller happened to stand, and installing the result was not written down anywhere. It is not a rare chore: the development box compiles with the distro's clang and the Flatpak with its bundled LLVM, a major version apart at the moment, so anything toolchain-sensitive has to be tried in the Flatpak too. Both are now scripts in project.cpp, the first users of cfg.scripts. `run flatpak` builds the manifest as it is, from the working tree, and ends with `crafter-build --version` from inside the result. Its state is build/flatpak/ (state/, repo/, build-dir/). That is a fixed name and not a BuildDir() on purpose: the Flatpak is compiled by the toolchain in the sandbox, so it does not depend on the host variant, and a variant-keyed directory would strand the LLVM cache on every host compiler update. The manifest already skips build/ when it copies the sources. flatpak-builder keys its cache on the manifest's path, so the manifest is never rewritten into a copy the way CI stamps the version in, and a local build reports 0.0.0-dev. The only argument accepted is --jobs=<N>: anything that ends the run without a build would leave the smoke test checking the previous one. `run install` installs the last export as branch `local` from a user remote of its own and makes it current, leaving the published branch installed. It does not build first: flatpak-builder never caches a `type: dir` module, so every build reruns build.sh and the suite. remote-add --if-not-exists is followed by remote-modify --url, because the remote may exist and point at another checkout. Both refuse to run from the Flatpak build of crafter-build, which has no flatpak to drive. The smoke test goes through `flatpak build` and not `<builder> --run`, which is what CI uses. flatpak-builder 1.4.9 run as the org.flatpak.Builder app exits 1 when the command it ran succeeded and 0 when it failed (`true` gives 1, `exit 3` gives 0), so the script reported a good build as a failure. Measured on the 56-core box with LLVM and the WASI sysroot cached: 260 seconds, the crafter-build module only, 29 tests passing in the sandbox. A second `run install` after a rebuild moved the installed commit. `clean` now also drops that state, about 2 GB and a cold LLVM build. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 18:29:32 +02:00
// See the top of this file.
cfg.scripts.push_back({"flatpak", BuildFlatpak});
cfg.scripts.push_back({"install", InstallFlatpak});
2026-04-27 07:04:42 +02:00
return cfg;
}