Compact, tool-neutral guidance for coding agents and contributors working in SpecLab. See README.md
for the design narrative and usage examples; this file records only facts that
are easy to get wrong or that contradict the docs.
- CMake 4.0–4.4, C++23, no extensions (
CMAKE_CXX_EXTENSIONS OFF, set beforeproject()). CMake 4.5+ is refused at configure time until itsimport stdgate is added (see below). - Compiler minimums enforced in
CMakeLists.txt: MSVC 19.40+ (17.10), GCC 16.1+, Clang 20+. Other compilers abort configure. GCC 15 is not supported (see issue #9): it does not round-trip libstdc++'sstdmodule through a second-level BMI, sospeclab.runners.testrunnerfails to compile. GCC 16.2.0 is not usable either (issue #17: it corrupts this tree's module BMIs); CI pinsgcc:16.1.0. - CI legs (
.github/workflows/ci.yml): GCC 16.1.0 × CMake 4.1.1 / 4.3.1 / 4.4.2, Clang 21 + libc++ × CMake 4.3.1, macOS 15 arm64 with Clang 21.1.8 + libc++ × CMake 4.3.1, and MSVC onwindows-2022(x64, x86) andwindows-latest(x64). These mirror what MduX, the main consumer, builds with. - Default build type is
RelWithDebInfo(set incmake/StandardProjectSettings.cmake, only when SpecLab is the top-level project). import stdis uniform across compilers — there is no per-compiler path and no manually precompiled std module anywhere in the build:CMAKE_EXPERIMENTAL_CXX_IMPORT_STDis set beforeproject(), with the value for the running CMake series:d0edc3af-4c50-42ea-a356-e2862fe7a444(4.0–4.2),451f2fe2-a8a2-47c3-bc32-94786d8fc91b(4.3),f35a9ac6-8463-4d38-8eec-5d6008153e7d(4.4). Values come from each release'sHelp/dev/experimental.rst; add a series there and extend the CI matrix in the same diff. It cannot be guarded onCMAKE_CXX_COMPILER_ID: that variable is only populated by compiler detection insideproject().- Availability is checked with
23 IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD, andCMAKE_CXX_MODULE_STD ON(directory scope) gives every SpecLab targetCXX_MODULE_STD. Do not test or link__CMAKE::CXX23by hand: it is an internal name, CMake 4.3 no longer creates it at configure time, and a manual link once leaked it into the install export set. - No
build_std_moduletarget exists — the old GCC one precompiled header units (import <vector>;), which is a different feature fromimport std;, and it was removed. Do not reintroduce a hand-rolledstd.pcmfor Clang either: it is a second definition of modulestd, and thestd.cppmpath is distro-specific. - Clang works with libc++ only: configure with
--toolchain cmake/toolchains/linux-clang21-libcxx.cmake(needsclang-21,libc++-21-dev,libc++abi-21-devfrom apt.llvm.org; override the root withSPECLAB_LLVM_ROOT). The toolchain file selects-stdlib=libc++and pointsCMAKE_CXX_STDLIB_MODULES_JSONatlibc++.modules.json. Same setup MduX uses. - macOS: Apple Silicon only, with upstream LLVM/Clang (Homebrew
llvm@21, verified 21.1.8) and libc++:--toolchain cmake/toolchains/macos-arm64-llvm.cmake(SPECLAB_LLVM_ROOToverrides the LLVM root). This is MduX's ADR-013 configuration. AppleClang is refused byCMakeLists.txtbecause it has noimport stdmodule surface. GCC on macOS is refused too, and so is any macOS target architecture other than arm64. The architecture check readsCMAKE_OSX_ARCHITECTURES, falling back to the processor when it is empty, so x86_64 and universalarm64;x86_64builds are rejected even on an Apple Silicon host. Another upstream Clang only gets a warning.
speclab_optionsandspeclab_warningsare linked privately (and wrapped in$<BUILD_INTERFACE:>), so nothing from SpecLab's build — warnings,-Werror,/permissive-,NOMINMAX,SPECLAB_*definitions — reaches a target that linksspeclab::speclab. Keep it that way: aPUBLIClink here once injectedMDUX_VERSION_*=0.1.0into every MduX test TU.- Instrumented builds are the exception, and
enable_sanitizers(speclab_options speclab)sets them up:-fsanitize=…is PUBLIC onspeclab, for both compiling and linking. A translation unit that doesimport speclab;compiles inline code from SpecLab's module interfaces as those interfaces were built. If the importer is not instrumented to match, GCC 16 fails with an internal compiler error (expand_UBSAN_NULL).--coverageis compiled privately (throughspeclab_options) and only its link flag is exported.- Never route any of these through
speclab_optionsalone:BUILD_INTERFACEwould drop them from the installed package (undefined reference to __asan_*).
- In-tree targets (examples, tests) opt in explicitly by linking
speclab_options speclab_warnings. SPECLAB_WARNINGS_AS_ERRORSdefaults toPROJECT_IS_TOP_LEVEL:-Werrorin SpecLab's own build, not when SpecLab is a subproject.- Settings that write cache entries (
CMAKE_BUILD_TYPE,CMAKE_EXPORT_COMPILE_COMMANDS) are applied only when top-level.
- A release is a
vX.Y.Ztag pushed ondevelop..github/workflows/release.ymlbuilds the packages and creates the GitHub release. The release notes are the## [X.Y.Z]section ofCHANGELOG.mdplus a fixed disclaimer. The workflow fails if that section is missing, so the CHANGELOG is also where the release text is written. BumpSPECLAB_PROJECT_VERSION's default inCMakeLists.txtand add aCHANGELOG.mdentry in a PR before tagging, so that the tagged sources declare their own version. - Tags are immutable: never move or re-push a published tag, and ship a fix as a new patch release. MduX pins SpecLab by SHA and treats the tag as documentation; v0.1.0 was moved once and MduX recorded it as a supplier risk.
- Before tagging, dry-run the release workflow on
develop(gh workflow run release.yml --ref develop). It builds every package but creates no release, because the publish jobs only run on a tag push.
Configure from a build/ subdir (in-source builds are blocked by
cmake/PreventInSourceBuilds.cmake):
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DSPECLAB_BUILD_EXAMPLES=ON -DSPECLAB_BUILD_TESTS=ON
cmake --build build --parallelRun the self-tests, then the examples:
ctest --test-dir build --output-on-failure
./build/examples/basic_example
./build/examples/pulse_oximeter_exampleCI does all three on every platform leg (ci.yml, -DSPECLAB_BUILD_TESTS=ON).
SPECLAB_BUILD_TESTSdefaults toPROJECT_IS_TOP_LEVEL, so consumers that add SpecLab as a subproject do not build them.speclab_selftestsis SpecLab tested with its own tools. Each scenario is aspeclab::Registerobject inAssertionTests.cpp,ChecksTests.cpporFunctionalApiTests.cpp, andmainisspeclab::runMain.DiscoverScenarios.cmake(loaded throughTEST_INCLUDE_FILES) registers one CTest test per scenario from--list-tests, with its labels, so adding a scenario needs no CMake change.speclab_discovery_fixturehas one passing and one failing scenario. Thecontract.*tests run it throughExpectRun.cmake, which checks the exit code and the exact output of--list-tests,--run=and a full run. Don't replace them withWILL_FAILorPASS_REGULAR_EXPRESSION: CTest cannot check both at once with those.- A scenario that checks a failing inner test builds the inner
Test, callsExecute(), then asserts on the returnedTestResultin an outerThen. Anything a Then needs is captured by value. .gitignoreignores*.cmake;tests/*.cmakehas an exception, likecmake/andcmake/toolchains/. A new.cmakefile elsewhere needs its own exception, or it never reaches CI.- The self-tests don't cover the class-based API, the requirement registry or the reporters yet.
examples/functional_api_examples.cpp and examples/requirements_example.cpp
are present in the tree but examples/CMakeLists.txt only wires
basic_example and pulse_oximeter_example. If you edit or run the other two,
add them to examples/CMakeLists.txt first; otherwise they silently rot.
.clang-tidyexists and is comprehensive (187 lines) — apply it manually..clang-formatis an empty 0-byte file;clang-formatwill fall back to defaults. Do not rely on it for the style described inREADME.md. Follow the written conventions (4-space indent, pointer/reference glued to type,UpperCamelCasetypes,lowerCamelCasefunctions) by hand.- Sanitizers are opt-in via
ENABLE_SANITIZER_{ADDRESS,LEAK,UNDEFINED_BEHAVIOR, THREAD,MEMORY}andENABLE_COVERAGE(GCC/Clang only); seecmake/Sanitizers.cmake. CMAKE_EXPORT_COMPILE_COMMANDSis always on for clang-based tooling.
README.md's module tree is incomplete. The authoritative file list is
target_sources(... FILE_SET cxx_modules ...) in CMakeLists.txt. Modules
actually present under include/speclab/:
core/:TestResult,Assertions,TestCase,TestSuite,Requirements,RequirementAPI,FunctionalAPImedical/:MedicalTestCase,ComplianceValidator,MedicalFunctionalAPIreporters/:Reporter,ConsoleReporterrunners/:TestRunner,Discovery(Register,registry(),runMain: the--list-tests/--run=contract, byte-compatible with MduX'sSpecLabBridge.hpp)SpecLab.cppm(top-level aggregator)
Do not invent imports from speclab.cppm, validators/, or utils/ — none
of these exist in the repo.
Lives in speclab.core.requirements (module core/Requirements.cppm /
core/RequirementAPI.cppm). Key free functions: RegisterRequirement,
LinkTestRequirement, ExportTraceMatrixCSV, ExportTraceMatrixHTML,
SetRequirementsConfig, TestRiskScore, HasUncoveredCriticalRequirements.
Suite execution auto-appends synthetic REQUIREMENT_COVERAGE (and, when
abortOnCriticalGaps is set, REQUIREMENT_COVERAGE_PRE) results — these are
framework-emitted, not tests you register.
speclab::Requirement(…), Feature(…) and IEC62304Process(…) (module
core/RequirementAPI.cppm) execute the tests attached to them since #25, and register
themselves and their links on Execute(). Keep the invariant their self-tests pin
(tests/RequirementApiTests.cpp): these builders never return an empty result list. A
requirement with no test returns Blocked, a disabled one Skipped, and an empty feature or
lifecycle process Blocked. An empty vector reads as "nothing failed" to a caller counting
failures, which is what #25 was about. They hand out references into their containers, so those
are std::deque, not std::vector.
Coverage links are rebuilt on every Execute() from the tests that ran and were not skipped,
plus AssociateTest ids; earlier links are cleared first. Keep that. Each of the three shapes it
rules out was a real false pass: a requirement disabled after an execution, a disabled attached
test, and a requirement with no test linking its own synthetic result (whose testId is the
requirement id). Risk levels and safety classes are normalised on the way in, because the builders
accept "Critical" while the gate compares "CRITICAL".
The registry's locking is checked by a ThreadSanitizer CI leg (linux-tsan in ci.yml). Without
the mutex, TSan reports a race in registerRequirement and the concurrency self-test spins instead
of finishing, which is why that job has a timeout.
SPECLAB_VERSION_*andSPECLAB_MEDICAL_DEVICE_COMPLIANCE=1are defined byconfigure_speclab_version(seecmake/CompilerSettings.cmake), for SpecLab's own translation units only. Don't hardcode them from the docs.- No
ASSERT_*/FAILmacros exist: a#definein a module interface unit is not exported byimport speclab;. Usespeclab::core::Assertions::…directly,require(cond, "fmt {}", args…)for a formatted message, andspeclab::core::Checksto collect several failures. AssertionFailure::formatLocation()reportsfile.cpp:line:column, with the file name only, so failure output is the same on every machine.location()keeps the full path. Tests assert on that format.- In
runners/Discovery.cppm,registry()andrunMainare deliberately notinline. As non-inline functions attached to the module they have one definition, so there is one registry per program. speclab::Test<State>with a function-localStatebreaks MSVC 19.44 (VS 2022): C5046 ("symbol involving type with internal linkage not defined") and then either an internal compiler error (C1001) or a link failure. VS 18, GCC and Clang are fine. DeclareStatetypes at namespace scope (an anonymous namespace works), astests/FunctionalApiTests.cppdoes. Don't silence C5046 with/wd5046: on that compiler it reports a real missing definition. Lambdas and theshared_ptr-to-local-struct idiom are not affected; awindows-2022probe checked that.- A GCC 16 modules bug has been seen in a consumer (MduX
ml_spec,GeneratedModelTests.cpp). Once its test bridge forwardedmaintospeclab::runMain, that translation unit failed with "use of deleted function ~ModelPackage()". A single localstd::println(std::cout, "{}", std::string)instantiation in the including TU avoids it. Moving the definitions out of the module interface does not help: this was tested. - New
.cppmmodules must be added to thetarget_sourcesFILE_SETlist in rootCMakeLists.txtor they will not be compiled/exported. *.modis.gitignore'd (Fortran convention), but C++ module BMI files (.ifc,.module.json) are also ignored — don't commit them.
AGENTS.mdis the canonical shared instruction file. Keep tool-specific assistant settings local and ignored; do not add a second repository instruction source.- Commit messages, PR descriptions, and code comments contain no assistant attribution.