Crafter.Build/interfaces/Crafter.Build-Toolchain.cppm

225 lines
13 KiB
Text
Raw Normal View History

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
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Crafter.Build:Toolchain;
import std;
namespace fs = std::filesystem;
export namespace Crafter {
// The compiler crafter-build drives and what sits next to it, resolved
fix(build): read what a source declares and imports with clang-scan-deps GetInterfacesAndImplementations found the module declarations and the imports of a configuration's sources by searching their text with regular expressions, after deleting the comments that fit on one line. The expressions skipped neither string literals nor comments that span lines, knew nothing of the preprocessor, and wanted one space after `import` and none before its semicolon (#45). An implementation source that held "export module std;" in a string literal was taken for a unit of a module std, and listing it threw "Module std not found not found". An import in a comment that spans lines or under #if 0 was followed. `import X;` and `import X ;` were missed, so their unit had no edge to the module it imports and could be compiled before that module's BMI was written. What a .cppm or .cpp declares and imports now comes from clang-scan-deps -format=p1689, which preprocesses the source with the configuration's C++ compile command, the one Build() compiles every unit of it with: strings, comments, spacing, macros and #if come out as they do for the compiler. GetInterfacesAndImplementations only lists the sources, in the new interfaceSources and implementationSources. Build() reads them (ReadSources) once the configuration's dependencies and external dependencies are built: the command takes their include paths, and a source may include headers of an external dependency, which are not there before it is fetched. From what it read, Build() makes the configuration's modules and units, its `interfaces` and `implementations`, and places each import on a module of the configuration or of what it is built on, whose own Build() has read its sources by then. It makes those of its own configuration alone, as the reset of the units' state did before it. A build pass builds a directory once, for whichever configuration of it asks first, and the loader can make two configurations of one directory: one project loaded along two paths with its args in two orders, which it keeps apart and VariantId, sorting the args, does not. Only the one that was built has the modules that build read, so the result of a build now names the configuration it ran on (BuildResult::built), and a dependency's modules are looked up through the pass's record of its directory. 6.4.1 had every configuration's modules from the listing and took such a graph for one with two builds of a module, which it refused; it is now built, once, and the units of both sides have their edges. A scan is kept in the build directory as an object is, in scans/ or, for a source outside cfg.path, in scans-outside/, as JSON of the command it was taken with and of what clang-scan-deps wrote, with the dependency file clang-scan-deps wrote beside it, which lists the source and every file it included. A build scans a source again unless its scan is newer than every file that dependency file lists, was taken with the same command and can be read, so a build with nothing changed runs no clang-scan-deps. Both files are written beside their places and renamed into them, as the archive and the list of objects are, for another crafter-build that may be building the same clone. A configuration's modules are known only once its build has read its sources, so the refusals of a module that two configurations of the graph build (DuplicateModuleError, #41) and of interface units that import each other (ImportCycleError) now come there: once the dependencies are built, before any .cppm or .cpp of the configuration is compiled. They came before the configuration made a directory or built a dependency. The contributor guide names clang-scan-deps among the prerequisites and among what :Toolchain resolves, has a test look at the modules of a configuration only after building it, and has the gotcha for the new order. ResolvePendingImports and the pendingImports of the unit classes go. They placed the imports that a scan at listing time could not, once the dependencies were wired up, and with the imports placed when the dependencies are built there is nothing pending. The tests that looked at a configuration's modules and units before building now look after it (DependencyLink, ModuleInterface, StaticLib, ConcurrentDependencyReset and the disabled TransitiveInterfaceChange), IncrementalInterfaceChange checks the edge that the build of a consumer gives it when its dependency was assigned after its sources were listed, and ImportCycle and DuplicateModule check that the refused configuration compiled nothing of its own. The workarounds for the old scanner are not needed: MingwSysroot writes its stand-in std module as a plain literal again, JobLimit writes the declarations of the sources it generates as plain literals, and Lint's comment on its fixture file no longer gives the scanner as the reason for it. The messages of the regex code stay where they still apply. The one for a source that declares a unit of a module the configuration does not have loses its doubled "not found", and applies to an implementation source that declares one, such as an implementation partition (`module X:P;`). An implementation unit written `module X;` declares no unit for clang-scan-deps but imports X, and an import needs no module of the configuration: the compile reports a module no one builds. A .cppm that declares an implementation partition is built as a partition of its module, where it was refused as declaring no module. The Toolchain gains clangScanDeps, resolved as llvm-ar is: in the bin/ of the LLVM prefix, else by name on PATH. The Flatpak has /app/bin/clang-scan-deps. Fixes #45
2026-11-27 09:25:53 +01:00
// once per process by GetToolchain(). Every clang++, clang, llvm-ar and
// clang-scan-deps the tool spawns, the libclang the linter dlopens, the
// std module source and the default sysroots come from here, so a
// toolchain installed anywhere other than /usr (the Flatpak carries its
// own under /app) needs no per-call-site knowledge.
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
struct Toolchain {
// LLVM install prefix. Empty when the tools are bare names on PATH.
fs::path prefix;
fs::path clangxx;
fs::path clang;
fs::path llvmAr;
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
// What a packaged program's shared libraries are read with.
fs::path llvmReadelf;
fix(build): read what a source declares and imports with clang-scan-deps GetInterfacesAndImplementations found the module declarations and the imports of a configuration's sources by searching their text with regular expressions, after deleting the comments that fit on one line. The expressions skipped neither string literals nor comments that span lines, knew nothing of the preprocessor, and wanted one space after `import` and none before its semicolon (#45). An implementation source that held "export module std;" in a string literal was taken for a unit of a module std, and listing it threw "Module std not found not found". An import in a comment that spans lines or under #if 0 was followed. `import X;` and `import X ;` were missed, so their unit had no edge to the module it imports and could be compiled before that module's BMI was written. What a .cppm or .cpp declares and imports now comes from clang-scan-deps -format=p1689, which preprocesses the source with the configuration's C++ compile command, the one Build() compiles every unit of it with: strings, comments, spacing, macros and #if come out as they do for the compiler. GetInterfacesAndImplementations only lists the sources, in the new interfaceSources and implementationSources. Build() reads them (ReadSources) once the configuration's dependencies and external dependencies are built: the command takes their include paths, and a source may include headers of an external dependency, which are not there before it is fetched. From what it read, Build() makes the configuration's modules and units, its `interfaces` and `implementations`, and places each import on a module of the configuration or of what it is built on, whose own Build() has read its sources by then. It makes those of its own configuration alone, as the reset of the units' state did before it. A build pass builds a directory once, for whichever configuration of it asks first, and the loader can make two configurations of one directory: one project loaded along two paths with its args in two orders, which it keeps apart and VariantId, sorting the args, does not. Only the one that was built has the modules that build read, so the result of a build now names the configuration it ran on (BuildResult::built), and a dependency's modules are looked up through the pass's record of its directory. 6.4.1 had every configuration's modules from the listing and took such a graph for one with two builds of a module, which it refused; it is now built, once, and the units of both sides have their edges. A scan is kept in the build directory as an object is, in scans/ or, for a source outside cfg.path, in scans-outside/, as JSON of the command it was taken with and of what clang-scan-deps wrote, with the dependency file clang-scan-deps wrote beside it, which lists the source and every file it included. A build scans a source again unless its scan is newer than every file that dependency file lists, was taken with the same command and can be read, so a build with nothing changed runs no clang-scan-deps. Both files are written beside their places and renamed into them, as the archive and the list of objects are, for another crafter-build that may be building the same clone. A configuration's modules are known only once its build has read its sources, so the refusals of a module that two configurations of the graph build (DuplicateModuleError, #41) and of interface units that import each other (ImportCycleError) now come there: once the dependencies are built, before any .cppm or .cpp of the configuration is compiled. They came before the configuration made a directory or built a dependency. The contributor guide names clang-scan-deps among the prerequisites and among what :Toolchain resolves, has a test look at the modules of a configuration only after building it, and has the gotcha for the new order. ResolvePendingImports and the pendingImports of the unit classes go. They placed the imports that a scan at listing time could not, once the dependencies were wired up, and with the imports placed when the dependencies are built there is nothing pending. The tests that looked at a configuration's modules and units before building now look after it (DependencyLink, ModuleInterface, StaticLib, ConcurrentDependencyReset and the disabled TransitiveInterfaceChange), IncrementalInterfaceChange checks the edge that the build of a consumer gives it when its dependency was assigned after its sources were listed, and ImportCycle and DuplicateModule check that the refused configuration compiled nothing of its own. The workarounds for the old scanner are not needed: MingwSysroot writes its stand-in std module as a plain literal again, JobLimit writes the declarations of the sources it generates as plain literals, and Lint's comment on its fixture file no longer gives the scanner as the reason for it. The messages of the regex code stay where they still apply. The one for a source that declares a unit of a module the configuration does not have loses its doubled "not found", and applies to an implementation source that declares one, such as an implementation partition (`module X:P;`). An implementation unit written `module X;` declares no unit for clang-scan-deps but imports X, and an import needs no module of the configuration: the compile reports a module no one builds. A .cppm that declares an implementation partition is built as a partition of its module, where it was refused as declaring no module. The Toolchain gains clangScanDeps, resolved as llvm-ar is: in the bin/ of the LLVM prefix, else by name on PATH. The Flatpak has /app/bin/clang-scan-deps. Fixes #45
2026-11-27 09:25:53 +01:00
// What reads the module a C++ source declares and the modules it
// imports, by preprocessing it with its compile command (Build).
fs::path clangScanDeps;
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
// Where clang-c/Index.h lives when it is not on the default include
// path; empty otherwise.
fs::path llvmIncludeDir;
// The exact libclang to dlopen; nullopt means search the usual names.
std::optional<fs::path> libclang;
// A libc++ install other than the compiler's own
// (CRAFTER_BUILD_LIBCXX_DIR); empty means clang finds its own.
fs::path libcxxDir;
// libc++'s std module source for host builds.
fs::path stdCppm;
fix(sysroot): take the std module source from the sysroot's libc++ release A cross build against a sysroot whose libc++ differs from the toolchain's failed while precompiling the std module, with a page of "no member named 'runtime_format' in namespace 'std'". The module source is a list of using-declarations for what one libc++ release declares, so it only compiles against that release's headers. BuildStdPcm wants the sysroot's own <sysroot>/usr/share/libc++/v1/std.cppm, but Alpine packages the headers without it, and the fallback was the toolchain's copy whatever its release. That held while the compiler came from the same distro as the sysroot; with the Flatpak's libc++ 22.1.8 and Alpine edge on 23.1.2 it no longer does. The release is now read from _LIBCPP_VERSION in the sysroot's and the toolchain's <__config>, and SysrootStdModule picks in this order: the sysroot's own source, the toolchain's when both are the same major release (a release branch only takes fixes), the copy crafter-build ships for that release under share/crafter-build/libc++-modules/<major>. When none fits the build stops with one line naming both releases and the directory the matching source belongs in, before clang is run. If either release cannot be read the toolchain's source is tried as before, since there is nothing to compare. Matching sources live in crafter-build's own share directory rather than the LLVM prefix: they are data this tool ships for sysroots, not part of any one compiler install, and "sources ship" already describes that directory. `--version` prints the toolchain's libc++ release and the releases sources are shipped for, the first thing to look at when such a build fails. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-03 16:37:00 +02:00
// The _LIBCPP_VERSION of the libc++ stdCppm belongs to (220108 for
// 22.1.8); 0 when its <__config> could not be read.
std::int32_t libcxxVersion = 0;
// Std module sources for libc++ releases other than the toolchain's
// own, one <major>/std.cppm each, for sysroots that carry libc++
// without them: <crafter prefix>/share/crafter-build/libc++-modules.
// Empty when the crafter prefix is unknown; need not exist.
fs::path stdModulesDir;
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
fs::path wasiSysroot;
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 mingw-w64 install prefix, the directory that holds
// x86_64-w64-mingw32/ and lib/gcc/x86_64-w64-mingw32/ (/usr for a
fix(mingw): view only a prefix that holds a Linux system The first fix showed clang every mingw prefix through a view of its mingw-w64 parts. That broke a prefix that holds mingw-w64 alone, where Windows libraries installed with --prefix land in include/ and lib/: with CRAFTER_MINGW_DIR=/opt/mingw, <SDL2/SDL.h> and -lSDL2 were no longer found. Such a prefix is clang's sysroot whole again. Only a prefix that also holds a Linux system gets the view (Toolchain::mingwPrefixIsSystem): the host's /usr inside the Flatpak, whatever its include/ holds, and a prefix whose include/ has a C library's features.h, which every glibc and musl header includes and mingw-w64 has no use for, as CRAFTER_MINGW_DIR=/usr has. MakeMingwSysroot makes the view in the cache, or in $XDG_RUNTIME_DIR/crafter.build when the cache's filesystem takes no symbolic links (vfat, exFAT, CIFS without unix extensions): the XDG spec promises them there, and nothing else in the cache needs them. Its path is absolute, because CMake runs the compiler from directories of its own and a relative cache did not resolve from there. The prefix is resolved once, absolute and lexically normal, so /opt/mingw/ and /opt/mingw are one prefix and not two builds. clang names a header by the path it found it at, so every diagnostic from a viewed mingw-w64 header named a hashed cache directory. RunBuildCommand now writes paths into the view as paths into the prefix, as BuildStdPcm did for its manifest messages already. Also from the review of PR #44: SysrootCompileFlags builds a mingw command, which can make a view, so it redirects the cache like the other tests; the manifest filter's comment names what it still keeps out; the C path asks MingwSysroot() once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:58:30 +01:00
// distro package), absolute and lexically normal. Empty means clang's
// own discovery, which follows the mingw gcc on PATH. Set by
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
// CRAFTER_MINGW_DIR, else the host's /usr when running sandboxed and
fix(mingw): view only a prefix that holds a Linux system The first fix showed clang every mingw prefix through a view of its mingw-w64 parts. That broke a prefix that holds mingw-w64 alone, where Windows libraries installed with --prefix land in include/ and lib/: with CRAFTER_MINGW_DIR=/opt/mingw, <SDL2/SDL.h> and -lSDL2 were no longer found. Such a prefix is clang's sysroot whole again. Only a prefix that also holds a Linux system gets the view (Toolchain::mingwPrefixIsSystem): the host's /usr inside the Flatpak, whatever its include/ holds, and a prefix whose include/ has a C library's features.h, which every glibc and musl header includes and mingw-w64 has no use for, as CRAFTER_MINGW_DIR=/usr has. MakeMingwSysroot makes the view in the cache, or in $XDG_RUNTIME_DIR/crafter.build when the cache's filesystem takes no symbolic links (vfat, exFAT, CIFS without unix extensions): the XDG spec promises them there, and nothing else in the cache needs them. Its path is absolute, because CMake runs the compiler from directories of its own and a relative cache did not resolve from there. The prefix is resolved once, absolute and lexically normal, so /opt/mingw/ and /opt/mingw are one prefix and not two builds. clang names a header by the path it found it at, so every diagnostic from a viewed mingw-w64 header named a hashed cache directory. RunBuildCommand now writes paths into the view as paths into the prefix, as BuildStdPcm did for its manifest messages already. Also from the review of PR #44: SysrootCompileFlags builds a mingw command, which can make a view, so it redirects the cache like the other tests; the manifest filter's comment names what it still keeps out; the C path asks MingwSysroot() once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:58:30 +01:00
// it has mingw-w64 (the sandbox's own /usr never does). What the
// mingw target passes as --sysroot is MingwSysroot(), not this:
// see mingwPrefixIsSystem.
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
fs::path mingwPrefix;
fix(mingw): view only a prefix that holds a Linux system The first fix showed clang every mingw prefix through a view of its mingw-w64 parts. That broke a prefix that holds mingw-w64 alone, where Windows libraries installed with --prefix land in include/ and lib/: with CRAFTER_MINGW_DIR=/opt/mingw, <SDL2/SDL.h> and -lSDL2 were no longer found. Such a prefix is clang's sysroot whole again. Only a prefix that also holds a Linux system gets the view (Toolchain::mingwPrefixIsSystem): the host's /usr inside the Flatpak, whatever its include/ holds, and a prefix whose include/ has a C library's features.h, which every glibc and musl header includes and mingw-w64 has no use for, as CRAFTER_MINGW_DIR=/usr has. MakeMingwSysroot makes the view in the cache, or in $XDG_RUNTIME_DIR/crafter.build when the cache's filesystem takes no symbolic links (vfat, exFAT, CIFS without unix extensions): the XDG spec promises them there, and nothing else in the cache needs them. Its path is absolute, because CMake runs the compiler from directories of its own and a relative cache did not resolve from there. The prefix is resolved once, absolute and lexically normal, so /opt/mingw/ and /opt/mingw are one prefix and not two builds. clang names a header by the path it found it at, so every diagnostic from a viewed mingw-w64 header named a hashed cache directory. RunBuildCommand now writes paths into the view as paths into the prefix, as BuildStdPcm did for its manifest messages already. Also from the review of PR #44: SysrootCompileFlags builds a mingw command, which can make a view, so it redirects the cache like the other tests; the manifest filter's comment names what it still keeps out; the C path asks MingwSysroot() once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:58:30 +01:00
// The prefix holds a Linux system as well as mingw-w64: the host's
// /usr in the sandbox, or a prefix whose include/ has a C library's
// features.h, as /usr has. clang searches a mingw sysroot's include/
// and lib/, so such a prefix is shown to it only through a view of
// its mingw-w64 parts; any other prefix is the sysroot itself, and
// Windows libraries installed into its include/ and lib/ are found.
bool mingwPrefixIsSystem = false;
fix(cuda): look for nvcc instead of leaving it to PATH cfg.cuda compiled with a bare "nvcc", which the shell looked up on PATH. In crafter-build's Flatpak PATH is /app/bin:/usr/bin, as its manifest sets it, which never holds the host's toolkit, so with it every build with CUDA sources stopped at "sh: line 1: nvcc: command not found", although the sandbox sees /opt/cuda through --filesystem=host. ResolveToolchain now finds nvcc as it finds clang++: CUDA_PATH, which is exclusive as CRAFTER_BUILD_LLVM_DIR is, else /opt/cuda (Arch's package) or /usr/local/cuda (NVIDIA's installer and packages), else the absolute entries of PATH, which it searches itself so that a build without a toolkit can say where it looked. A relative CUDA_PATH is made absolute there, once, as CRAFTER_MINGW_DIR is, since nvcc runs later from whatever working directory a build is in. The sandbox shows the host's /usr and /etc under /run/host, with its own runtime at /usr, and NVIDIA's /usr/local/cuda is a link, to /usr/local/cuda-<version> or through /etc/alternatives. A link to an absolute path names a path of the host, /opt/cuda pointing at /usr/local/cuda-<version> too, and the sandbox would look it up in its own root, so where the path of a toolkit, CUDA_PATH, /opt/cuda or /usr/local/cuda, is such a link, HostPath follows it, and the link its target is in turn, each taken as the host's; a link partway along that path, or inside the toolkit, is the kernel's to resolve, in the sandbox's root. A missing toolkit is reported by the build that has a .cu to compile and not by GetToolchain(), so no other build fails for want of one. crafter-build --version prints the nvcc it found, whether or not the compiler could be resolved.
2026-11-11 19:34:52 +01:00
// The nvcc that compiles cfg.cuda: <CUDA_PATH>/bin/nvcc when CUDA_PATH
// is set, else bin/nvcc of the first toolkit that has one among
// ToolchainInputs::cudaRoots, else the first nvcc in an absolute entry
// of PATH. In a sandbox, a toolkit is looked up as the host has it:
// under hostRoot where it is in the host's /usr or /etc, and, where
// its path is a link, through that link and the link its target is in
// turn, each taken as the host's, wherever they point. Empty when
// there is none, and nvccError says where it was looked for; only a
// build with a .cu to compile reports that, so no other build fails
// for want of a CUDA toolkit.
fs::path nvcc;
std::string nvccError;
feat(cuda): make the GPU architecture configurable, native by default nvcc ran with -arch=sm_89 for every build, which is code for that one architecture and its PTX, whatever GPU the program was for. Jorijn asked for the architecture to be configurable, and native when nothing sets it, as the CPU's is. cfg.cudaArch is nvcc's -arch now, and it defaults to "native": nvcc compiles for the GPUs it sees, and where it sees none it warns and uses its own default architecture. Like -march=native it is for a program that runs where it is built, since it carries no PTX, and `crafter-build bundle` warns of a bundle whose CUDA code, in the program or a library it is built on, is compiled for native, as it warns of -march=native. ApplyStandardArgs sets it from --cuda-arch= and CRAFTER_BUILD_CUDA_ARCH as it sets march from --march= and CRAFTER_BUILD_MARCH; AddTest and AddMarchVariants give their tests the parent's, as they give them its sysroot and debug flag; and ForceHostTooling gives host tooling the host's, as it gives it the host's march, since project.so runs it on the machine that loads it. A .cu is compiled again only when it is newer than its object, so the architecture keys VariantId, and so does the nvcc that compiles it, by what it is rather than where: Toolchain::nvccStamp, its canonical path, size and time, read without a process, changes when CUDA_PATH names another toolkit and when an update replaces the one at the same path, as a package does at /opt/cuda. native is keyed as well, by Toolchain::cudaNativeKey: the NVIDIA display devices sysfs lists, by PCI address and device ID, and CUDA_VISIBLE_DEVICES and CUDA_DEVICE_ORDER, which choose and number them, each empty value apart from an unset one, read without a process. It is crafter-build's reading of the machine, not nvcc's. The word alone would keep an object compiled for a GPU the machine no longer has, after a GPU change or on another machine that shares the checkout, and that object carries no PTX for the GPU it has now, where sm_89's carried its PTX. Only a configuration with CUDA sources is keyed, so every other one keeps the directory it had, but for one built with --cuda-arch=, which was a project argument, hashed as one, and is crafter-build's own now.
2026-11-11 19:34:52 +01:00
// What that nvcc is, for VariantId: its canonical path, size and
// modification time, which change when the toolkit is updated or
// replaced at the same path, as the path alone does not. Empty
// without an nvcc.
std::string nvccStamp;
// What -arch=native compiles for on this machine, for VariantId: the
// NVIDIA display devices the PCI bus lists, by address and device ID,
// and CUDA_VISIBLE_DEVICES and CUDA_DEVICE_ORDER, which choose among
// them and number them, each unset apart from empty. Empty without an
// nvcc.
std::string cudaNativeKey;
feat(cuda): link the CUDA runtime of the toolkit that compiles the .cu A program with CUDA sources needs the CUDA runtime, which cfg.linkFlags had to name: -L/opt/cuda/lib64 -lcudart for Arch's toolkit, a path into it. In the Flatpak that holds for /opt/cuda but not for the host's /usr/local/cuda, which is under /run/host there, at a path crafter-build resolves for nvcc and a project.cpp does not know. Jorijn chose to have crafter-build link it. A configuration with CUDA sources links the static runtime of the toolkit whose nvcc compiles them, by its path, with the -lrt -lpthread -ldl that nvcc's own link line puts after it. ResolveToolchain finds it with nvcc, as Toolchain::cudaRuntime: libcudart_static.a in the lib64 beside nvcc's bin, looked for without starting a process, so a test can stage a toolkit for it as for nvcc, and crafter-build --version prints it. The static one, so no run path into the toolkit ends up in the program; libcuda.so.1, which the runtime loads, comes with the driver. By its path, not through a -L of the lib64, which would put the toolkit's libraries, such as Arch's libcheckpoint.so, in the way of a project's own of the same name. It goes into BuildResult::runtimeLibs, which a configuration hands its consumers as it does libs and every link puts after them, so whatever is built on a library with CUDA sources links the runtime too, and a -lcudart a project names itself comes first. Where that lib64 holds none, as where a distribution keeps the toolkit's libraries in its own directories, cudaRuntime is empty and nothing is linked, as before: a -lcudart_static the linker could not find would fail the link even of a project that names its own -lcudart. The archive is looked for without throwing, so a lib64 that cannot be looked into, through a link loop or for want of permission, counts as one without it.
2026-11-11 19:34:52 +01:00
// The static CUDA runtime a configuration with CUDA sources links:
// libcudart_static.a in the lib64 beside nvcc's bin. Empty without an
// nvcc, and where that lib64 holds none, as where a distribution keeps
// the toolkit's libraries in its own directories, or cannot be looked
// into: then nothing is linked, and cfg.linkFlags names the runtime.
fs::path cudaRuntime;
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
// The Flatpak runtime crafter-build runs on, from the
// runtime=runtime/<id>/<arch>/<branch> line of /.flatpak-info:
// "x86_64" and "26.08" in the Flatpak, both empty outside one. A
// program built here links that runtime's glibc, so an executable is
// only packaged as a Flatpak when they are set, and for that branch.
// CRAFTER_BUILD_FLATPAK_INFO names another file to read them from,
// for tests that package outside the Flatpak.
std::string flatpakArch;
std::string flatpakBranch;
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
// `clang++ -print-target-triple` and the first line of
// `clang++ --version`; both empty when clang++ could not be run.
std::string hostTriple;
std::string clangVersion;
// Why clang++ could not be resolved or run; empty when it could.
std::string error;
// Flags for compiling against libcxxDir; empty without one.
std::string LibcxxCompileFlags() const;
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
// Where libc++.so.1 is when clang would not find it itself: an
// explicit libcxxDir's lib, or <prefix>/lib of a toolchain outside
// /usr, /app/lib in crafter-build's Flatpak, which holds the rest of
// its LLVM as well. Empty for a toolchain in /usr, whose libraries
// are on the linker's and the loader's default paths.
fs::path LibcxxLibDir() const;
// Flags for linking against the libc++ the compiler will use: a -L
// and an rpath for <prefix>/lib when the prefix is not the system one
// (clang searches only its per-target runtime directory and the
// system paths, and a bundled toolchain's libc++.so.1 is on neither
// the linker's nor the loader's default path), or for an explicit
// libcxxDir.
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 LibcxxLinkFlags() const;
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
// LibcxxLinkFlags without the rpath: for a program that finds its
// copy of libc++ somewhere else at run time, as a Flatpak does.
std::string LibcxxSearchFlags() const;
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
// Names this toolchain for cache directory names: the clang version
// followed by a hash of what decides which headers and libraries a
// PCM is built against. Two toolchains with different keys never
// share a PCM.
std::string Key() const;
};
// What ResolveToolchain reads, so a test can feed it a staged layout.
struct ToolchainInputs {
fix(cuda): look for nvcc instead of leaving it to PATH cfg.cuda compiled with a bare "nvcc", which the shell looked up on PATH. In crafter-build's Flatpak PATH is /app/bin:/usr/bin, as its manifest sets it, which never holds the host's toolkit, so with it every build with CUDA sources stopped at "sh: line 1: nvcc: command not found", although the sandbox sees /opt/cuda through --filesystem=host. ResolveToolchain now finds nvcc as it finds clang++: CUDA_PATH, which is exclusive as CRAFTER_BUILD_LLVM_DIR is, else /opt/cuda (Arch's package) or /usr/local/cuda (NVIDIA's installer and packages), else the absolute entries of PATH, which it searches itself so that a build without a toolkit can say where it looked. A relative CUDA_PATH is made absolute there, once, as CRAFTER_MINGW_DIR is, since nvcc runs later from whatever working directory a build is in. The sandbox shows the host's /usr and /etc under /run/host, with its own runtime at /usr, and NVIDIA's /usr/local/cuda is a link, to /usr/local/cuda-<version> or through /etc/alternatives. A link to an absolute path names a path of the host, /opt/cuda pointing at /usr/local/cuda-<version> too, and the sandbox would look it up in its own root, so where the path of a toolkit, CUDA_PATH, /opt/cuda or /usr/local/cuda, is such a link, HostPath follows it, and the link its target is in turn, each taken as the host's; a link partway along that path, or inside the toolkit, is the kernel's to resolve, in the sandbox's root. A missing toolkit is reported by the build that has a .cu to compile and not by GetToolchain(), so no other build fails for want of one. crafter-build --version prints the nvcc it found, whether or not the compiler could be resolved.
2026-11-11 19:34:52 +01:00
// The CRAFTER_* variables, CUDA_PATH and PATH, present only when set
// and non-empty.
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::map<std::string, std::string, std::less<>> env;
// The <prefix> of <prefix>/share/crafter-build; empty when unknown.
fs::path crafterPrefix;
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
// Where the host's root shows inside a sandbox (/run/host in a
// Flatpak); empty outside one.
fs::path hostRoot;
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
// What /.flatpak-info holds, or the file CRAFTER_BUILD_FLATPAK_INFO
// names; empty outside a Flatpak.
std::string flatpakInfo;
fix(cuda): look for nvcc instead of leaving it to PATH cfg.cuda compiled with a bare "nvcc", which the shell looked up on PATH. In crafter-build's Flatpak PATH is /app/bin:/usr/bin, as its manifest sets it, which never holds the host's toolkit, so with it every build with CUDA sources stopped at "sh: line 1: nvcc: command not found", although the sandbox sees /opt/cuda through --filesystem=host. ResolveToolchain now finds nvcc as it finds clang++: CUDA_PATH, which is exclusive as CRAFTER_BUILD_LLVM_DIR is, else /opt/cuda (Arch's package) or /usr/local/cuda (NVIDIA's installer and packages), else the absolute entries of PATH, which it searches itself so that a build without a toolkit can say where it looked. A relative CUDA_PATH is made absolute there, once, as CRAFTER_MINGW_DIR is, since nvcc runs later from whatever working directory a build is in. The sandbox shows the host's /usr and /etc under /run/host, with its own runtime at /usr, and NVIDIA's /usr/local/cuda is a link, to /usr/local/cuda-<version> or through /etc/alternatives. A link to an absolute path names a path of the host, /opt/cuda pointing at /usr/local/cuda-<version> too, and the sandbox would look it up in its own root, so where the path of a toolkit, CUDA_PATH, /opt/cuda or /usr/local/cuda, is such a link, HostPath follows it, and the link its target is in turn, each taken as the host's; a link partway along that path, or inside the toolkit, is the kernel's to resolve, in the sandbox's root. A missing toolkit is reported by the build that has a .cu to compile and not by GetToolchain(), so no other build fails for want of one. crafter-build --version prints the nvcc it found, whether or not the compiler could be resolved.
2026-11-11 19:34:52 +01:00
// Where a CUDA toolkit is installed when CUDA_PATH names none, in the
// order they are tried and as the host names them: GetToolchain()
// passes /opt/cuda, Arch's, and /usr/local/cuda, NVIDIA's installers'.
std::vector<fs::path> cudaRoots;
feat(cuda): make the GPU architecture configurable, native by default nvcc ran with -arch=sm_89 for every build, which is code for that one architecture and its PTX, whatever GPU the program was for. Jorijn asked for the architecture to be configurable, and native when nothing sets it, as the CPU's is. cfg.cudaArch is nvcc's -arch now, and it defaults to "native": nvcc compiles for the GPUs it sees, and where it sees none it warns and uses its own default architecture. Like -march=native it is for a program that runs where it is built, since it carries no PTX, and `crafter-build bundle` warns of a bundle whose CUDA code, in the program or a library it is built on, is compiled for native, as it warns of -march=native. ApplyStandardArgs sets it from --cuda-arch= and CRAFTER_BUILD_CUDA_ARCH as it sets march from --march= and CRAFTER_BUILD_MARCH; AddTest and AddMarchVariants give their tests the parent's, as they give them its sysroot and debug flag; and ForceHostTooling gives host tooling the host's, as it gives it the host's march, since project.so runs it on the machine that loads it. A .cu is compiled again only when it is newer than its object, so the architecture keys VariantId, and so does the nvcc that compiles it, by what it is rather than where: Toolchain::nvccStamp, its canonical path, size and time, read without a process, changes when CUDA_PATH names another toolkit and when an update replaces the one at the same path, as a package does at /opt/cuda. native is keyed as well, by Toolchain::cudaNativeKey: the NVIDIA display devices sysfs lists, by PCI address and device ID, and CUDA_VISIBLE_DEVICES and CUDA_DEVICE_ORDER, which choose and number them, each empty value apart from an unset one, read without a process. It is crafter-build's reading of the machine, not nvcc's. The word alone would keep an object compiled for a GPU the machine no longer has, after a GPU change or on another machine that shares the checkout, and that object carries no PTX for the GPU it has now, where sm_89's carried its PTX. Only a configuration with CUDA sources is keyed, so every other one keeps the directory it had, but for one built with --cuda-arch=, which was a project argument, hashed as one, and is crafter-build's own now.
2026-11-11 19:34:52 +01:00
// The PCI devices sysfs lists, one directory each with its vendor,
// device and class: GetToolchain() passes /sys/bus/pci/devices, which
// the sandbox shows too. What -arch=native compiles for is keyed by
// the NVIDIA display devices among them.
fs::path pciDevices;
// CUDA_VISIBLE_DEVICES, which chooses the GPUs -arch=native compiles
// for, when it is set: set but empty hides them all, which is not the
// same as unset, so it is kept apart from env, which holds non-empty
// values alone.
std::optional<std::string> cudaVisibleDevices;
// CUDA_DEVICE_ORDER, when it is set: it decides which GPU a number in
// CUDA_VISIBLE_DEVICES means, by PCI address or by speed.
std::optional<std::string> cudaDeviceOrder;
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
};
// Pure path resolution: an env override wins, then a toolchain installed
// beside crafter-build (<crafterPrefix>/bin/clang++), then bare names on
// PATH. Never runs a process, so hostTriple and clangVersion stay empty.
fix(cuda): look for nvcc instead of leaving it to PATH cfg.cuda compiled with a bare "nvcc", which the shell looked up on PATH. In crafter-build's Flatpak PATH is /app/bin:/usr/bin, as its manifest sets it, which never holds the host's toolkit, so with it every build with CUDA sources stopped at "sh: line 1: nvcc: command not found", although the sandbox sees /opt/cuda through --filesystem=host. ResolveToolchain now finds nvcc as it finds clang++: CUDA_PATH, which is exclusive as CRAFTER_BUILD_LLVM_DIR is, else /opt/cuda (Arch's package) or /usr/local/cuda (NVIDIA's installer and packages), else the absolute entries of PATH, which it searches itself so that a build without a toolkit can say where it looked. A relative CUDA_PATH is made absolute there, once, as CRAFTER_MINGW_DIR is, since nvcc runs later from whatever working directory a build is in. The sandbox shows the host's /usr and /etc under /run/host, with its own runtime at /usr, and NVIDIA's /usr/local/cuda is a link, to /usr/local/cuda-<version> or through /etc/alternatives. A link to an absolute path names a path of the host, /opt/cuda pointing at /usr/local/cuda-<version> too, and the sandbox would look it up in its own root, so where the path of a toolkit, CUDA_PATH, /opt/cuda or /usr/local/cuda, is such a link, HostPath follows it, and the link its target is in turn, each taken as the host's; a link partway along that path, or inside the toolkit, is the kernel's to resolve, in the sandbox's root. A missing toolkit is reported by the build that has a .cu to compile and not by GetToolchain(), so no other build fails for want of one. crafter-build --version prints the nvcc it found, whether or not the compiler could be resolved.
2026-11-11 19:34:52 +01:00
// nvcc is not left to the shell's PATH lookup but searched for here,
// PATH included, so a build that cannot find one can say where it looked.
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
Toolchain ResolveToolchain(const ToolchainInputs& inputs);
// ResolveToolchain over the real environment plus the two clang probes,
// computed once and cached. Never throws.
const Toolchain& GetToolchain();
// GetToolchain(), or a std::runtime_error carrying its error.
const Toolchain& RequireToolchain();
fix(mingw): view only a prefix that holds a Linux system The first fix showed clang every mingw prefix through a view of its mingw-w64 parts. That broke a prefix that holds mingw-w64 alone, where Windows libraries installed with --prefix land in include/ and lib/: with CRAFTER_MINGW_DIR=/opt/mingw, <SDL2/SDL.h> and -lSDL2 were no longer found. Such a prefix is clang's sysroot whole again. Only a prefix that also holds a Linux system gets the view (Toolchain::mingwPrefixIsSystem): the host's /usr inside the Flatpak, whatever its include/ holds, and a prefix whose include/ has a C library's features.h, which every glibc and musl header includes and mingw-w64 has no use for, as CRAFTER_MINGW_DIR=/usr has. MakeMingwSysroot makes the view in the cache, or in $XDG_RUNTIME_DIR/crafter.build when the cache's filesystem takes no symbolic links (vfat, exFAT, CIFS without unix extensions): the XDG spec promises them there, and nothing else in the cache needs them. Its path is absolute, because CMake runs the compiler from directories of its own and a relative cache did not resolve from there. The prefix is resolved once, absolute and lexically normal, so /opt/mingw/ and /opt/mingw are one prefix and not two builds. clang names a header by the path it found it at, so every diagnostic from a viewed mingw-w64 header named a hashed cache directory. RunBuildCommand now writes paths into the view as paths into the prefix, as BuildStdPcm did for its manifest messages already. Also from the review of PR #44: SysrootCompileFlags builds a mingw command, which can make a view, so it redirects the cache like the other tests; the manifest filter's comment names what it still keeps out; the C path asks MingwSysroot() once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:58:30 +01:00
// Makes, in the first of `parents` that can hold one, a directory that
// shows clang only the mingw-w64 parts of `prefix`: links named
// x86_64-w64-mingw32, lib/gcc and lib64/gcc to the same paths under
// `prefix`, at <parent>/mingw-sysroot/<hash of prefix>, and returns it.
// A view already there is reused; one another process makes at the same
// moment is as good as one made here. Throws when no parent can hold
// one, with the reason for each.
fs::path MakeMingwSysroot(const fs::path& prefix, std::span<const fs::path> parents);
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
// The --sysroot of every compile, link and CMake configure for the mingw
fix(mingw): view only a prefix that holds a Linux system The first fix showed clang every mingw prefix through a view of its mingw-w64 parts. That broke a prefix that holds mingw-w64 alone, where Windows libraries installed with --prefix land in include/ and lib/: with CRAFTER_MINGW_DIR=/opt/mingw, <SDL2/SDL.h> and -lSDL2 were no longer found. Such a prefix is clang's sysroot whole again. Only a prefix that also holds a Linux system gets the view (Toolchain::mingwPrefixIsSystem): the host's /usr inside the Flatpak, whatever its include/ holds, and a prefix whose include/ has a C library's features.h, which every glibc and musl header includes and mingw-w64 has no use for, as CRAFTER_MINGW_DIR=/usr has. MakeMingwSysroot makes the view in the cache, or in $XDG_RUNTIME_DIR/crafter.build when the cache's filesystem takes no symbolic links (vfat, exFAT, CIFS without unix extensions): the XDG spec promises them there, and nothing else in the cache needs them. Its path is absolute, because CMake runs the compiler from directories of its own and a relative cache did not resolve from there. The prefix is resolved once, absolute and lexically normal, so /opt/mingw/ and /opt/mingw are one prefix and not two builds. clang names a header by the path it found it at, so every diagnostic from a viewed mingw-w64 header named a hashed cache directory. RunBuildCommand now writes paths into the view as paths into the prefix, as BuildStdPcm did for its manifest messages already. Also from the review of PR #44: SysrootCompileFlags builds a mingw command, which can make a view, so it redirects the cache like the other tests; the manifest filter's comment names what it still keeps out; the C path asks MingwSysroot() once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:58:30 +01:00
// target, settled on the first call of a process: empty without a
// mingwPrefix, the prefix itself for one that holds mingw-w64 alone, and
// for a system prefix the view MakeMingwSysroot makes in crafter-build's
// cache, or in $XDG_RUNTIME_DIR/crafter.build when the cache's
// filesystem takes no symbolic links. A system prefix cannot be the
// sysroot: clang takes a mingw sysroot for a tree that holds mingw-w64
// alone and searches its include/ and lib/ as well, which for /usr are
// the Linux system's own. A Windows build then saw glibc's headers, and
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
// libstdc++, finding <sys/single_threaded.h>, had shared_ptr read
// __libc_single_threaded, which nothing on Windows defines (issue #43).
// Throws when the view cannot be made.
const fs::path& MingwSysroot();
fix(mingw): view only a prefix that holds a Linux system The first fix showed clang every mingw prefix through a view of its mingw-w64 parts. That broke a prefix that holds mingw-w64 alone, where Windows libraries installed with --prefix land in include/ and lib/: with CRAFTER_MINGW_DIR=/opt/mingw, <SDL2/SDL.h> and -lSDL2 were no longer found. Such a prefix is clang's sysroot whole again. Only a prefix that also holds a Linux system gets the view (Toolchain::mingwPrefixIsSystem): the host's /usr inside the Flatpak, whatever its include/ holds, and a prefix whose include/ has a C library's features.h, which every glibc and musl header includes and mingw-w64 has no use for, as CRAFTER_MINGW_DIR=/usr has. MakeMingwSysroot makes the view in the cache, or in $XDG_RUNTIME_DIR/crafter.build when the cache's filesystem takes no symbolic links (vfat, exFAT, CIFS without unix extensions): the XDG spec promises them there, and nothing else in the cache needs them. Its path is absolute, because CMake runs the compiler from directories of its own and a relative cache did not resolve from there. The prefix is resolved once, absolute and lexically normal, so /opt/mingw/ and /opt/mingw are one prefix and not two builds. clang names a header by the path it found it at, so every diagnostic from a viewed mingw-w64 header named a hashed cache directory. RunBuildCommand now writes paths into the view as paths into the prefix, as BuildStdPcm did for its manifest messages already. Also from the review of PR #44: SysrootCompileFlags builds a mingw command, which can make a view, so it redirects the cache like the other tests; the manifest filter's comment names what it still keeps out; the C path asks MingwSysroot() once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:58:30 +01:00
// `text` with every path into the view MingwSysroot() made written as
// the same path into the prefix it shows, so that compiler messages name
// a header where the user installed it rather than in a hashed cache
// directory; `text` unchanged when no view was made.
std::string MingwViewToPrefix(std::string text);
fix(sysroot): take the std module source from the sysroot's libc++ release A cross build against a sysroot whose libc++ differs from the toolchain's failed while precompiling the std module, with a page of "no member named 'runtime_format' in namespace 'std'". The module source is a list of using-declarations for what one libc++ release declares, so it only compiles against that release's headers. BuildStdPcm wants the sysroot's own <sysroot>/usr/share/libc++/v1/std.cppm, but Alpine packages the headers without it, and the fallback was the toolchain's copy whatever its release. That held while the compiler came from the same distro as the sysroot; with the Flatpak's libc++ 22.1.8 and Alpine edge on 23.1.2 it no longer does. The release is now read from _LIBCPP_VERSION in the sysroot's and the toolchain's <__config>, and SysrootStdModule picks in this order: the sysroot's own source, the toolchain's when both are the same major release (a release branch only takes fixes), the copy crafter-build ships for that release under share/crafter-build/libc++-modules/<major>. When none fits the build stops with one line naming both releases and the directory the matching source belongs in, before clang is run. If either release cannot be read the toolchain's source is tried as before, since there is nothing to compare. Matching sources live in crafter-build's own share directory rather than the LLVM prefix: they are data this tool ships for sysroots, not part of any one compiler install, and "sources ship" already describes that directory. `--version` prints the toolchain's libc++ release and the releases sources are shipped for, the first thing to look at when such a build fails. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-03 16:37:00 +02:00
// _LIBCPP_VERSION as the <__config> in `includeDir` (an include/c++/v1)
// defines it, XXYYZZ; 0 when the file is missing or has no such line.
std::int32_t LibcxxVersion(const fs::path& includeDir);
// "23.1.2" for 230102.
std::string LibcxxVersionString(std::int32_t version);
struct StdModuleSource {
fs::path stdCppm;
// One line saying why no source fits; empty when stdCppm is set.
std::string error;
};
// The std module source to precompile for a native (non-wasm) build
// against `sysroot`. The module source is a list of using-declarations
// for names the headers of the same libc++ release declare, so one from
// another release fails on every name that release added or dropped. In
// order: the sysroot's own <sysroot>/usr/share/libc++/v1/std.cppm, the
// toolchain's when both are the same major release, the copy for the
// sysroot's release under toolchain.stdModulesDir. Not every distro
// packages the module sources with its libc++ (Alpine does not), which
// is why the sysroot's own copy cannot be the only answer. When the
// sysroot's release cannot be read, the toolchain's source is returned
// and the compile is the check.
StdModuleSource SysrootStdModule(const Toolchain& toolchain, const fs::path& sysroot);
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 version baked in when crafter-build was built; "0.0.0-dev" for a
// build that was given none.
std::string_view CrafterBuildVersion();
}