- Header-only C++20 implementation of the WebAssembly Component Model canonical ABI; public surface aggregates through
include/cmcpp.hppand thecmcppnamespace. - Core work revolves around marshaling values between C++ types and wasm flat values using
lift_flat,lower_flat,lift_flat_values, andlower_flat_valuestemplates. - Implementation mirrors the official Python reference: The C++ code structure, type names, and semantics directly correspond to the Python implementation in
ref/component-model/design/mvp/canonical-abi/definitions.pyand the specification inref/component-model/design/mvp/CanonicalABI.md. When making changes, cross-reference these files to ensure alignment. - Supports async runtime primitives (
Store,Thread,Task), resource management (own,borrow), streams/futures, waitables, and error contexts.
- Do not create summary documents: Avoid creating markdown files in
docs/to summarize work sessions, changes, or fixes unless explicitly requested. The git commit history and code comments are sufficient documentation. - Focus on making changes directly to code, updating existing documentation only when functionality changes, and providing concise summaries in responses rather than generating files.
include/cmcpp/traits.hppdefinesValTrait, type aliases (e.g.,bool_t,string_t), and concept shortcuts that every new type must implement.include/cmcpp/context.hppencapsulatesLiftLowerContext,ComponentInstance,Task, resource tables (HandleTable,InstanceTable), and canonical operations likecanon_waitable_*,canon_stream_*,canon_future_*.include/cmcpp/runtime.hppprovides async primitives:Store,Thread,Call, and supporting types for cooperative scheduling.include/cmcpp/error_context.hppimplements error context lifecycle (canon_error_context_new/debug_message/drop).- Memory helpers live in
include/cmcpp/load.hpp/store.hpp; always respectValTrait<T>::sizeandalignmentfrom those headers instead of hard-coding layout rules.
lower_flat_valuesflattens function arguments, auto-switching to heap marshalling when the arity exceedsMAX_FLAT_PARAMS;lift_flat_valuesmirrors this when decoding results.- Heap-based lowering uses
cx.opts.reallocto allocate guest memory; make sure any caller populatesLiftLowerOptionswith a working realloc when passing heap-backed types (lists, strings, large tuples). - String conversions rely on the
convertcallback; tests wire this through ICU (test/host-util.cpp). Preserve the encoding enum contract (Encoding::Utf8,Encoding::Utf16,Encoding::Latin1,Encoding::Latin1_Utf16).
- Extend
ValTraitspecializations andValTrait<T>::flat_typesfor new composite types before touching lift/lower logic. - Use concepts from
traits.hpp(e.g.,List,Variant,Flags) so overload resolution stays consistent; mirror patterns ininclude/cmcpp/list.hpp,variant.hpp, etc. - Guard traps with
trap_if(cx, condition, message)and route all host failures through theHostTrapprovided by the context rather than throwing ad-hoc exceptions. - Maintain Python equivalence: When implementing new canonical operations or type handling, ensure the C++ behavior matches the corresponding Python code in
definitions.py. Type names, state transitions, and error conditions should align with the reference implementation.
- Default build enables coverage flags on GCC/Clang; run
cmake --preset linux-ninja-Debugfollowed bycmake --build --preset linux-ninja-Debugand thenctest --output-on-failurefrom the build tree. - C++ tests live in
test/main.cppusing doctest and ICU for encoding checks; keep new tests near related sections for quick discovery. - Test coverage workflow: run tests, then
lcov --capture --directory . --output-file coverage.info, filter withlcov --remove, and optionally generate HTML withgenhtml. See README for full workflow. - Python reference tests: The canonical ABI test suite in
ref/component-model/design/mvp/canonical-abi/run_tests.pyexercises the same ABI rules—use it to cross-check tricky canonical ABI edge cases when changing flattening behavior. Run withpython3 run_tests.py(requires Python 3.10+). - When adding new features to the C++ implementation, verify behavior matches the Python reference by comparing against
definitions.pylogic and running the Python test suite.
- Enabling
-DBUILD_SAMPLES=ONbuilds the WAMR host sample (samples/wamr); it wraps host callbacks withhost_function/guest_functionhelpers defined ininclude/wamr.hpp. - Sample guest wasm artifacts are generated from
wasm/test.witviawit-bindgenandwasm-tools. Thesamples/CMakeLists.txtexternal project expectsWASI_SDK_PREFIXto point at the vcpkg-installed WASI SDK. wasm/build.shspins up a dev container to compile wasm components reproducibly; run it if you need to refresh the sample binaries.
- Dependencies are managed through
vcpkg.jsonwith overlays invcpkg_overlays/(notably for WAMR); stick with preset builds so CMake wires in the correct toolchain file automatically. - Cargo manifest (
Cargo.toml) is only for fetchingwasm-toolsandwit-bindgen-cli; if you touch wasm generation logic, update both the manifest and any scripts referencing those versions. - Release management uses Release Please with conventional commits (
feat:,fix:, etc.) to automate changelog and version bumps. - Keep documentation alongside code: update
README.mdwhen introducing new host types or workflows so downstream integrators stay aligned with the canonical ABI behavior.