2026-07-23 01:24:42 +02:00
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
2026-07-22 18:16:38 +02:00
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
import std ;
import Crafter . Build ;
using namespace Crafter ;
namespace {
2026-07-23 01:24:42 +02:00
std : : int32_t Failures = 0 ;
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
void Check ( bool cond , std : : string_view msg ) {
if ( ! cond ) {
std : : println ( std : : cerr , " FAIL: {} " , msg ) ;
2026-07-23 01:24:42 +02:00
+ + Failures ;
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
}
}
Configuration MakeBase ( ) {
Configuration cfg ;
cfg . path = " /tmp/variant-id-test " ;
cfg . name = " vt " ;
cfg . outputName = " vt " ;
cfg . target = " x86_64-pc-linux-gnu " ;
cfg . march = " native " ;
cfg . mtune = " native " ;
cfg . type = ConfigurationType : : Executable ;
return cfg ;
}
}
// VariantId is the cache key for build outputs. Two Configurations that
// differ only in something that affects codegen must produce different
// VariantId / BuildDir / BinDir, otherwise their .o files collide.
int main ( ) {
{
// Baseline against itself: VariantId is deterministic.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
Check ( a . VariantId ( ) = = b . VariantId ( ) , " identical configs have identical VariantId " ) ;
Check ( a . BuildDir ( ) = = b . BuildDir ( ) , " identical configs have identical BuildDir " ) ;
}
{
// type differs -> VariantId differs.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
b . type = ConfigurationType : : LibraryStatic ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " type change perturbs VariantId " ) ;
}
feat: lay an executable out as the files/ of a Flatpak
A Linux executable built by the Flatpak crafter-build links the libc++,
libc++abi and libunwind in its /app/lib and the Sdk's glibc, so it runs
inside crafter-build's sandbox and practically nowhere else: a host
needs glibc 2.38 or newer and all three LLVM libraries, which not even
Arch has. A program built here is meant to run in a Flatpak, so it can
now be laid out as one: with cfg.packaging = Packaging::Flatpak, or
--packaging=flatpak where the project.cpp crafter-build was pointed at
calls ApplyStandardArgs, its BinDir() holds files/, what becomes /app in
the app's sandbox, and -r runs the program there against the libraries
the app carries.
The program is linked into files/bin, where its shaders, files and
assets land too (ProgramDir()), with $ORIGIN/../lib as its one run path,
and the new :Flatpak partition writes the rest of files/: files/lib with
the LLVM runtime libraries, located one by one through clang, and
whatever else the program needs, read with llvm-readelf, that the
directories of the shared libraries it is built on hold, the ones an
unpackaged link records as run paths, or the toolchain's own lib dir,
/app/lib in crafter-build's Flatpak, which the link searches too; and
the desktop entry, metainfo and icons under the app-id in files/share,
the entry refused when its Icon= is not the app-id or
desktop-file-validate, where there is one, rejects it, and an icon that
is not an .svg or a square .png. The metadata and export/ of a build
directory are flatpak build-finish's to write, and crafter-build keeps
no copy of its rules: what a permission means and what the host sees of
an app change with flatpak's releases, and a copy would have to follow
every one. The writer copies a file only when its content differs,
compared a block at a time so that a large file costs no more memory
than a small one, and writes one only when what it would write differs,
never deciding by an mtime, which ostree sets to 0 for every file of
/app, and works the program's libraries out on every write, which reads
only their dynamic sections, since a library replaced in place, as by a
toolchain update, can need others, which FlatpakLibraryChange checks; it
prunes from files/bin each top-level entry an earlier build put there
and this one does not, reporting those the program wrote there itself.
What cannot be a Flatpak is refused before anything is built, saying
why: a Windows or wasm executable, a build against a sysroot or for
musl, another architecture than the runtime's, a build against
CRAFTER_BUILD_LIBCXX_DIR, whose libc++ the Flatpak would not carry, and
a build by a native crafter-build, which links the host's glibc: a
native process knows no Flatpak runtime, from /.flatpak-info, unless
CRAFTER_BUILD_FLATPAK_INFO, the tests' hook, names a file with one.
Default stays the executable as linked for now, RunTests runs every test
as linked, whatever its Configuration asks for, and RunLint works out
its compile command so, and a forwarded --packaging= leaves a
dependency's executables alone, since consumers run them by path. A
dependency that packages its own executable gets its desktop file,
metainfo and icons rebased by the loader as its cfg.files are, so they
are its own whatever directory the consumer builds from. Only a Flatpak
is keyed into VariantId, so every other configuration keeps its
directory, but for one given --packaging=, which was a project arg,
hashed into VariantId, and is a standard arg now, a dependency's
included. The app-id and what a Flatpak is installed as are not keyed:
they change files/share, never what is compiled. The asset name map,
kept three times, twice in Build() and once for the browser runtime's
files.json, is one function now, CompressedAssetName; CompressAsset, in
Crafter.Build-Asset.cpp, keeps the list of the extensions it loads,
which has to agree with it. Each copy a Flatpak build makes into the
program's directory, of its shaders, assets, cfg.files and what its
dependencies forward, records the top-level name it places there, the
names of what a directory holds for one copied into it itself ("data/",
"data/."), and those are what the writer keeps in files/bin; a build
that fails after copying adds them to the writer's record all the same,
so the next write removes what no build places any more.
SharedLibraryRuns now also packages its program as a Flatpak, whose
files/lib has to carry libgreet.so for it to start.
2026-11-01 19:20:55 +01:00
{
// A Flatpak lays its bin dir out unlike the executable as linked, so
// the two get directories of their own. Only a Flatpak is keyed:
// Default and None, and a library whatever it asks for, keep the
// directory they had, and what the app is installed as changes
// files/share only, never what is compiled.
Configuration plain = MakeBase ( ) ;
Configuration none = MakeBase ( ) ;
none . packaging = Packaging : : None ;
Configuration flatpak = MakeBase ( ) ;
flatpak . packaging = Packaging : : Flatpak ;
Configuration described = MakeBase ( ) ;
described . packaging = Packaging : : Flatpak ;
described . flatpak . appId = " net.example.Described " ;
described . flatpak . desktopFile = " app.desktop " ;
described . flatpak . icons = { " icon.svg " } ;
Configuration library = MakeBase ( ) ;
library . type = ConfigurationType : : LibraryStatic ;
Configuration flatpakLibrary = MakeBase ( ) ;
flatpakLibrary . type = ConfigurationType : : LibraryStatic ;
flatpakLibrary . packaging = Packaging : : Flatpak ;
Check ( plain . VariantId ( ) = = none . VariantId ( ) , " Default and None share a directory " ) ;
Check ( plain . VariantId ( ) ! = flatpak . VariantId ( ) , " a Flatpak gets a directory of its own " ) ;
Check ( flatpak . VariantId ( ) = = described . VariantId ( ) , " the app-id, desktop entry and icons do not move the directory " ) ;
Check ( library . VariantId ( ) = = flatpakLibrary . VariantId ( ) , " a library ignores packaging " ) ;
Check ( flatpak . ProgramDir ( ) = = flatpak . BinDir ( ) / " files " / " bin " & & plain . ProgramDir ( ) = = plain . BinDir ( ) , " a Flatpak's program lives in files/bin, everything else's in the bin dir " ) ;
}
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
{
// debug differs -> VariantId differs.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
b . debug = true ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " debug change perturbs VariantId " ) ;
}
{
// sysroot differs -> VariantId differs.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
b . sysroot = " /opt/sysroot " ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " sysroot change perturbs VariantId " ) ;
}
{
// defines differ -> VariantId differs.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
b . defines . push_back ( { " FOO " , " 1 " } ) ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " define added perturbs VariantId " ) ;
}
{
// Same define name, different value -> VariantId differs.
Configuration a = MakeBase ( ) ;
a . defines . push_back ( { " FOO " , " 1 " } ) ;
Configuration b = MakeBase ( ) ;
b . defines . push_back ( { " FOO " , " 2 " } ) ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " define value change perturbs VariantId " ) ;
}
{
// compileFlags differ -> VariantId differs.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
b . compileFlags . push_back ( " -fno-omit-frame-pointer " ) ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " compile flag added perturbs VariantId " ) ;
}
{
// target differs -> VariantId differs.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
b . target = " aarch64-linux-gnu " ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " target change perturbs VariantId " ) ;
}
{
// march differs -> VariantId differs.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
b . march = " x86-64-v3 " ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " march change perturbs VariantId " ) ;
}
fix: key the host PCM cache on source content, add clean, hash project args
Three follow-ons to the stale-build report, all cases of an identity not
capturing something that changes the output.
The host PCM cache under <cache>/crafter.build/<target>-<march>/ is shared by
every crafter-build on the machine, and freshness was a per-file mtime
comparison. That cannot tell "this PCM is newer than my source" from "this PCM
was built from different sources that happen to be newer", so a package install
and a working checkout — or two checkouts of different versions — silently
compiled their project.cpp against each other's declarations. Invalidation now
keys on a stamp over the bytes of every module source, which also covers the
case one file's mtime never could: the cached PCMs import each other, so a
change to :Interface invalidates :Clang's PCM with Crafter.Build-Clang.cppm
untouched.
Project args ApplyStandardArgs does not itself interpret are now folded into
VariantId. Such a flag typically decides what gets compiled or bundled — the
report's example is --no-webgpu dropping entries from cfg.files — and without it
both settings shared one bin dir and interleaved their outputs there, leaving a
bundle matching neither. Sorted and deduplicated so flag order doesn't split the
cache, and inherited by test Configurations.
`crafter-build clean` removes the project's bin/ and build/ trees. It
deliberately does not load project.cpp: cleaning is most often reached when
something is already wrong, and a clean that first needs the project to compile
is useless exactly then.
2026-07-30 17:43:09 +00:00
{
// A project flag the framework can't interpret still decides what gets
// compiled and bundled, so it has to key into VariantId. Otherwise both
// settings share one bin dir and interleave their outputs there — an
// index.html from one alongside a script from the other.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
b . projectArgs . push_back ( " --no-webgpu " ) ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " project arg perturbs VariantId " ) ;
Check ( a . BinDir ( ) ! = b . BinDir ( ) , " project arg yields a distinct BinDir " ) ;
}
{
// Distinct project args must not collide with each other either.
Configuration a = MakeBase ( ) ;
a . projectArgs . push_back ( " --no-webgpu " ) ;
Configuration b = MakeBase ( ) ;
b . projectArgs . push_back ( " --no-audio " ) ;
Check ( a . VariantId ( ) ! = b . VariantId ( ) , " different project args yield different VariantId " ) ;
}
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
{
// PcmDir() differs between Executable (in BuildDir) and Library
// (in BinDir) — Library PCMs land in the installable bin dir so
// downstream consumers can find them.
Configuration exe = MakeBase ( ) ;
Configuration lib = MakeBase ( ) ;
lib . type = ConfigurationType : : LibraryStatic ;
Check ( exe . PcmDir ( ) = = exe . BuildDir ( ) , " Executable PcmDir == BuildDir " ) ;
Check ( lib . PcmDir ( ) = = lib . BinDir ( ) , " Library PcmDir == BinDir " ) ;
}
{
// VariantId is embedded in the path so distinct ids produce distinct dirs.
Configuration a = MakeBase ( ) ;
Configuration b = MakeBase ( ) ;
b . debug = true ;
Check ( a . BuildDir ( ) ! = b . BuildDir ( ) , " different VariantId yields different BuildDir " ) ;
Check ( a . BinDir ( ) ! = b . BinDir ( ) , " different VariantId yields different BinDir " ) ;
}
2026-10-03 20:09:22 +02:00
{
// The compiler is compile state as much as any flag: a PCM can only
// be read by the clang release that wrote it, and nothing in a
// project's sources changes when the compiler does. With the
// toolchain left out of the id, a project built with clang 22 kept
// its PCMs after crafter-build moved to clang 23; the build after
// the update found nothing stale, and the first edit failed with
// "module file ... uses an older format that is no longer supported"
// until the project was cleaned by hand.
Configuration cfg = MakeBase ( ) ;
Toolchain older ;
older . clangxx = " /app/bin/clang++ " ;
older . clangVersion = " clang version 22.1.8 " ;
Toolchain newer = older ;
newer . clangVersion = " clang version 23.1.2 " ;
Check ( cfg . VariantId ( older ) ! = cfg . VariantId ( newer ) , " a compiler update at the same path perturbs VariantId " ) ;
Check ( cfg . VariantId ( older ) = = cfg . VariantId ( older ) , " VariantId under one toolchain is deterministic " ) ;
// Two installs of one release are still two toolchains: their
// libc++ need not be the same build.
Toolchain elsewhere = older ;
elsewhere . clangxx = " /usr/bin/clang++ " ;
Check ( cfg . VariantId ( older ) ! = cfg . VariantId ( elsewhere ) , " the same release installed elsewhere perturbs VariantId " ) ;
Check ( cfg . VariantId ( ) = = cfg . VariantId ( GetToolchain ( ) ) , " VariantId() is the variant under the running toolchain " ) ;
Check ( cfg . BuildDir ( ) . filename ( ) = = cfg . VariantId ( GetToolchain ( ) ) , " BuildDir is named for the running toolchain's variant " ) ;
}
test: a mingw build sees no header from its prefix's include/
MingwSysroot stages a prefix shaped like a Linux system's /usr with a
mingw-w64 cross toolchain in it, without needing a real one: glibc's
<sys/single_threaded.h> in include/, gcc's per-target directory, and a
stand-in mingw-w64 tree whose libstdc++ has an empty std module. A
static library for x86_64-w64-mingw32, so that nothing is linked,
compiles a C++ and a C source that stop with #error when they see the
prefix's include/ or miss mingw-w64's or libstdc++'s headers. Against
the library before the fix, the C++ source stopped on
<sys/single_threaded.h>. The test also checks that the std module is
not cached in the directory older releases built it in against the
prefix itself. It needs only clang, so it runs in CI too, where no
mingw-w64 is installed.
The stand-in std module's source is written through std::format: the
build's import scanner reads string literals as code, and the literal
"export module std;" made the test itself a unit of a module std.
VariantId checks that a prefix gives a mingw configuration a variant of
its own, that two prefixes give two, and that other targets ignore it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 20:48:06 +01:00
{
// The mingw-w64 prefix decides what a mingw build compiles against.
// Before issue #43 it was clang's sysroot as is, which put the host's
// headers on the include path, and with the prefix left out of the
// id, the release that fixed that reused the objects built against
// them: the next build only relinked, and failed to link as before.
Configuration mingw = MakeBase ( ) ;
mingw . target = " x86_64-w64-mingw32 " ;
Toolchain discovered ;
discovered . clangxx = " /app/bin/clang++ " ;
Toolchain hostUsr = discovered ;
hostUsr . mingwPrefix = " /run/host/usr " ;
Toolchain optMingw = discovered ;
optMingw . mingwPrefix = " /opt/mingw " ;
Check ( mingw . VariantId ( discovered ) ! = mingw . VariantId ( hostUsr ) , " a mingw prefix perturbs a mingw configuration's VariantId " ) ;
Check ( mingw . VariantId ( hostUsr ) ! = mingw . VariantId ( optMingw ) , " two mingw prefixes are two variants " ) ;
Configuration host = MakeBase ( ) ;
Check ( host . VariantId ( discovered ) = = host . VariantId ( hostUsr ) , " the mingw prefix leaves other targets' variants alone " ) ;
fix: key the std module's directory on everything it is compiled with
StdPcmDir named the directory by target, march and toolchain, then
grew a case per target for the rest: the wasm flags, and with the first
fix for #43 the mingw prefix. Every other flag BuildStdPcm passes went
unkeyed, so configurations that differed only there took turns
rebuilding one std PCM in place, under the PCMs built against it: a
project with -mtune=generic against project.cpp's -mtune=native on every
run, or two sysroots for one target. And the mingw prefix was keyed only
when there was one, so a build without a prefix landed in the directory
an older release had filled with a CRAFTER_MINGW_DIR=/usr build, and
relinked its objects.
StdPcmFlags is now the one source of the flags BuildStdPcm compiles
with, and StdPcmKey names the directory by target, march and toolchain
followed by a hash of those flags and, for the mingw target, of the
prefix behind its --sysroot. VariantId hashes StdPcmKey in place of the
mingw prefix: units do not notice a std module that moved directories,
so a build has to move with it. Every std PCM directory and build
directory moves once, as after a compiler update; the old ones stay
until `clean` and the cache is cleared by hand.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:58:44 +01:00
// The std module's directory is keyed the same way, and so is a
// prefix given whole against one reached through a view.
Check ( StdPcmKey ( mingw , discovered ) ! = StdPcmKey ( mingw , hostUsr ) , " a mingw prefix moves the mingw std module " ) ;
Check ( StdPcmKey ( mingw , hostUsr ) ! = StdPcmKey ( mingw , optMingw ) , " two mingw prefixes are two std modules " ) ;
Toolchain hostUsrWhole = hostUsr ;
hostUsrWhole . mingwPrefixIsSystem = ! hostUsr . mingwPrefixIsSystem ;
Check ( StdPcmKey ( mingw , hostUsr ) ! = StdPcmKey ( mingw , hostUsrWhole ) , " a prefix given whole and one shown through a view are two std modules " ) ;
Check ( mingw . VariantId ( hostUsr ) ! = mingw . VariantId ( hostUsrWhole ) , " and two variants, through the std module " ) ;
Check ( StdPcmKey ( host , discovered ) = = StdPcmKey ( host , hostUsr ) , " the mingw prefix leaves other targets' std modules alone " ) ;
}
{
// Everything the std module is compiled with keys its directory, not
// only target and march. -mtune was left out, so a project built
// with -mtune=generic shared one std PCM with project.cpp's
// -mtune=native, and the two rebuilt it in turn on every run, under
// every module built against it; two sysroots did the same.
Toolchain tc ;
tc . clangxx = " /app/bin/clang++ " ;
tc . clangVersion = " clang version 23.1.2 " ;
Configuration native = MakeBase ( ) ;
Configuration generic = MakeBase ( ) ;
generic . mtune = " generic " ;
Check ( StdPcmKey ( native , tc ) ! = StdPcmKey ( generic , tc ) , " -mtune keys the std module " ) ;
Configuration sysrootA = MakeBase ( ) ;
sysrootA . sysroot = " /opt/sysroot-a " ;
Configuration sysrootB = MakeBase ( ) ;
sysrootB . sysroot = " /opt/sysroot-b " ;
Check ( StdPcmKey ( sysrootA , tc ) ! = StdPcmKey ( sysrootB , tc ) & & StdPcmKey ( sysrootA , tc ) ! = StdPcmKey ( native , tc ) , " the sysroot keys the std module " ) ;
Configuration wasm = MakeBase ( ) ;
wasm . target = " wasm32-wasip1 " ;
wasm . sysroot = " /opt/wasi-sysroot " ;
Configuration relaxed = MakeBase ( ) ;
relaxed . target = wasm . target ;
relaxed . sysroot = wasm . sysroot ;
relaxed . wasmVariantFlags = { " -mrelaxed-simd " } ;
Check ( StdPcmKey ( wasm , tc ) ! = StdPcmKey ( relaxed , tc ) , " a wasm variant pass's flags key the std module " ) ;
Check ( StdPcmKey ( native , tc ) = = StdPcmKey ( MakeBase ( ) , tc ) , " one configuration, one std module " ) ;
Check ( StdPcmKey ( native , tc ) . starts_with ( std : : format ( " {}-{}-{}- " , native . target , native . march , tc . Key ( ) ) ) , std : : format ( " the directory still says target, march and toolchain (got '{}') " , StdPcmKey ( native , tc ) ) ) ;
Check ( native . VariantId ( tc ) ! = generic . VariantId ( tc ) & & sysrootA . VariantId ( tc ) ! = sysrootB . VariantId ( tc ) , " a build moves with its std module " ) ;
test: a mingw build sees no header from its prefix's include/
MingwSysroot stages a prefix shaped like a Linux system's /usr with a
mingw-w64 cross toolchain in it, without needing a real one: glibc's
<sys/single_threaded.h> in include/, gcc's per-target directory, and a
stand-in mingw-w64 tree whose libstdc++ has an empty std module. A
static library for x86_64-w64-mingw32, so that nothing is linked,
compiles a C++ and a C source that stop with #error when they see the
prefix's include/ or miss mingw-w64's or libstdc++'s headers. Against
the library before the fix, the C++ source stopped on
<sys/single_threaded.h>. The test also checks that the std module is
not cached in the directory older releases built it in against the
prefix itself. It needs only clang, so it runs in CI too, where no
mingw-w64 is installed.
The stand-in std module's source is written through std::format: the
build's import scanner reads string literals as code, and the literal
"export module std;" made the test itself a unit of a module std.
VariantId checks that a prefix gives a mingw configuration a variant of
its own, that two prefixes give two, and that other targets ignore it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 20:48:06 +01:00
}
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
2026-07-23 01:24:42 +02:00
if ( Failures > 0 ) {
std : : println ( std : : cerr , " {} assertions failed " , Failures ) ;
test: broaden self-test coverage beyond the compile smoke test
The suite had only HelloWorld, which built and exited an empty exe. Add
in-process tests covering each public surface area users actually touch:
- StaticLib / ModuleInterface / DependencyLink — Build() against
fixtures for libraries, project-local module interfaces, and
cross-config module deps with link verification (runs the built exe).
- ShaderCompile — drives Shader::Compile directly, validates SPIR-V
magic + Check() idempotency.
- StandardArgs — covers --debug, --target=, --march=, --mtune=,
--lib/--shared promotions, and ArgQuery::Has / Get.
- TestRunnerSpec — FromSpec parse rules, ForTarget routing for host,
wasm32-wasip1, aarch64-linux-gnu (+ sysroot QEMU_LD_PREFIX),
i686 → qemu-i386 rewrite, mingw → wine on Linux hosts, FromEnv.
- VariantId — confirms type / debug / sysroot / defines / compileFlags /
target / march all perturb the cache key, plus PcmDir routing.
- WasiBrowserRuntime — calls EnableWasiBrowserRuntime, asserts the
three cfg.files entries get registered and index.html had its
template placeholder substituted.
- RunSingleTestExit — drives RunSingleTest against tiny sh scripts and
pins the documented exit-code mapping (0/77/non-zero) and the
Cmd-prefix runner path.
Closes #12.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-27 19:38:18 +00:00
return 1 ;
}
return 0 ;
}