Crafter.Build/examples/library
Jorijn van der Graaf 8892154b28
Some checks failed
CI / build-test-release (push) Failing after 7m15s
linting
2026-07-23 01:24:42 +02:00
..
mylib linting 2026-07-23 01:24:42 +02:00
main.cpp linting 2026-07-23 01:24:42 +02:00
project.cpp linting 2026-07-23 01:24:42 +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.