Crafter.Build/examples/library
Jorijn van der Graaf 7ff426b2f0
Some checks failed
CI / build-test-release (push) Failing after 5m36s
SPDX license update
Canonical LGPL-3.0-only text, GPL-3.0 companion, SPDX headers on all
first-party sources, MIT for examples/. Vendored lib/ untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-22 18:19:17 +02:00
..
mylib SPDX license update 2026-07-22 18:19:17 +02:00
main.cpp SPDX license update 2026-07-22 18:19:17 +02:00
project.cpp SPDX license update 2026-07-22 18:19:17 +02:00
README.md V2: WASI, -r flag, CI pipeline, examples & tests cleanup 2026-04-28 23:24:46 +02:00

library

A static library + an executable that consumes it.

cd examples/library
crafter-build
./bin/math-app-x86_64-pc-linux-gnu-native/math-app

Layout:

mylib/MyMath.cppm     # the library's module interface
main.cpp              # the consumer
project.cpp           # declares both, with cfg.dependencies wiring them

Two Configuration objects: a LibraryStatic and an Executable whose dependencies points at the lib. The build runs them in parallel and links libMyMath.a into math-app automatically. import MyMath; in main.cpp resolves through the dep graph — no header paths to hand-wire.

The static unique_ptr<Configuration> for the lib is the canonical lifetime pattern: the parent's dependencies is vector<Configuration*> (raw), so something needs to keep the lib alive across the function return. File-local static does it cleanly without a global pool.