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
|
|
|
|
|
|
|
|
|
|
module Crafter.Build:External_impl;
|
|
|
|
|
|
import std;
|
|
|
|
|
|
import :External;
|
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
|
|
|
|
import :Toolchain;
|
2026-04-27 07:04:42 +02:00
|
|
|
|
import :Platform;
|
2026-04-30 02:20:19 +02:00
|
|
|
|
import :Progress;
|
|
|
|
|
|
import :Clang;
|
2026-04-27 07:04:42 +02:00
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
using namespace Crafter;
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
std::string DeriveName(const GitSource& source) {
|
|
|
|
|
|
std::string url = source.url;
|
|
|
|
|
|
while (!url.empty() && (url.back() == '/' || url.back() == '\\')) url.pop_back();
|
|
|
|
|
|
if (url.ends_with(".git")) url.resize(url.size() - 4);
|
|
|
|
|
|
auto slash = url.find_last_of("/\\");
|
|
|
|
|
|
return slash == std::string::npos ? url : url.substr(slash + 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string JoinOptions(std::span<const std::string> options) {
|
|
|
|
|
|
std::string out;
|
|
|
|
|
|
for (const std::string& opt : options) {
|
|
|
|
|
|
if (!out.empty()) out += ' ';
|
|
|
|
|
|
out += ShellQuote(opt);
|
|
|
|
|
|
}
|
|
|
|
|
|
return out;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string FetchGit(const GitSource& source, const fs::path& cloneDir) {
|
|
|
|
|
|
auto runGit = [](std::string_view cmd) -> std::optional<std::string> {
|
|
|
|
|
|
CommandResult r = RunCommandChecked(cmd);
|
|
|
|
|
|
if (r.exitCode != 0) return std::format("`{}` failed (exit {}): {}", cmd, r.exitCode, r.output);
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
};
|
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
|
|
|
|
// Submodules follow the checkout only when asked to: after every clone,
|
|
|
|
|
|
// switch, checkout or pull, so they match the revision that was fetched
|
|
|
|
|
|
// instead of whichever one was checked out before, from the URLs that
|
|
|
|
|
|
// revision's .gitmodules gives (sync). A no-op, and offline, when they
|
|
|
|
|
|
// already match, which puts back submodules moved by hand; and no git at
|
|
|
|
|
|
// all without any.
|
|
|
|
|
|
auto updateSubmodules = [&runGit](const fs::path& dir) -> std::optional<std::string> {
|
|
|
|
|
|
if (!fs::exists(dir / ".gitmodules")) return std::nullopt;
|
|
|
|
|
|
const std::string quoted = ShellQuote(dir.string());
|
|
|
|
|
|
if (auto err = runGit(std::format("git -C {} submodule sync --recursive", quoted))) return err;
|
|
|
|
|
|
return runGit(std::format("git -C {} submodule update --init --recursive", quoted));
|
|
|
|
|
|
};
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
|
|
|
|
|
if (fs::exists(cloneDir)) {
|
|
|
|
|
|
CommandResult remote = RunCommandChecked(std::format("git -C {} remote get-url origin", ShellQuote(cloneDir.string())));
|
|
|
|
|
|
std::string currentUrl = remote.output;
|
|
|
|
|
|
while (!currentUrl.empty() && (currentUrl.back() == '\n' || currentUrl.back() == '\r')) currentUrl.pop_back();
|
|
|
|
|
|
if (remote.exitCode != 0 || currentUrl != source.url) {
|
|
|
|
|
|
fs::remove_all(cloneDir);
|
|
|
|
|
|
} else if (!source.commit.empty()) {
|
|
|
|
|
|
CommandResult head = RunCommandChecked(std::format("git -C {} rev-parse HEAD", ShellQuote(cloneDir.string())));
|
|
|
|
|
|
std::string currentHead = head.output;
|
|
|
|
|
|
while (!currentHead.empty() && (currentHead.back() == '\n' || currentHead.back() == '\r')) currentHead.pop_back();
|
|
|
|
|
|
if (head.exitCode == 0 && currentHead != source.commit) {
|
|
|
|
|
|
if (auto err = runGit(std::format("git -C {} fetch origin", ShellQuote(cloneDir.string())))) return *err;
|
|
|
|
|
|
if (auto err = runGit(std::format("git -C {} checkout {}", ShellQuote(cloneDir.string()), ShellQuote(source.commit)))) return *err;
|
|
|
|
|
|
}
|
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
|
|
|
|
// Also when the commit already matched: a clone made before
|
|
|
|
|
|
// submodules were updated has them at the default branch's.
|
|
|
|
|
|
if (auto err = updateSubmodules(cloneDir)) return *err;
|
2026-04-27 07:04:42 +02:00
|
|
|
|
return "";
|
|
|
|
|
|
} else {
|
2026-04-30 02:20:19 +02:00
|
|
|
|
// No commit pinned — pull latest. The user opted into "track latest"
|
|
|
|
|
|
// by not pinning; the cost is one network round-trip per build.
|
|
|
|
|
|
// Pin source.commit to a SHA for reproducible, offline-capable builds.
|
|
|
|
|
|
if (!source.branch.empty()) {
|
|
|
|
|
|
if (auto err = runGit(std::format("git -C {} pull origin {}", ShellQuote(cloneDir.string()), ShellQuote(source.branch)))) return *err;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (auto err = runGit(std::format("git -C {} pull", ShellQuote(cloneDir.string())))) return *err;
|
|
|
|
|
|
}
|
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
|
|
|
|
if (auto err = updateSubmodules(cloneDir)) return *err;
|
2026-04-27 07:04:42 +02:00
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-27 01:55:29 +00:00
|
|
|
|
// Random per-invocation tmp suffix so concurrent crafter-build processes
|
|
|
|
|
|
// resolving to the same cache key don't share an in-flight `.tmp`
|
|
|
|
|
|
// directory — git's pack tempfiles would get yanked when one process
|
|
|
|
|
|
// removes or renames the dir out from under the other.
|
|
|
|
|
|
std::random_device rd;
|
2026-04-27 07:04:42 +02:00
|
|
|
|
fs::path tmpDir = cloneDir;
|
2026-05-27 01:55:29 +00:00
|
|
|
|
tmpDir += std::format(".tmp.{:08x}{:08x}", rd(), rd());
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
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
|
|
|
|
// Not --recursive: that checks out the default branch's submodules, and
|
|
|
|
|
|
// the requested revision's come once it is checked out.
|
|
|
|
|
|
if (auto err = runGit(std::format("git clone {} {}", ShellQuote(source.url), ShellQuote(tmpDir.string())))) {
|
2026-04-27 07:04:42 +02:00
|
|
|
|
if (fs::exists(tmpDir)) fs::remove_all(tmpDir);
|
|
|
|
|
|
return *err;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!source.branch.empty()) {
|
|
|
|
|
|
if (auto err = runGit(std::format("git -C {} switch {}", ShellQuote(tmpDir.string()), ShellQuote(source.branch)))) {
|
|
|
|
|
|
fs::remove_all(tmpDir);
|
|
|
|
|
|
return *err;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!source.commit.empty()) {
|
|
|
|
|
|
if (auto err = runGit(std::format("git -C {} checkout {}", ShellQuote(tmpDir.string()), ShellQuote(source.commit)))) {
|
|
|
|
|
|
fs::remove_all(tmpDir);
|
|
|
|
|
|
return *err;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
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
|
|
|
|
if (auto err = updateSubmodules(tmpDir)) {
|
|
|
|
|
|
fs::remove_all(tmpDir);
|
|
|
|
|
|
return *err;
|
|
|
|
|
|
}
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
|
fs::rename(tmpDir, cloneDir, ec);
|
|
|
|
|
|
if (ec) {
|
|
|
|
|
|
fs::remove_all(tmpDir);
|
2026-05-27 01:55:29 +00:00
|
|
|
|
// If a concurrent build won the race, cloneDir now exists with the
|
|
|
|
|
|
// same source revision (cache key includes url+branch+commit), so
|
|
|
|
|
|
// discard our clone and reuse theirs.
|
|
|
|
|
|
if (fs::exists(cloneDir)) return "";
|
2026-04-27 07:04:42 +02:00
|
|
|
|
return std::format("rename {} -> {} failed: {}", tmpDir.string(), cloneDir.string(), ec.message());
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
std::string BuildInjectedCMakeFlags(const fs::path& cmakeBuildDir, std::string_view target) {
|
2026-04-27 07:04:42 +02:00
|
|
|
|
std::string out;
|
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
|
|
|
|
// Without an explicit build type, some packages (glslang) append a 'd'
|
|
|
|
|
|
// suffix to library names assuming a debug build, breaking -l<name>
|
|
|
|
|
|
// linking. Pin to Release.
|
|
|
|
|
|
out += " -DCMAKE_BUILD_TYPE=Release";
|
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
|
|
|
|
const Toolchain& tc = GetToolchain();
|
|
|
|
|
|
out += std::format(" -DCMAKE_C_COMPILER={}", ShellQuote(tc.clang.string()));
|
|
|
|
|
|
out += std::format(" -DCMAKE_CXX_COMPILER={}", ShellQuote(tc.clangxx.string()));
|
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
|
|
|
|
// Stdlib choice: libc++ for Linux targets (matches how crafter-build
|
|
|
|
|
|
// itself is built with -stdlib=libc++); the mingw cross-compile uses the
|
|
|
|
|
|
// libstdc++ shipped by the mingw-w64 toolchain, so it keeps the default.
|
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 (target.ends_with("-linux-gnu") || target.ends_with("-linux-musl")) {
|
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
|
|
|
|
out += std::format(" -DCMAKE_CXX_FLAGS={}", ShellQuote(std::format("-stdlib=libc++{}", tc.LibcxxCompileFlags())));
|
|
|
|
|
|
out += std::format(" -DCMAKE_EXE_LINKER_FLAGS={}", ShellQuote(std::format("-stdlib=libc++{}", tc.LibcxxLinkFlags())));
|
|
|
|
|
|
out += std::format(" -DCMAKE_SHARED_LINKER_FLAGS={}", ShellQuote(std::format("-stdlib=libc++{}", tc.LibcxxLinkFlags())));
|
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
|
|
|
|
}
|
|
|
|
|
|
if (target == "x86_64-w64-mingw32") {
|
|
|
|
|
|
out += " -DCMAKE_SYSTEM_NAME=Windows";
|
|
|
|
|
|
out += std::format(" -DCMAKE_C_COMPILER_TARGET={}", target);
|
|
|
|
|
|
out += std::format(" -DCMAKE_CXX_COMPILER_TARGET={}", target);
|
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
|
|
|
|
// The libstdc++ and the mingw-w64 install the project's own compiles
|
|
|
|
|
|
// use (GetBaseCommand).
|
|
|
|
|
|
out += " -DCMAKE_CXX_FLAGS=-stdlib=libstdc++";
|
fix: give the mingw target a sysroot that holds mingw-w64 alone
Inside the Flatpak the mingw-w64 prefix is the host's /usr, and it was
clang's --sysroot as is. clang's mingw driver takes a sysroot for a tree
that holds mingw-w64 alone, and adds its include/ to the include path
and its lib/ to the library path. For /usr those are the Linux system's
own: every header mingw-w64 lacks came from glibc, and libstdc++'s
<ext/atomicity.h>, finding <sys/single_threaded.h>, had shared_ptr read
__libc_single_threaded, which nothing on Windows defines. Every program
that used one failed to link, among them every Crafter.Graphics Win32
executable, through Crafter.Asset's GLB loader. CRAFTER_MINGW_DIR=/usr
did the same outside the Flatpak (#43).
The sysroot is now MingwSysroot(): a directory in the cache, one per
prefix, holding only links to the prefix's x86_64-w64-mingw32/, lib/gcc/
and lib64/gcc/ (where openSUSE keeps gcc). Through it clang finds
mingw-w64, gcc's version and libstdc++ exactly as it does through the
mingw gcc on PATH, and nothing else. It is made by the first mingw
compile, link or CMake configure of a process, so no other command
writes to the cache for it and a failure to make it is that build's
error. The Toolchain field is now mingwPrefix, since clang never gets
the prefix itself, and it is made absolute when the toolchain is
resolved, as it ends up in link targets and directory names. Messages
keep naming paths under the prefix rather than under the view.
The prefix is also part of the mingw target's VariantId and of its std
PCM directory. Units do not track the std PCM they import: when the
fixed release built in a directory a broken build had left, the std
module was rebuilt and the objects compiled against glibc's headers
were only relinked, failing as before. As with a compiler update, a new
directory is what gets them rebuilt. It also keeps two releases that
share a cache, as the Flatpak's branches do, from rebuilding one std PCM
under each other's PCMs, and two prefixes apart. Without a prefix both
stay as they were: clang's own discovery has not changed.
Two shorter ways do not work: --sysroot=<prefix>/x86_64-w64-mingw32
loses the directory gcc's version names, so <string> is not found, and
clang ignores --gcc-toolchain and --gcc-install-dir for this target.
Fixes #43
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 20:48:06 +01:00
|
|
|
|
if (const fs::path& sysroot = MingwSysroot(); !sysroot.empty()) out += std::format(" -DCMAKE_SYSROOT={}", ShellQuote(sysroot.string()));
|
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
|
|
|
|
}
|
2026-04-27 07:04:42 +02:00
|
|
|
|
fs::path absBuildDir = fs::absolute(cmakeBuildDir);
|
|
|
|
|
|
out += std::format(" -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY={}", ShellQuote(absBuildDir.string()));
|
|
|
|
|
|
out += std::format(" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}", ShellQuote(absBuildDir.string()));
|
|
|
|
|
|
return out;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
std::string ConfigureCMake(const fs::path& cloneDir, const fs::path& cmakeBuildDir, std::span<const std::string> options, std::string_view target) {
|
2026-04-27 07:04:42 +02:00
|
|
|
|
fs::path optionsFile = cmakeBuildDir / ".crafter-options";
|
|
|
|
|
|
std::string optionsKey = JoinOptions(options);
|
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
|
|
|
|
// The injected flags are inputs too: a different compiler or libc++
|
|
|
|
|
|
// must reconfigure rather than reuse a CMakeCache made with the old one.
|
|
|
|
|
|
const std::string injected = BuildInjectedCMakeFlags(cmakeBuildDir, target);
|
|
|
|
|
|
const std::string configureKey = injected + '\n' + optionsKey;
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
|
|
|
|
|
bool needsConfigure = !fs::exists(cmakeBuildDir / "CMakeCache.txt");
|
|
|
|
|
|
if (!needsConfigure) {
|
|
|
|
|
|
std::ifstream existing(optionsFile);
|
|
|
|
|
|
if (!existing) {
|
|
|
|
|
|
needsConfigure = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
std::stringstream buf;
|
|
|
|
|
|
buf << existing.rdbuf();
|
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
|
|
|
|
if (buf.str() != configureKey) needsConfigure = true;
|
2026-04-27 07:04:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!needsConfigure) return "";
|
|
|
|
|
|
|
fix(external): start a CMake build over when its configure inputs change
ConfigureCMake records the flags it injects (compiler, libc++, and for
the mingw target CMAKE_SYSROOT) and reconfigures when they differ, but
it did so in place. CMake then keeps what the old flags compiled: the
Makefiles generator writes --sysroot into build.make, which make does
not compare, so nothing was recompiled, and the check results the old
configure cached stay too. A mingw external built by a release that gave
clang the host's /usr as the sysroot kept its objects reading
__libc_single_threaded after the fix for #43, and only deleting
<cache>/external/<name>-<hash>/build by hand got rid of them.
A build directory with a CMakeCache.txt whose recorded inputs differ is
now removed before the configure. It keeps its name, since projects
point include directories at headers generated in it. The two
crafter-builds the Flatpak's branches are, sharing one cache, rebuild
such an external from nothing each time they take turns, where they
used to reuse each other's objects.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:59:22 +01:00
|
|
|
|
// A build directory configured with other inputs starts over instead of
|
|
|
|
|
|
// being reconfigured. CMake reconfigures in place without recompiling
|
|
|
|
|
|
// what an old compiler or --sysroot compiled (the Makefiles generator
|
|
|
|
|
|
// writes --sysroot into build.make, which make does not compare) and
|
|
|
|
|
|
// keeps the check results the old configure cached. A mingw external
|
|
|
|
|
|
// built against the host's /usr as the sysroot (issue #43) kept its
|
|
|
|
|
|
// objects reading __libc_single_threaded after the fix that way. The
|
|
|
|
|
|
// directory keeps its name, which projects point generated headers at.
|
|
|
|
|
|
if (fs::exists(cmakeBuildDir / "CMakeCache.txt")) {
|
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
|
fs::remove_all(cmakeBuildDir, ec);
|
|
|
|
|
|
if (ec) return std::format("cannot clear {} for a fresh configure: {}", cmakeBuildDir.string(), ec.message());
|
|
|
|
|
|
}
|
2026-04-27 07:04:42 +02:00
|
|
|
|
if (!fs::exists(cmakeBuildDir)) fs::create_directories(cmakeBuildDir);
|
|
|
|
|
|
|
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 cmd = std::format("cmake -S {} -B {}{}", ShellQuote(fs::absolute(cloneDir).string()), ShellQuote(fs::absolute(cmakeBuildDir).string()), injected);
|
2026-04-27 07:04:42 +02:00
|
|
|
|
if (!options.empty()) {
|
|
|
|
|
|
cmd += " ";
|
|
|
|
|
|
cmd += optionsKey;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CommandResult r = RunCommandChecked(cmd);
|
|
|
|
|
|
if (r.exitCode != 0) {
|
|
|
|
|
|
return std::format("cmake configure failed (exit {}): {}", r.exitCode, r.output);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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::ofstream(optionsFile) << configureKey;
|
2026-04-27 07:04:42 +02:00
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string BuildCMake(const fs::path& cmakeBuildDir) {
|
2026-06-01 20:38:00 +00:00
|
|
|
|
// Without --parallel, the Unix Makefiles generator builds one translation
|
|
|
|
|
|
// unit at a time, leaving every core but one idle. Pass an explicit job
|
|
|
|
|
|
// count (a bare --parallel maps to an unbounded `make -j` fork bomb on the
|
|
|
|
|
|
// Makefiles generator) so deps like DPP/msquic/glslang compile ~N× faster.
|
2026-07-23 01:24:42 +02:00
|
|
|
|
std::uint32_t jobs = std::max(1u, std::thread::hardware_concurrency());
|
|
|
|
|
|
std::string cmd = std::format("cmake --build {} --parallel {}", ShellQuote(fs::absolute(cmakeBuildDir).string()), jobs);
|
2026-04-27 07:04:42 +02:00
|
|
|
|
CommandResult r = RunCommandChecked(cmd);
|
|
|
|
|
|
if (r.exitCode != 0) {
|
|
|
|
|
|
return std::format("cmake --build failed (exit {}): {}", r.exitCode, r.output);
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
feat(lint): no-char-pointer reads the AST, retiring the interop denylist
The rule was `\bchar\s*\*` over the text minus a substring denylist — argv,
getenv, setenv, dlerror, c_str, .data(, reinterpret_cast, extern ". Every entry
was a patch for one interop site, the list could only grow as libraries
arrived, and each entry disabled the rule for the whole LINE it appeared on.
It now walks declarations and asks the question the denylist was approximating:
whose header dictates this spelling? A declaration with C language linkage, or
one whose initialiser binds to an entity declared outside the project root, is
somebody else's API and keeps its spelling. getenv, c_str and friends are
exempt because of where they are declared, not because they are named here, so
a new external library needs no new entry.
Two bugs found while testing this, both of which had made the rule silently
pass over the entire repository:
clang_getCursorLanguage cannot be used to detect extern "C". Its default answer
is CXLanguage_C for a plain function, variable or parameter even in a C++
translation unit, so isExternC was true almost everywhere and exempted
everything. Replaced by tracking CXCursor_LinkageSpec depth during the walk,
reading the extent text to tell extern "C" from extern "C++".
Attributing any foreign reference in a subtree to the enclosing declaration was
too broad: a function that merely touched libc++ somewhere in its body would
exempt its own signature. Narrowed to initialiser contexts — a variable, field
or parameter — which is where a binding to a foreign API actually occurs.
Also: functions now carry their RESULT type rather than the whole function
type, since the parameters arrive as their own declarations and would otherwise
be reported twice. main's parameters are exempt structurally, its signature
being fixed by the language rather than chosen here.
Two sites keep an explicit lint-disable, both Crafter::Run taking main's argv
verbatim. That is two visible, reasoned suppressions in place of a denylist
that silently disabled the rule for every line mentioning one of eight tokens.
ExternalCloneDir and ExternalIncludeFlags are now exposed from :External, so a
source that includes an external dependency's headers can be parsed without
running a build to discover where they are. BuildExternal derives its own
working directory through the same function, so the two cannot drift.
Crafter.Build-Shader.cpp needed this to parse at all.
A file with no compile command — project.cpp, which LoadProject builds with its
own flags — is not a translation unit of the build graph, so AST rules skip it
the way a rule self-filters by extension. That is distinct from a file that
should have parsed and did not, which stays an error.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 23:46:32 +02:00
|
|
|
|
fs::path Crafter::ExternalCloneDir(const ExternalDependency& dep, std::string_view target) {
|
|
|
|
|
|
std::string name = dep.name.empty() ? DeriveName(dep.source) : dep.name;
|
|
|
|
|
|
if (name.empty()) return {};
|
|
|
|
|
|
std::string keyMaterial = std::format("{}|{}|{}|{}|{}", dep.source.url, dep.source.branch, dep.source.commit, JoinOptions(dep.options), target);
|
|
|
|
|
|
std::size_t key = std::hash<std::string>{}(keyMaterial);
|
|
|
|
|
|
return GetCacheDir() / "external" / std::format("{}-{:016x}", name, key);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> Crafter::ExternalIncludeFlags(const ExternalDependency& dep, std::string_view target) {
|
|
|
|
|
|
std::vector<std::string> flags;
|
|
|
|
|
|
fs::path cloneDir = ExternalCloneDir(dep, target);
|
|
|
|
|
|
if (cloneDir.empty()) return flags;
|
|
|
|
|
|
for (const fs::path& include : dep.includeDirs) {
|
|
|
|
|
|
fs::path full = include.empty() ? cloneDir : cloneDir / include;
|
|
|
|
|
|
flags.push_back(std::format("-I{}", fs::absolute(full).string()));
|
|
|
|
|
|
}
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
fs::path Crafter::ExternalBuildDir(const ExternalDependency& dep, std::string_view target) {
|
|
|
|
|
|
fs::path cloneDir = ExternalCloneDir(dep, target);
|
|
|
|
|
|
if (cloneDir.empty() || dep.builder != ExternalBuilder::CMake) return cloneDir;
|
|
|
|
|
|
return cloneDir / "build";
|
|
|
|
|
|
}
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
std::string Crafter::BuildExternal(const ExternalDependency& dep, std::string_view target) {
|
2026-04-27 07:04:42 +02:00
|
|
|
|
std::string name = dep.name.empty() ? DeriveName(dep.source) : dep.name;
|
|
|
|
|
|
if (name.empty()) {
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
return std::format("Could not derive name for external dependency from URL '{}'", dep.source.url);
|
2026-04-27 07:04:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fs::path externalRoot = GetCacheDir() / "external";
|
|
|
|
|
|
if (!fs::exists(externalRoot)) {
|
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
|
fs::create_directories(externalRoot, ec);
|
|
|
|
|
|
if (ec) {
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
return std::format("Failed to create {}: {}", externalRoot.string(), ec.message());
|
2026-04-27 07:04:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
feat(lint): no-char-pointer reads the AST, retiring the interop denylist
The rule was `\bchar\s*\*` over the text minus a substring denylist — argv,
getenv, setenv, dlerror, c_str, .data(, reinterpret_cast, extern ". Every entry
was a patch for one interop site, the list could only grow as libraries
arrived, and each entry disabled the rule for the whole LINE it appeared on.
It now walks declarations and asks the question the denylist was approximating:
whose header dictates this spelling? A declaration with C language linkage, or
one whose initialiser binds to an entity declared outside the project root, is
somebody else's API and keeps its spelling. getenv, c_str and friends are
exempt because of where they are declared, not because they are named here, so
a new external library needs no new entry.
Two bugs found while testing this, both of which had made the rule silently
pass over the entire repository:
clang_getCursorLanguage cannot be used to detect extern "C". Its default answer
is CXLanguage_C for a plain function, variable or parameter even in a C++
translation unit, so isExternC was true almost everywhere and exempted
everything. Replaced by tracking CXCursor_LinkageSpec depth during the walk,
reading the extent text to tell extern "C" from extern "C++".
Attributing any foreign reference in a subtree to the enclosing declaration was
too broad: a function that merely touched libc++ somewhere in its body would
exempt its own signature. Narrowed to initialiser contexts — a variable, field
or parameter — which is where a binding to a foreign API actually occurs.
Also: functions now carry their RESULT type rather than the whole function
type, since the parameters arrive as their own declarations and would otherwise
be reported twice. main's parameters are exempt structurally, its signature
being fixed by the language rather than chosen here.
Two sites keep an explicit lint-disable, both Crafter::Run taking main's argv
verbatim. That is two visible, reasoned suppressions in place of a denylist
that silently disabled the rule for every line mentioning one of eight tokens.
ExternalCloneDir and ExternalIncludeFlags are now exposed from :External, so a
source that includes an external dependency's headers can be parsed without
running a build to discover where they are. BuildExternal derives its own
working directory through the same function, so the two cannot drift.
Crafter.Build-Shader.cpp needed this to parse at all.
A file with no compile command — project.cpp, which LoadProject builds with its
own flags — is not a translation unit of the build graph, so AST rules skip it
the way a rule self-filters by extension. That is distinct from a file that
should have parsed and did not, which stays an error.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 23:46:32 +02:00
|
|
|
|
fs::path cloneDir = ExternalCloneDir(dep, target);
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
// Build() makes one call for all the configurations of a pass, but two
|
|
|
|
|
|
// crafter-builds, or two passes, can still reach the same clone at once,
|
|
|
|
|
|
// and two pulls in one clone race on its .git/FETCH_HEAD.
|
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
|
|
|
|
FileLock lock(fs::path(std::format("{}.lock", cloneDir.string())));
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
if (std::string err = FetchGit(dep.source, cloneDir); !err.empty()) {
|
|
|
|
|
|
return std::format("git fetch for '{}': {}", name, err);
|
2026-04-27 07:04:42 +02:00
|
|
|
|
}
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
if (dep.builder != ExternalBuilder::CMake) return "";
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
const fs::path cmakeBuildDir = ExternalBuildDir(dep, target);
|
|
|
|
|
|
if (std::string err = ConfigureCMake(cloneDir, cmakeBuildDir, dep.options, target); !err.empty()) {
|
|
|
|
|
|
return std::format("cmake configure for '{}': {}", name, err);
|
2026-04-27 07:04:42 +02:00
|
|
|
|
}
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
if (std::string err = BuildCMake(cmakeBuildDir); !err.empty()) {
|
|
|
|
|
|
return std::format("cmake build for '{}': {}", name, err);
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
ExternalBuildResult Crafter::ExternalOutputs(const ExternalDependency& dep, std::string_view target) {
|
|
|
|
|
|
ExternalBuildResult result;
|
feat(lint): no-char-pointer reads the AST, retiring the interop denylist
The rule was `\bchar\s*\*` over the text minus a substring denylist — argv,
getenv, setenv, dlerror, c_str, .data(, reinterpret_cast, extern ". Every entry
was a patch for one interop site, the list could only grow as libraries
arrived, and each entry disabled the rule for the whole LINE it appeared on.
It now walks declarations and asks the question the denylist was approximating:
whose header dictates this spelling? A declaration with C language linkage, or
one whose initialiser binds to an entity declared outside the project root, is
somebody else's API and keeps its spelling. getenv, c_str and friends are
exempt because of where they are declared, not because they are named here, so
a new external library needs no new entry.
Two bugs found while testing this, both of which had made the rule silently
pass over the entire repository:
clang_getCursorLanguage cannot be used to detect extern "C". Its default answer
is CXLanguage_C for a plain function, variable or parameter even in a C++
translation unit, so isExternC was true almost everywhere and exempted
everything. Replaced by tracking CXCursor_LinkageSpec depth during the walk,
reading the extent text to tell extern "C" from extern "C++".
Attributing any foreign reference in a subtree to the enclosing declaration was
too broad: a function that merely touched libc++ somewhere in its body would
exempt its own signature. Narrowed to initialiser contexts — a variable, field
or parameter — which is where a binding to a foreign API actually occurs.
Also: functions now carry their RESULT type rather than the whole function
type, since the parameters arrive as their own declarations and would otherwise
be reported twice. main's parameters are exempt structurally, its signature
being fixed by the language rather than chosen here.
Two sites keep an explicit lint-disable, both Crafter::Run taking main's argv
verbatim. That is two visible, reasoned suppressions in place of a denylist
that silently disabled the rule for every line mentioning one of eight tokens.
ExternalCloneDir and ExternalIncludeFlags are now exposed from :External, so a
source that includes an external dependency's headers can be parsed without
running a build to discover where they are. BuildExternal derives its own
working directory through the same function, so the two cannot drift.
Crafter.Build-Shader.cpp needed this to parse at all.
A file with no compile command — project.cpp, which LoadProject builds with its
own flags — is not a translation unit of the build graph, so AST rules skip it
the way a rule self-filters by extension. That is distinct from a file that
should have parsed and did not, which stays an error.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 23:46:32 +02:00
|
|
|
|
result.compileFlags = ExternalIncludeFlags(dep, target);
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
const fs::path cmakeBuildDir = ExternalBuildDir(dep, target);
|
|
|
|
|
|
if (dep.builder != ExternalBuilder::CMake || cmakeBuildDir.empty()) return result;
|
|
|
|
|
|
|
refactor: carry run paths as directories, not -Wl,-rpath flags
ExternalOutputs put an -Wl,-rpath,<dir> per library directory of a CMake
external into its link flags, and the flags travelled up the dependency
graph in BuildResult::libs to every link that consumed them: an
executable's or a shared library's, and that of the project.so
LoadProject links against a project file's pragma dependencies. Whether
a program should record those directories depends on how it is packaged:
a Flatpak has to load its libraries from its own files/lib instead, and
has to know the directories to copy them from. ExternalBuildResult and
BuildResult now carry them as runPaths, merged up the graph beside libs,
and all three links turn each into an -Wl,-rpath as before, so the link
commands differ only in the order of their flags. PragmaSharedExternal
holds project.so's link to them.
2026-11-01 18:56:41 +01:00
|
|
|
|
// Each search path is both a -L (link time) and a run path (the
|
|
|
|
|
|
// loader's), so the program picks its shared dependencies up from the
|
|
|
|
|
|
// cache without any LD_LIBRARY_PATH gymnastics; static ones (.a) need
|
|
|
|
|
|
// the run path not at all and are not hurt by it. The PE/COFF target
|
|
|
|
|
|
// (mingw) resolves DLLs through PATH or the program's own directory
|
|
|
|
|
|
// rather than a run path, and lld warns if it is given one.
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
const bool isPe = target == "x86_64-w64-mingw32";
|
|
|
|
|
|
std::string buildDirAbs = fs::absolute(cmakeBuildDir).string();
|
|
|
|
|
|
result.linkFlags.push_back(std::format("-L{}", buildDirAbs));
|
refactor: carry run paths as directories, not -Wl,-rpath flags
ExternalOutputs put an -Wl,-rpath,<dir> per library directory of a CMake
external into its link flags, and the flags travelled up the dependency
graph in BuildResult::libs to every link that consumed them: an
executable's or a shared library's, and that of the project.so
LoadProject links against a project file's pragma dependencies. Whether
a program should record those directories depends on how it is packaged:
a Flatpak has to load its libraries from its own files/lib instead, and
has to know the directories to copy them from. ExternalBuildResult and
BuildResult now carry them as runPaths, merged up the graph beside libs,
and all three links turn each into an -Wl,-rpath as before, so the link
commands differ only in the order of their flags. PragmaSharedExternal
holds project.so's link to them.
2026-11-01 18:56:41 +01:00
|
|
|
|
if (!isPe) result.runPaths.push_back(buildDirAbs);
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
for (const fs::path& libDir : dep.libDirs) {
|
|
|
|
|
|
fs::path full = libDir.is_absolute() ? libDir : cmakeBuildDir / libDir;
|
|
|
|
|
|
std::string fullAbs = fs::absolute(full).string();
|
|
|
|
|
|
result.linkFlags.push_back(std::format("-L{}", fullAbs));
|
refactor: carry run paths as directories, not -Wl,-rpath flags
ExternalOutputs put an -Wl,-rpath,<dir> per library directory of a CMake
external into its link flags, and the flags travelled up the dependency
graph in BuildResult::libs to every link that consumed them: an
executable's or a shared library's, and that of the project.so
LoadProject links against a project file's pragma dependencies. Whether
a program should record those directories depends on how it is packaged:
a Flatpak has to load its libraries from its own files/lib instead, and
has to know the directories to copy them from. ExternalBuildResult and
BuildResult now carry them as runPaths, merged up the graph beside libs,
and all three links turn each into an -Wl,-rpath as before, so the link
commands differ only in the order of their flags. PragmaSharedExternal
holds project.so's link to them.
2026-11-01 18:56:41 +01:00
|
|
|
|
if (!isPe) result.runPaths.push_back(fullAbs);
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
for (const std::string& lib : dep.libs) {
|
|
|
|
|
|
result.linkFlags.push_back(std::format("-l{}", lib));
|
|
|
|
|
|
}
|
2026-04-27 07:04:42 +02:00
|
|
|
|
|
fix(external): fetch and build each clone once per build pass
`crafter-build test` builds a project's tests side by side, and a
project whose tests each copy its externalDependencies hands every one
of them the same unpinned dependency. Each test's Build() pulled the
shared clone. Before the clone had a lock, those pulls ran at the same
time and broke its .git/FETCH_HEAD, which failed every test of
Crafter.Graphics (issue #34). Since 653dd0b they wait for each other,
but every one is still a network round trip: 26 tests cost 26 pulls of
each dependency, one after another, and for a CMake dependency as many
configure checks and builds.
depResults already records one build pass, keyed by the PcmDir of every
dependency configuration built in it. An external dependency now goes
in the same map, keyed by the directory its build leaves
(ExternalBuildDir: the clone, or for CMake its build directory). The
first configuration that needs it fetches and builds it; the others
wait for that and take its outcome. Keying on the build directory
rather than the clone keeps a CMake declaration from taking the outcome
of a header-only declaration of the same clone, which only fetched it.
A fresh depResults is a fresh pass, so the next build still pulls, and
every caller of Build() gets this: RunTests, a plain build, and the
pragma dependencies LoadProject builds.
To make that possible BuildExternal is split. BuildExternal is now the
shared work, lock, fetch, configure and build, and returns the error.
ExternalOutputs computes what one declaration compiles and links with,
because two declarations of one clone can differ in includeDirs,
libDirs and libs; ExternalBuildResult loses its error field. The work
no longer stops between steps when the configuration that started it
is cancelled: others may be waiting on it, and a run cut short would
leave them a clone nobody fetched. A dependency configuration's Build()
already runs to completion for the same reason.
The promise and future the dependency threads used to build or wait for
a configuration are now one helper, OncePerPass, which both kinds use.
An exception thrown in BuildExternal used to escape its thread into
std::terminate; it is now a build error, as for a dependency.
With eight tests that share a local dependency, a test run fetched it
eight times before this and fetches it once now (SharedExternalFetch,
next commit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 02:09:24 +01:00
|
|
|
|
// The newest library in every directory the link searches: the build
|
|
|
|
|
|
// directory and the libDirs, where projects like msquic put theirs,
|
|
|
|
|
|
// versioned names (libmsquic.so.2) included.
|
|
|
|
|
|
auto isLibrary = [](const std::string& name) {
|
|
|
|
|
|
return name.ends_with(".a") || name.ends_with(".so") || name.contains(".so.") || name.ends_with(".dll");
|
|
|
|
|
|
};
|
|
|
|
|
|
std::vector<fs::path> searched = { cmakeBuildDir };
|
|
|
|
|
|
for (const fs::path& libDir : dep.libDirs) searched.push_back(libDir.is_absolute() ? libDir : cmakeBuildDir / libDir);
|
|
|
|
|
|
for (const fs::path& dir : searched) {
|
|
|
|
|
|
std::error_code listEc;
|
|
|
|
|
|
for (fs::directory_iterator it(dir, listEc), end; !listEc && it != end; it.increment(listEc)) {
|
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
|
if (!it->is_regular_file(ec) || !isLibrary(it->path().filename().string())) continue;
|
|
|
|
|
|
fs::file_time_type t = it->last_write_time(ec);
|
|
|
|
|
|
if (!ec && t > result.latestArtifact) result.latestArtifact = t;
|
2026-04-27 07:04:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2026-04-30 02:20:19 +02:00
|
|
|
|
|
|
|
|
|
|
namespace {
|
2026-07-23 01:24:42 +02:00
|
|
|
|
std::mutex ProjectCacheMutex;
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
// What each project file loaded here returned, in the file's order, by
|
|
|
|
|
|
// spec and args. An entry is never changed or removed once it is in.
|
|
|
|
|
|
std::unordered_map<std::string, std::vector<Configuration*>> ProjectCache;
|
|
|
|
|
|
// Keyed by the Configurations ProjectCache holds, which live as long as
|
|
|
|
|
|
// the process does (see LoadConfigurations), so the pointers never
|
|
|
|
|
|
// dangle. Guarded by ProjectCacheMutex as well.
|
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
|
|
|
|
std::unordered_map<const Configuration*, LoadedProject> LoadedProjects;
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
// The configurations a loaded project keeps to itself, with the project:
|
|
|
|
|
|
// what the configurations its file returned led to when the file was
|
|
|
|
|
|
// loaded and the file did not return. A configuration leads to what it
|
|
|
|
|
|
// is built on and to the configurations of its tests, and each of those
|
|
|
|
|
|
// leads on in the same way. Taken down at that moment, since a consumer
|
|
|
|
|
|
// may add to the `dependencies` of a configuration it was given, and
|
|
|
|
|
|
// what it adds is its own. Guarded by ProjectCacheMutex as well.
|
|
|
|
|
|
std::unordered_map<const Configuration*, LoadedProject> KeptConfigurations;
|
|
|
|
|
|
|
|
|
|
|
|
// What the cache holds under `fullHash`, or nullptr.
|
|
|
|
|
|
const std::vector<Configuration*>* CachedProject(const std::string& fullHash) {
|
|
|
|
|
|
const std::lock_guard lock(ProjectCacheMutex);
|
|
|
|
|
|
const auto it = ProjectCache.find(fullHash);
|
|
|
|
|
|
return it == ProjectCache.end() ? nullptr : &it->second;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// cfg.path and every other relative path collection of `cfg`, made
|
|
|
|
|
|
// absolute against `depRoot`, so Build() can run from any cwd without
|
|
|
|
|
|
// misresolving them.
|
|
|
|
|
|
void RebaseOnto(Configuration& cfg, const fs::path& depRoot) {
|
2026-04-30 02:20:19 +02:00
|
|
|
|
cfg.path = fs::absolute(depRoot / cfg.path).lexically_normal();
|
|
|
|
|
|
auto abs = [&](const fs::path& p) -> fs::path {
|
|
|
|
|
|
return p.is_absolute() ? p : fs::absolute(depRoot / p).lexically_normal();
|
|
|
|
|
|
};
|
|
|
|
|
|
for (fs::path& p : cfg.cFiles) p = abs(p);
|
|
|
|
|
|
for (fs::path& p : cfg.cuda) p = abs(p);
|
|
|
|
|
|
for (fs::path& p : cfg.files) p = abs(p);
|
2026-05-02 21:08:51 +02:00
|
|
|
|
for (fs::path& p : cfg.buildFiles) p = abs(p);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
for (Shader& s : cfg.shaders) s.path = abs(s.path);
|
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
|
|
|
|
// A dependency that packages its own executable as a Flatpak names
|
|
|
|
|
|
// the files it is installed with as it names its cfg.files. An
|
|
|
|
|
|
// empty one is none, and stays empty.
|
|
|
|
|
|
if (!cfg.flatpak.desktopFile.empty()) cfg.flatpak.desktopFile = abs(cfg.flatpak.desktopFile);
|
|
|
|
|
|
if (!cfg.flatpak.metainfo.empty()) cfg.flatpak.metainfo = abs(cfg.flatpak.metainfo);
|
|
|
|
|
|
for (fs::path& p : cfg.flatpak.icons) p = abs(p);
|
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
|
|
|
|
for (fs::path& p : cfg.flatpak.modules) p = abs(p);
|
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
|
|
|
|
for (auto& entry : cfg.flatpak.share) {
|
|
|
|
|
|
if (!entry.source.empty()) entry.source = abs(entry.source);
|
|
|
|
|
|
}
|
2026-04-30 02:20:19 +02:00
|
|
|
|
}
|
fix(agents): what the review of dependency notes found
A review of the feature turned up the following, fixed here.
Writing. AGENTS.md was replaced through a temporary renamed over it,
which swaps in another file: a read-only AGENTS.md was rewritten
anyway, a hard link such as a CLAUDE.md beside it kept the old text,
ACLs and ownership were dropped, and without an fsync a power cut could
still leave it empty. The temporary was named after the PID, which
every Flatpak instance shares as PID 2. The file is now written in
place, from the first byte that differs, then truncated and synced,
under an flock on the file itself. A write that fails partway is undone
where the disk allows; with the section last, where it is appended,
only the section can be damaged. A read-only file is opened for writing
only when something would change, so it is refused then and silent
otherwise.
Reading. libc++'s filebuf reports a failed read as the end of the file,
so an I/O error came back as a short file and the section was written
over what was left. Reads go through read(2).
Code fences. ```make``` was taken for a fence, and a fence in a list
item was missed while its indented closer opened one, so markers a user
quoted in a code block could be taken for the section, or the real one
hidden and appended again. Backtick info strings, block quotes and list
items are now followed, and a block ends with its container.
Warnings with nothing to write. With no notes, nothing short of a
well-formed section is reported, so an AGENTS.md that ends in an open
code block, or a project set to None, no longer warns on every build.
An unclosed fence after a section no longer stops it being rewritten
in place.
Labels. The `from` line carried the git URL, credentials and all, or a
path relative to the consumer that changed with the machine, the cache
location and --local. It is now the repository's or the directory's
name. Notes are deduplicated by repository rather than by clone, so one
library pinned two ways is described once, as the nearer spec has it.
The walk. It no longer looks at the project's tests: a plain build
never did, and a test's dependency can point at the Configuration the
project file returned by value. It goes ring by ring over projects
rather than configurations, so what the project names itself comes
first even with the library/executable split. The project's own
AGENTS.consumer.md is excluded by path, also when a dependency's
project file sits beside the project's.
Removing a section dropped a blank line even from between two
paragraphs, joining them; only a section that ends the file takes it
now. A CRLF file gets a CRLF section.
A note was checked on its raw bytes and again, under other whitespace
rules, on the trimmed ones, so it could pass the first check and fail
the merge, which then dropped every note. It is normalised once and
checked on exactly what is merged.
`test --list` only lists, and no longer writes AGENTS.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 05:02:28 +01:00
|
|
|
|
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
// Run the dep's project.cpp from its own directory so its relative paths
|
|
|
|
|
|
// (cfg.path = "./", interfaces/, lib/, ...) resolve against the dep
|
|
|
|
|
|
// root, then rebase every configuration it returns onto that root.
|
|
|
|
|
|
// The mutex is NOT held across the load — the dep may itself call
|
|
|
|
|
|
// GitProject/LocalProject, and a non-recursive lock would deadlock.
|
|
|
|
|
|
std::vector<Configuration*> LoadProjectFromRoot(const fs::path& projectPath, const fs::path& depRoot, std::span<const std::string_view> args) {
|
|
|
|
|
|
fs::path savedCwd = fs::current_path();
|
|
|
|
|
|
std::vector<Configuration*> configurations;
|
|
|
|
|
|
fs::current_path(depRoot);
|
|
|
|
|
|
try {
|
|
|
|
|
|
configurations = LoadConfigurations(projectPath, args);
|
|
|
|
|
|
} catch (...) {
|
|
|
|
|
|
fs::current_path(savedCwd);
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
fs::current_path(savedCwd);
|
|
|
|
|
|
for (Configuration* cfg : configurations) {
|
|
|
|
|
|
// One the file loaded from another project file and returns
|
|
|
|
|
|
// itself was rebased onto that project's root when it was
|
|
|
|
|
|
// loaded, and other consumers may be reading it by now.
|
|
|
|
|
|
if (!LoadedProjectOf(*cfg)) RebaseOnto(*cfg, depRoot);
|
|
|
|
|
|
}
|
|
|
|
|
|
return configurations;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Into ProjectCache under `fullHash`, with `loaded` recorded beside each
|
|
|
|
|
|
// configuration that is not another project's already, and beside what
|
|
|
|
|
|
// those are built on and the file kept to itself. When another thread
|
|
|
|
|
|
// stored the same spec first, what it stored wins.
|
|
|
|
|
|
const std::vector<Configuration*>& StoreProject(std::string fullHash, std::vector<Configuration*> configurations, const LoadedProject& loaded) {
|
|
|
|
|
|
const std::lock_guard lock(ProjectCacheMutex);
|
fix(agents): what the review of dependency notes found
A review of the feature turned up the following, fixed here.
Writing. AGENTS.md was replaced through a temporary renamed over it,
which swaps in another file: a read-only AGENTS.md was rewritten
anyway, a hard link such as a CLAUDE.md beside it kept the old text,
ACLs and ownership were dropped, and without an fsync a power cut could
still leave it empty. The temporary was named after the PID, which
every Flatpak instance shares as PID 2. The file is now written in
place, from the first byte that differs, then truncated and synced,
under an flock on the file itself. A write that fails partway is undone
where the disk allows; with the section last, where it is appended,
only the section can be damaged. A read-only file is opened for writing
only when something would change, so it is refused then and silent
otherwise.
Reading. libc++'s filebuf reports a failed read as the end of the file,
so an I/O error came back as a short file and the section was written
over what was left. Reads go through read(2).
Code fences. ```make``` was taken for a fence, and a fence in a list
item was missed while its indented closer opened one, so markers a user
quoted in a code block could be taken for the section, or the real one
hidden and appended again. Backtick info strings, block quotes and list
items are now followed, and a block ends with its container.
Warnings with nothing to write. With no notes, nothing short of a
well-formed section is reported, so an AGENTS.md that ends in an open
code block, or a project set to None, no longer warns on every build.
An unclosed fence after a section no longer stops it being rewritten
in place.
Labels. The `from` line carried the git URL, credentials and all, or a
path relative to the consumer that changed with the machine, the cache
location and --local. It is now the repository's or the directory's
name. Notes are deduplicated by repository rather than by clone, so one
library pinned two ways is described once, as the nearer spec has it.
The walk. It no longer looks at the project's tests: a plain build
never did, and a test's dependency can point at the Configuration the
project file returned by value. It goes ring by ring over projects
rather than configurations, so what the project names itself comes
first even with the library/executable split. The project's own
AGENTS.consumer.md is excluded by path, also when a dependency's
project file sits beside the project's.
Removing a section dropped a blank line even from between two
paragraphs, joining them; only a section that ends the file takes it
now. A CRLF file gets a CRLF section.
A note was checked on its raw bytes and again, under other whitespace
rules, on the trimmed ones, so it could pass the first check and fail
the merge, which then dropped every note. It is normalised once and
checked on exactly what is merged.
`test --list` only lists, and no longer writes AGENTS.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 05:02:28 +01:00
|
|
|
|
if (auto it = ProjectCache.find(fullHash); it != ProjectCache.end()) {
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
return it->second;
|
|
|
|
|
|
}
|
|
|
|
|
|
// What this file returned, and then what each of those leads to:
|
|
|
|
|
|
// what it is built on and the configurations of its tests. One that
|
|
|
|
|
|
// another project's file returned is that project's, and so is what
|
|
|
|
|
|
// is found from there.
|
|
|
|
|
|
std::vector<const Configuration*> pending;
|
|
|
|
|
|
const auto leadsTo = [&pending](const Configuration& cfg) {
|
|
|
|
|
|
pending.insert(pending.end(), cfg.dependencies.begin(), cfg.dependencies.end());
|
|
|
|
|
|
for (const Test& test : cfg.tests) pending.push_back(&test.config);
|
|
|
|
|
|
};
|
|
|
|
|
|
for (const Configuration* cfg : configurations) {
|
|
|
|
|
|
if (LoadedProjects.try_emplace(cfg, loaded).second) leadsTo(*cfg);
|
|
|
|
|
|
}
|
|
|
|
|
|
while (!pending.empty()) {
|
|
|
|
|
|
const Configuration* kept = pending.back();
|
|
|
|
|
|
pending.pop_back();
|
|
|
|
|
|
if (!kept || LoadedProjects.contains(kept) || !KeptConfigurations.try_emplace(kept, loaded).second) continue;
|
|
|
|
|
|
leadsTo(*kept);
|
|
|
|
|
|
}
|
|
|
|
|
|
return ProjectCache.emplace(std::move(fullHash), std::move(configurations)).first->second;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The one of `configurations` a spec asks for by `name`: the first for
|
|
|
|
|
|
// an empty name. `what` names the spec in the error for a name that none
|
|
|
|
|
|
// has, or that two have.
|
|
|
|
|
|
Configuration* PickConfiguration(std::span<Configuration* const> configurations, std::string_view name, std::string_view what) {
|
|
|
|
|
|
if (name.empty()) return configurations.front();
|
|
|
|
|
|
Configuration* picked = nullptr;
|
|
|
|
|
|
for (Configuration* cfg : configurations) {
|
|
|
|
|
|
if (cfg->name != name) continue;
|
|
|
|
|
|
if (picked) throw std::runtime_error(std::format("{}: two of its configurations are named '{}', so the name picks neither", what, name));
|
|
|
|
|
|
picked = cfg;
|
fix(agents): what the review of dependency notes found
A review of the feature turned up the following, fixed here.
Writing. AGENTS.md was replaced through a temporary renamed over it,
which swaps in another file: a read-only AGENTS.md was rewritten
anyway, a hard link such as a CLAUDE.md beside it kept the old text,
ACLs and ownership were dropped, and without an fsync a power cut could
still leave it empty. The temporary was named after the PID, which
every Flatpak instance shares as PID 2. The file is now written in
place, from the first byte that differs, then truncated and synced,
under an flock on the file itself. A write that fails partway is undone
where the disk allows; with the section last, where it is appended,
only the section can be damaged. A read-only file is opened for writing
only when something would change, so it is refused then and silent
otherwise.
Reading. libc++'s filebuf reports a failed read as the end of the file,
so an I/O error came back as a short file and the section was written
over what was left. Reads go through read(2).
Code fences. ```make``` was taken for a fence, and a fence in a list
item was missed while its indented closer opened one, so markers a user
quoted in a code block could be taken for the section, or the real one
hidden and appended again. Backtick info strings, block quotes and list
items are now followed, and a block ends with its container.
Warnings with nothing to write. With no notes, nothing short of a
well-formed section is reported, so an AGENTS.md that ends in an open
code block, or a project set to None, no longer warns on every build.
An unclosed fence after a section no longer stops it being rewritten
in place.
Labels. The `from` line carried the git URL, credentials and all, or a
path relative to the consumer that changed with the machine, the cache
location and --local. It is now the repository's or the directory's
name. Notes are deduplicated by repository rather than by clone, so one
library pinned two ways is described once, as the nearer spec has it.
The walk. It no longer looks at the project's tests: a plain build
never did, and a test's dependency can point at the Configuration the
project file returned by value. It goes ring by ring over projects
rather than configurations, so what the project names itself comes
first even with the library/executable split. The project's own
AGENTS.consumer.md is excluded by path, also when a dependency's
project file sits beside the project's.
Removing a section dropped a blank line even from between two
paragraphs, joining them; only a section that ends the file takes it
now. A CRLF file gets a CRLF section.
A note was checked on its raw bytes and again, under other whitespace
rules, on the trimmed ones, so it could pass the first check and fail
the merge, which then dropped every note. It is normalised once and
checked on exactly what is merged.
`test --list` only lists, and no longer writes AGENTS.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 05:02:28 +01:00
|
|
|
|
}
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
if (picked) return picked;
|
|
|
|
|
|
std::string names;
|
|
|
|
|
|
for (const Configuration* cfg : configurations) {
|
|
|
|
|
|
if (!names.empty()) names += ", ";
|
|
|
|
|
|
names += cfg->name;
|
|
|
|
|
|
}
|
|
|
|
|
|
throw std::runtime_error(std::format("{}: no configuration named '{}' (it has: {})", what, name, names));
|
fix(agents): what the review of dependency notes found
A review of the feature turned up the following, fixed here.
Writing. AGENTS.md was replaced through a temporary renamed over it,
which swaps in another file: a read-only AGENTS.md was rewritten
anyway, a hard link such as a CLAUDE.md beside it kept the old text,
ACLs and ownership were dropped, and without an fsync a power cut could
still leave it empty. The temporary was named after the PID, which
every Flatpak instance shares as PID 2. The file is now written in
place, from the first byte that differs, then truncated and synced,
under an flock on the file itself. A write that fails partway is undone
where the disk allows; with the section last, where it is appended,
only the section can be damaged. A read-only file is opened for writing
only when something would change, so it is refused then and silent
otherwise.
Reading. libc++'s filebuf reports a failed read as the end of the file,
so an I/O error came back as a short file and the section was written
over what was left. Reads go through read(2).
Code fences. ```make``` was taken for a fence, and a fence in a list
item was missed while its indented closer opened one, so markers a user
quoted in a code block could be taken for the section, or the real one
hidden and appended again. Backtick info strings, block quotes and list
items are now followed, and a block ends with its container.
Warnings with nothing to write. With no notes, nothing short of a
well-formed section is reported, so an AGENTS.md that ends in an open
code block, or a project set to None, no longer warns on every build.
An unclosed fence after a section no longer stops it being rewritten
in place.
Labels. The `from` line carried the git URL, credentials and all, or a
path relative to the consumer that changed with the machine, the cache
location and --local. It is now the repository's or the directory's
name. Notes are deduplicated by repository rather than by clone, so one
library pinned two ways is described once, as the nearer spec has it.
The walk. It no longer looks at the project's tests: a plain build
never did, and a test's dependency can point at the Configuration the
project file returned by value. It goes ring by ring over projects
rather than configurations, so what the project names itself comes
first even with the library/executable split. The project's own
AGENTS.consumer.md is excluded by path, also when a dependency's
project file sits beside the project's.
Removing a section dropped a blank line even from between two
paragraphs, joining them; only a section that ends the file takes it
now. A CRLF file gets a CRLF section.
A note was checked on its raw bytes and again, under other whitespace
rules, on the trimmed ones, so it could pass the first check and fail
the merge, which then dropped every note. It is normalised once and
checked on exactly what is merged.
`test --list` only lists, and no longer writes AGENTS.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 05:02:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// `url` as it names a repository: without user info, which is where a
|
|
|
|
|
|
// token goes, and without trailing slashes or ".git", so specs that only
|
|
|
|
|
|
// spell the repository differently name the same one.
|
|
|
|
|
|
std::string RepositoryKey(std::string_view url) {
|
|
|
|
|
|
std::string key(url);
|
|
|
|
|
|
if (const std::size_t scheme = key.find("://"); scheme != std::string::npos) {
|
|
|
|
|
|
const std::size_t host = scheme + 3;
|
|
|
|
|
|
const std::size_t at = key.rfind('@', key.find('/', host));
|
|
|
|
|
|
if (at != std::string::npos && at >= host) key.erase(host, at + 1 - host);
|
|
|
|
|
|
}
|
|
|
|
|
|
while (key.ends_with('/')) key.pop_back();
|
|
|
|
|
|
if (key.ends_with(".git")) key.resize(key.size() - 4);
|
|
|
|
|
|
return key;
|
|
|
|
|
|
}
|
2026-04-30 02:20:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Configuration* Crafter::GitProject(const GitProjectSpec& spec) {
|
|
|
|
|
|
// Two hashes: the clone is shared across specs that point at the same
|
|
|
|
|
|
// source revision (forwarded args don't change what gets cloned, just
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
// how the dep's project.cpp interprets them at runtime), while what the
|
|
|
|
|
|
// file returned is keyed by the args as well, so each (args)
|
|
|
|
|
|
// permutation gets its own Configuration objects, and host tooling ones
|
|
|
|
|
|
// apart from the target's even for the same args. Which configuration
|
|
|
|
|
|
// the spec picks is in neither: it chooses among what one load returned.
|
2026-07-23 01:24:42 +02:00
|
|
|
|
std::string srcKey = std::format("git|{}|{}|{}|{}", spec.source.url, spec.source.branch, spec.source.commit, spec.projectFile.string());
|
2026-04-30 02:20:19 +02:00
|
|
|
|
std::string srcHash = std::format("{:016x}", std::hash<std::string>{}(srcKey));
|
|
|
|
|
|
|
fix: keep host tooling out of the project cache the target uses
ForceHostTooling rewrites a `#pragma crafter dependency` and everything
it loads in place: host target, march native, release, -fPIC. Those are
entries of the project cache like any other, keyed by project file and
args alone. A project that loaded the same sibling as its tool, with
the same args, got the rewritten entry back. That happens whenever the
project gets no args, since host tooling gets none either: a consumer
built for x86-64-v2 then imported a sibling's BMI compiled with
-march=native, and clang refused it. Any arg on the command line split
the keys and hid it.
A thread-local count of pragma loads now marks the tool's load and
every load inside it, its project file's siblings included, and
GitProject and LocalProject put that mark in the key. The clone stays
shared; only the Configuration is separate, as for two arg lists. A
module-internal function rather than a spec field, because the
siblings of a tool are loaded by the tool's own project.cpp, which
cannot know it is host tooling.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 05:10:21 +01:00
|
|
|
|
std::string fullKey = std::format("{}{}", LoadingHostTooling() ? "host|" : "", srcKey);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
for (const std::string& a : spec.args) {
|
|
|
|
|
|
fullKey += '|';
|
|
|
|
|
|
fullKey += a;
|
|
|
|
|
|
}
|
|
|
|
|
|
std::string fullHash = std::format("{:016x}", std::hash<std::string>{}(fullKey));
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
const std::string what = std::format("GitProject({})", spec.source.url);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
if (const std::vector<Configuration*>* cached = CachedProject(fullHash)) {
|
|
|
|
|
|
return PickConfiguration(*cached, spec.configuration, what);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string name = DeriveName(spec.source);
|
|
|
|
|
|
if (name.empty()) {
|
|
|
|
|
|
throw std::runtime_error(std::format("GitProject: could not derive name from URL '{}'", spec.source.url));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fs::path externalRoot = GetCacheDir() / "external";
|
|
|
|
|
|
fs::create_directories(externalRoot);
|
|
|
|
|
|
fs::path cloneDir = externalRoot / std::format("{}-{}", name, srcHash);
|
|
|
|
|
|
|
|
|
|
|
|
{
|
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
|
|
|
|
// One fetch of a clone at a time, as in BuildExternal.
|
|
|
|
|
|
FileLock lock(fs::path(std::format("{}.lock", cloneDir.string())));
|
feat(lint): const-local and constexpr-constant rules
Two rules the AST makes possible, plus the mutation analysis behind them.
const-local reports a local that is never written. It is restricted to SCALARS
— integers, bools, enums, floating types — and that restriction is what makes
the answer exact rather than a guess: a scalar has no member functions, so the
only ways to write one are assignment, ++/--, having its address taken, or
binding to a non-const reference. All four are now tracked in the walk:
- assignment and compound assignment visit their LEFT operand in a write
context, the right one normally;
- ++/-- and & write their operand;
- a call argument is checked against the callee's parameter type, so passing
to `const int&` or by value is a read while `int&` is a write;
- initialising a non-const reference writes what it binds to.
For a class type a non-const method call could mutate it, and deciding that is
the whole-program analysis clang-tidy does, so those are simply out of scope
rather than guessed at.
constexpr-constant promotes a const constant whose initialiser is made only of
literals and operators, so `const int A = 1 << 4;` qualifies and
`const int B = Compute();` does not.
On this repository const-local found 103 candidates, which was too many to be
useful, and the reason was informative: most were range-for bindings and
pointer locals. `for (T* const x : …)` and `T* const p` are not spellings
anybody writes, and the useful constness for a pointer is on the pointee, which
this rule cannot advise on. Excluding both leaves 36, all plain bool or enum
locals worth fixing — isWasm, isPe, exists, writes, isC and so on. Those 36 are
fixed in this commit; the compiler verified every one.
Both rules are report-only. The analysis is exact, but adding const is a
judgement about intent as much as mechanics, and a wrong suggestion should cost
a glance rather than a build. const-local also deliberately does not become a
transform: inserting `const` before a shared type would apply it to every
declarator in a multi-declarator statement, including any that IS written.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-31 00:50:48 +02:00
|
|
|
|
const bool exists = fs::exists(cloneDir);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
Progress::Task task(std::format("{} {}", exists ? "Updating" : "Cloning", name));
|
|
|
|
|
|
if (std::string err = FetchGit(spec.source, cloneDir); !err.empty()) {
|
|
|
|
|
|
throw std::runtime_error(std::format("GitProject({}): {}", spec.source.url, err));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fs::path projectPath = cloneDir / spec.projectFile;
|
|
|
|
|
|
if (!fs::exists(projectPath)) {
|
2026-07-23 01:24:42 +02:00
|
|
|
|
throw std::runtime_error(std::format("GitProject({}): {} not found in clone", spec.source.url, spec.projectFile.string()));
|
2026-04-30 02:20:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string_view> argViews(spec.args.begin(), spec.args.end());
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
std::vector<Configuration*> configurations = LoadProjectFromRoot(projectPath, cloneDir, argViews);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
|
fix(agents): what the review of dependency notes found
A review of the feature turned up the following, fixed here.
Writing. AGENTS.md was replaced through a temporary renamed over it,
which swaps in another file: a read-only AGENTS.md was rewritten
anyway, a hard link such as a CLAUDE.md beside it kept the old text,
ACLs and ownership were dropped, and without an fsync a power cut could
still leave it empty. The temporary was named after the PID, which
every Flatpak instance shares as PID 2. The file is now written in
place, from the first byte that differs, then truncated and synced,
under an flock on the file itself. A write that fails partway is undone
where the disk allows; with the section last, where it is appended,
only the section can be damaged. A read-only file is opened for writing
only when something would change, so it is refused then and silent
otherwise.
Reading. libc++'s filebuf reports a failed read as the end of the file,
so an I/O error came back as a short file and the section was written
over what was left. Reads go through read(2).
Code fences. ```make``` was taken for a fence, and a fence in a list
item was missed while its indented closer opened one, so markers a user
quoted in a code block could be taken for the section, or the real one
hidden and appended again. Backtick info strings, block quotes and list
items are now followed, and a block ends with its container.
Warnings with nothing to write. With no notes, nothing short of a
well-formed section is reported, so an AGENTS.md that ends in an open
code block, or a project set to None, no longer warns on every build.
An unclosed fence after a section no longer stops it being rewritten
in place.
Labels. The `from` line carried the git URL, credentials and all, or a
path relative to the consumer that changed with the machine, the cache
location and --local. It is now the repository's or the directory's
name. Notes are deduplicated by repository rather than by clone, so one
library pinned two ways is described once, as the nearer spec has it.
The walk. It no longer looks at the project's tests: a plain build
never did, and a test's dependency can point at the Configuration the
project file returned by value. It goes ring by ring over projects
rather than configurations, so what the project names itself comes
first even with the library/executable split. The project's own
AGENTS.consumer.md is excluded by path, also when a dependency's
project file sits beside the project's.
Removing a section dropped a blank line even from between two
paragraphs, joining them; only a section that ends the file takes it
now. A CRLF file gets a CRLF section.
A note was checked on its raw bytes and again, under other whitespace
rules, on the trimmed ones, so it could pass the first check and fail
the merge, which then dropped every note. It is normalised once and
checked on exactly what is merged.
`test --list` only lists, and no longer writes AGENTS.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 05:02:28 +01:00
|
|
|
|
const fs::path projectInRepo = spec.projectFile.lexically_normal();
|
|
|
|
|
|
const fs::path below = projectInRepo.parent_path();
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
return PickConfiguration(StoreProject(std::move(fullHash), std::move(configurations), {
|
fix(agents): what the review of dependency notes found
A review of the feature turned up the following, fixed here.
Writing. AGENTS.md was replaced through a temporary renamed over it,
which swaps in another file: a read-only AGENTS.md was rewritten
anyway, a hard link such as a CLAUDE.md beside it kept the old text,
ACLs and ownership were dropped, and without an fsync a power cut could
still leave it empty. The temporary was named after the PID, which
every Flatpak instance shares as PID 2. The file is now written in
place, from the first byte that differs, then truncated and synced,
under an flock on the file itself. A write that fails partway is undone
where the disk allows; with the section last, where it is appended,
only the section can be damaged. A read-only file is opened for writing
only when something would change, so it is refused then and silent
otherwise.
Reading. libc++'s filebuf reports a failed read as the end of the file,
so an I/O error came back as a short file and the section was written
over what was left. Reads go through read(2).
Code fences. ```make``` was taken for a fence, and a fence in a list
item was missed while its indented closer opened one, so markers a user
quoted in a code block could be taken for the section, or the real one
hidden and appended again. Backtick info strings, block quotes and list
items are now followed, and a block ends with its container.
Warnings with nothing to write. With no notes, nothing short of a
well-formed section is reported, so an AGENTS.md that ends in an open
code block, or a project set to None, no longer warns on every build.
An unclosed fence after a section no longer stops it being rewritten
in place.
Labels. The `from` line carried the git URL, credentials and all, or a
path relative to the consumer that changed with the machine, the cache
location and --local. It is now the repository's or the directory's
name. Notes are deduplicated by repository rather than by clone, so one
library pinned two ways is described once, as the nearer spec has it.
The walk. It no longer looks at the project's tests: a plain build
never did, and a test's dependency can point at the Configuration the
project file returned by value. It goes ring by ring over projects
rather than configurations, so what the project names itself comes
first even with the library/executable split. The project's own
AGENTS.consumer.md is excluded by path, also when a dependency's
project file sits beside the project's.
Removing a section dropped a blank line even from between two
paragraphs, joining them; only a section that ends the file takes it
now. A CRLF file gets a CRLF section.
A note was checked on its raw bytes and again, under other whitespace
rules, on the trimmed ones, so it could pass the first check and fail
the merge, which then dropped every note. It is normalised once and
checked on exactly what is merged.
`test --list` only lists, and no longer writes AGENTS.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 05:02:28 +01:00
|
|
|
|
.projectFile = projectPath.lexically_normal(),
|
|
|
|
|
|
.name = below.empty() ? name : std::format("{}/{}", name, below.generic_string()),
|
|
|
|
|
|
.identity = std::format("git|{}|{}", RepositoryKey(spec.source.url), projectInRepo.generic_string()),
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
}), spec.configuration, what);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-19 00:50:06 +02:00
|
|
|
|
fs::path Crafter::GitFetch(const GitSource& source) {
|
|
|
|
|
|
std::string name = DeriveName(source);
|
|
|
|
|
|
if (name.empty()) {
|
2026-07-23 01:24:42 +02:00
|
|
|
|
throw std::runtime_error(std::format("GitFetch: could not derive name from URL '{}'", source.url));
|
2026-05-19 00:50:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
fs::path externalRoot = GetCacheDir() / "external";
|
|
|
|
|
|
std::error_code ec;
|
|
|
|
|
|
fs::create_directories(externalRoot, ec);
|
|
|
|
|
|
if (ec) {
|
2026-07-23 01:24:42 +02:00
|
|
|
|
throw std::runtime_error(std::format("GitFetch: failed to create {}: {}", externalRoot.string(), ec.message()));
|
2026-05-19 00:50:06 +02:00
|
|
|
|
}
|
2026-07-23 01:24:42 +02:00
|
|
|
|
std::string keyMaterial = std::format("git|{}|{}|{}", source.url, source.branch, source.commit);
|
2026-05-19 00:50:06 +02:00
|
|
|
|
std::size_t key = std::hash<std::string>{}(keyMaterial);
|
|
|
|
|
|
fs::path cloneDir = externalRoot / std::format("{}-{:016x}", name, key);
|
|
|
|
|
|
|
|
|
|
|
|
{
|
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
|
|
|
|
// One fetch of a clone at a time, as in BuildExternal.
|
|
|
|
|
|
FileLock lock(fs::path(std::format("{}.lock", cloneDir.string())));
|
feat(lint): const-local and constexpr-constant rules
Two rules the AST makes possible, plus the mutation analysis behind them.
const-local reports a local that is never written. It is restricted to SCALARS
— integers, bools, enums, floating types — and that restriction is what makes
the answer exact rather than a guess: a scalar has no member functions, so the
only ways to write one are assignment, ++/--, having its address taken, or
binding to a non-const reference. All four are now tracked in the walk:
- assignment and compound assignment visit their LEFT operand in a write
context, the right one normally;
- ++/-- and & write their operand;
- a call argument is checked against the callee's parameter type, so passing
to `const int&` or by value is a read while `int&` is a write;
- initialising a non-const reference writes what it binds to.
For a class type a non-const method call could mutate it, and deciding that is
the whole-program analysis clang-tidy does, so those are simply out of scope
rather than guessed at.
constexpr-constant promotes a const constant whose initialiser is made only of
literals and operators, so `const int A = 1 << 4;` qualifies and
`const int B = Compute();` does not.
On this repository const-local found 103 candidates, which was too many to be
useful, and the reason was informative: most were range-for bindings and
pointer locals. `for (T* const x : …)` and `T* const p` are not spellings
anybody writes, and the useful constness for a pointer is on the pointee, which
this rule cannot advise on. Excluding both leaves 36, all plain bool or enum
locals worth fixing — isWasm, isPe, exists, writes, isC and so on. Those 36 are
fixed in this commit; the compiler verified every one.
Both rules are report-only. The analysis is exact, but adding const is a
judgement about intent as much as mechanics, and a wrong suggestion should cost
a glance rather than a build. const-local also deliberately does not become a
transform: inserting `const` before a shared type would apply it to every
declarator in a multi-declarator statement, including any that IS written.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-31 00:50:48 +02:00
|
|
|
|
const bool exists = fs::exists(cloneDir);
|
2026-05-19 00:50:06 +02:00
|
|
|
|
Progress::Task task(std::format("{} {}", exists ? "Updating" : "Cloning", name));
|
|
|
|
|
|
if (std::string err = FetchGit(source, cloneDir); !err.empty()) {
|
|
|
|
|
|
throw std::runtime_error(std::format("GitFetch({}): {}", source.url, err));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return cloneDir;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-30 02:20:19 +02:00
|
|
|
|
Configuration* Crafter::LocalProject(const LocalProjectSpec& spec) {
|
|
|
|
|
|
fs::path projectPath = fs::absolute(spec.projectFile).lexically_normal();
|
|
|
|
|
|
if (!fs::exists(projectPath)) {
|
|
|
|
|
|
throw std::runtime_error(std::format("LocalProject: {} not found", projectPath.string()));
|
|
|
|
|
|
}
|
|
|
|
|
|
fs::path canonical = fs::canonical(projectPath);
|
|
|
|
|
|
|
fix: keep host tooling out of the project cache the target uses
ForceHostTooling rewrites a `#pragma crafter dependency` and everything
it loads in place: host target, march native, release, -fPIC. Those are
entries of the project cache like any other, keyed by project file and
args alone. A project that loaded the same sibling as its tool, with
the same args, got the rewritten entry back. That happens whenever the
project gets no args, since host tooling gets none either: a consumer
built for x86-64-v2 then imported a sibling's BMI compiled with
-march=native, and clang refused it. Any arg on the command line split
the keys and hid it.
A thread-local count of pragma loads now marks the tool's load and
every load inside it, its project file's siblings included, and
GitProject and LocalProject put that mark in the key. The clone stays
shared; only the Configuration is separate, as for two arg lists. A
module-internal function rather than a spec field, because the
siblings of a tool are loaded by the tool's own project.cpp, which
cannot know it is host tooling.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 05:10:21 +01:00
|
|
|
|
std::string fullKey = std::format("{}local|{}", LoadingHostTooling() ? "host|" : "", canonical.string());
|
2026-04-30 02:20:19 +02:00
|
|
|
|
for (const std::string& a : spec.args) {
|
|
|
|
|
|
fullKey += '|';
|
|
|
|
|
|
fullKey += a;
|
|
|
|
|
|
}
|
|
|
|
|
|
std::string fullHash = std::format("{:016x}", std::hash<std::string>{}(fullKey));
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
const std::string what = std::format("LocalProject({})", canonical.string());
|
2026-04-30 02:20:19 +02:00
|
|
|
|
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
if (const std::vector<Configuration*>* cached = CachedProject(fullHash)) {
|
|
|
|
|
|
return PickConfiguration(*cached, spec.configuration, what);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fs::path depRoot = canonical.parent_path();
|
|
|
|
|
|
std::vector<std::string_view> argViews(spec.args.begin(), spec.args.end());
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
std::vector<Configuration*> configurations = LoadProjectFromRoot(canonical, depRoot, argViews);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
return PickConfiguration(StoreProject(std::move(fullHash), std::move(configurations), {
|
fix(agents): what the review of dependency notes found
A review of the feature turned up the following, fixed here.
Writing. AGENTS.md was replaced through a temporary renamed over it,
which swaps in another file: a read-only AGENTS.md was rewritten
anyway, a hard link such as a CLAUDE.md beside it kept the old text,
ACLs and ownership were dropped, and without an fsync a power cut could
still leave it empty. The temporary was named after the PID, which
every Flatpak instance shares as PID 2. The file is now written in
place, from the first byte that differs, then truncated and synced,
under an flock on the file itself. A write that fails partway is undone
where the disk allows; with the section last, where it is appended,
only the section can be damaged. A read-only file is opened for writing
only when something would change, so it is refused then and silent
otherwise.
Reading. libc++'s filebuf reports a failed read as the end of the file,
so an I/O error came back as a short file and the section was written
over what was left. Reads go through read(2).
Code fences. ```make``` was taken for a fence, and a fence in a list
item was missed while its indented closer opened one, so markers a user
quoted in a code block could be taken for the section, or the real one
hidden and appended again. Backtick info strings, block quotes and list
items are now followed, and a block ends with its container.
Warnings with nothing to write. With no notes, nothing short of a
well-formed section is reported, so an AGENTS.md that ends in an open
code block, or a project set to None, no longer warns on every build.
An unclosed fence after a section no longer stops it being rewritten
in place.
Labels. The `from` line carried the git URL, credentials and all, or a
path relative to the consumer that changed with the machine, the cache
location and --local. It is now the repository's or the directory's
name. Notes are deduplicated by repository rather than by clone, so one
library pinned two ways is described once, as the nearer spec has it.
The walk. It no longer looks at the project's tests: a plain build
never did, and a test's dependency can point at the Configuration the
project file returned by value. It goes ring by ring over projects
rather than configurations, so what the project names itself comes
first even with the library/executable split. The project's own
AGENTS.consumer.md is excluded by path, also when a dependency's
project file sits beside the project's.
Removing a section dropped a blank line even from between two
paragraphs, joining them; only a section that ends the file takes it
now. A CRLF file gets a CRLF section.
A note was checked on its raw bytes and again, under other whitespace
rules, on the trimmed ones, so it could pass the first check and fail
the merge, which then dropped every note. It is normalised once and
checked on exactly what is merged.
`test --list` only lists, and no longer writes AGENTS.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 05:02:28 +01:00
|
|
|
|
.projectFile = canonical,
|
|
|
|
|
|
.name = depRoot.filename().string(),
|
|
|
|
|
|
.identity = std::format("local|{}", canonical.string()),
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
}), spec.configuration, what);
|
2026-04-30 02:20:19 +02:00
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
std::optional<LoadedProject> Crafter::LoadedProjectOf(const Configuration& cfg) {
|
2026-07-23 01:24:42 +02:00
|
|
|
|
std::lock_guard lock(ProjectCacheMutex);
|
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
|
|
|
|
if (auto it = LoadedProjects.find(&cfg); it != LoadedProjects.end()) return it->second;
|
|
|
|
|
|
return std::nullopt;
|
2026-04-30 02:20:19 +02:00
|
|
|
|
}
|
feat: let a project file return several configurations
A project.cpp described one configuration: CrafterBuildProject returns a
Configuration by value, and anything else the project wanted built had
to be among that one's dependencies. There it was built as part of that
configuration's graph: under the check that a graph builds each module
once, with its libraries handed up to whatever links that configuration,
and with its tests and scripts out of reach of `test` and `run`. Jorijn
asked for a project.cpp that can return several unrelated configurations
which all get built, and suggested a separate entry point, so that no
existing project file breaks.
A project file now defines one of two functions. CrafterBuildProject is
as it was. CrafterBuildConfigurations returns
std::vector<Configuration*>: pointers to configurations the file keeps
alive itself, or that GitProject and LocalProject gave it. The two have
different names because the loader finds the entry point by its C
symbol, which carries no return type, so one name with two return types
would be called as whichever the loader guessed. They are pointers
because a project file takes pointers between its configurations, for
`dependencies` and for a test's, before it returns them, and a vector of
values would move them.
LoadConfigurations loads a project file with either entry point and
returns the list. A CrafterBuildProject's Configuration comes back as a
list of one, constructed by the call where the loader keeps it for the
rest of the process; LoadProjectFromRoot, which did that for a
sibling's, leaves it to LoadConfigurations, and the project cache holds
the lists without owning a Configuration. The Configuration of the
project crafter-build is pointed at is kept that long as well, where it
was a local of Run(). LoadConfigurations throws for a file that defines
both functions or neither, and for a CrafterBuildConfigurations that
returns nothing, a null pointer or one configuration twice. It also
throws for one that returns a configuration a project loaded through
GitProject or LocalProject keeps to itself, which the loader now takes
down when it loads that project's file: what the configurations the file
returned led to through `dependencies` or through their tests, as far as
the first configuration on each way that a loaded project's file had
returned or another loaded project keeps. Returned from here, such a
configuration would count as this file's own to `test` and `run`, and
only the configurations a project file returns are rebased onto its
directory. LoadProject stays, for a caller that wants a
CrafterBuildProject's Configuration by value, and throws for a file with
the other entry point.
GitProject and LocalProject keep, per spec and args, the list a
sibling's file returned, and return the first one unless the spec's new
`configuration` names another by Configuration::name. Every
configuration of the list is rebased onto the sibling's directory,
except one that another project's file had returned before, which was
rebased onto that project's. Specs that differ only in the name they
pick share one load. A name the sibling does not have throws, listing
the names it has, and a name two of its configurations share throws
too. A `#pragma crafter dependency` gets the first.
BuildAll builds the returned configurations in one pass. Each is built
by Build(), as a project's one configuration is, the first on the
calling thread and each other one on a thread of its own, and its result
then goes into the record of the pass under its PcmDir, where Build()
looks for a dependency. One that another of them is built on is built
before that other starts, which then finds it in the record: started
beside it, the other would not find it there yet and would build it a
second time. A configuration is not put into the record before it is
built, because a dependency of its own that is built into the same
directory would be handed its unfinished build and wait for it, while it
waits for the dependency. All of them are built to the end, and the
errors come back in the order given, each message once; an exception a
build throws comes back as an error that names the configuration, where
Run() printed the exception's own text for a project's one
configuration. Refused before anything is built: two that would be built
into one directory, which would be two builds writing the same files at
once; several that are each built on something of another's directory,
so that none could be built first; and one that is built on something of
its own directory when another is built on that directory as well, since
the record holds one result for a directory and the other could be given
either.
One shortcut is in it. A wasm executable that declares wasmVariants
builds what it is built on once more per variant, and says which
variant by rewriting those configurations in place, at the end of its
Build(). A library that two returned configurations share would change
under the one still building its baseline, so with such an executable
anywhere in the graph BuildAll builds the configurations one after the
other, on the calling thread. Keeping them side by side takes a variant
driver that does not rewrite configurations other builds read, which
this commit does not attempt.
Run() works on the list. A build builds all of it. `test` runs the
tests, and `run` offers the scripts, of the ones in it that the project
file made itself. One that another project's file returned to GitProject
or LocalProject, and that this file returns in turn, is built with the
rest, but its tests and scripts stay that project's, so `run` still
reaches only the scripts of the project crafter-build was pointed at.
What the list itself rules out Run() refuses once the project file has
loaded, before any of the list is built and before AGENTS.md is written:
for a build, `-r`, `install` and `bundle` whatever BuildAll refuses a
list for, and for `test`, which builds its tests with Build() and never
comes to BuildAll, two returned configurations of one directory.
BuildAll makes its refusals again for whoever calls it. A script is
handed the configuration it is declared on. `lint` and `format` walk
from every returned configuration and keep, as before, the
configurations in the project's directory: the returned ones first, in
the order the file returned them, then what they depend on, so that of
two returned ones that register a rule under one name the earlier one's
runs. `-r` runs the executable when exactly one of them is one, and
`install` and `bundle` export the one that is packaged as a Flatpak;
with more than one candidate each refuses and names them, `-r` once
everything is built and `install` and `bundle` before anything is.
AGENTS.md takes the notes that the dependencyNotes of each returned
configuration the file made itself selects among what that one is built
against, and the file's pragma tooling and a returned configuration of
another project go by the widest of those settings. There, a
configuration is another project's when GitProject or LocalProject
loaded it from another project file than the one whose AGENTS.md is
written, two files being one when they resolve to one path, so
UpdateAgentsMd still reads the setting of a Configuration one of the two
returned when it is given that Configuration's own project file.
For that, RunTests, RunLint, RunScript and UpdateAgentsMd each gained an
overload that takes the list, and the one that takes a single
Configuration calls it with a list of one. SetParentProject gained one
too, and ParentLib searches the graph of every configuration it was
given. BuildAll, RunTests and RunScript count a configuration the list
names twice once.
The tests of several configurations share what one configuration's had
to itself: AddTest names a test's sources, tests/<name>, and its build
directory after the test and its compile state, not after the
configuration that declares it. Two configurations that each declare a
test of one name, compiled alike, would have RunTests build both in that
one directory, each with the dependencies of its own declaration.
RunTests fails both without building either, and each failure names the
configurations. It compares tests of different configurations only, so
a project of one configuration is treated as it was.
The --help text names the second entry point, says what -r, install and
bundle do with several configurations, and speaks of the project file's
entry point as what gets the project args, where it named
CrafterBuildProject. AGENTS.template.md says that a project.cpp returns
one configuration or several, that Run() works on the list and what a
new verb has to decide about it, which configurations have their path
rebased, and that the scripts of a returned configuration of another
project cannot be run. Two of its notes named LoadProject as what loads
a project.cpp for crafter-build, which Run(), GitProject and
LocalProject no longer call, and speak of the load now. Its rule for the
link flags of a test that loads a project file names the ways a test
loads one, where it named LoadProject, and its entry for `:Script`
speaks of the `scripts` of the configurations the driver is given, where
it named `cfg.scripts`. Its entry for `:Platform` names
LoadConfigurations beside LoadProject. That entry also said that
`:Platform` holds all OS-specific code, which it did not before this
range either, :Agents, :Progress, :Lint and :Clang including POSIX
headers of their own, and no longer says so. The bug-prover lens's
section names BuildAll's threads and LoadConfigurations.
Not in this commit: a way to say which executable -r runs or which app
install and bundle export when there are several, and a keyword that
lets a `#pragma crafter dependency` name a configuration.
2026-11-15 02:16:06 +01:00
|
|
|
|
|
|
|
|
|
|
std::optional<LoadedProject> Crafter::KeptBy(const Configuration& cfg) {
|
|
|
|
|
|
const std::lock_guard lock(ProjectCacheMutex);
|
|
|
|
|
|
if (const auto it = KeptConfigurations.find(&cfg); it != KeptConfigurations.end()) return it->second;
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
}
|