You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+11-4Lines changed: 11 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,14 @@
1
1
## Repository focus
2
2
- Header-only C++20 implementation of the WebAssembly Component Model canonical ABI; public surface aggregates through `include/cmcpp.hpp` and the `cmcpp` namespace.
3
3
- Core work revolves around marshaling values between C++ types and wasm flat values using `lift_flat`, `lower_flat`, `lift_flat_values`, and `lower_flat_values` templates.
4
-
- Project is kept in sync with the upstream spec (`ref/component-model`) and the reference Python definitions (`definitions.py`, `run_tests.py`). Compare against those when adjusting ABI semantics.
4
+
-**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.py` and the specification in `ref/component-model/design/mvp/CanonicalABI.md`. When making changes, cross-reference these files to ensure alignment.
- Memory helpers live in `include/cmcpp/load.hpp`/`store.hpp`; always respect `ValTrait<T>::size` and `alignment` from those headers instead of hard-coding layout rules.
10
13
11
14
## Lift/Lower workflow
@@ -17,11 +20,14 @@
17
20
- Extend `ValTrait` specializations and `ValTrait<T>::flat_types` for new composite types before touching lift/lower logic.
18
21
- Use concepts from `traits.hpp` (e.g., `List`, `Variant`, `Flags`) so overload resolution stays consistent; mirror patterns in `include/cmcpp/list.hpp`, `variant.hpp`, etc.
19
22
- Guard traps with `trap_if(cx, condition, message)` and route all host failures through the `HostTrap` provided by the context rather than throwing ad-hoc exceptions.
23
+
-**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.
20
24
21
25
## Testing
22
-
- Default build enables coverage flags on GCC/Clang; run `cmake --preset linux-ninja-Debug` followed by `cmake --build --preset linux-ninja-Debug` and then `ctest --preset linux-ninja-Debug` (or `ctest -VV`from the build tree).
26
+
- Default build enables coverage flags on GCC/Clang; run `cmake --preset linux-ninja-Debug` followed by `cmake --build --preset linux-ninja-Debug` and then `ctest --output-on-failure`from the build tree.
23
27
- C++ tests live in `test/main.cpp` using doctest and ICU for encoding checks; keep new tests near related sections for quick discovery.
24
-
-`run_tests.py` exercises the same ABI rules via Python—use it to cross-check tricky canonical ABI edge cases when changing flattening behavior.
28
+
- Test coverage workflow: run tests, then `lcov --capture --directory . --output-file coverage.info`, filter with `lcov --remove`, and optionally generate HTML with `genhtml`. See README for full workflow.
29
+
-**Python reference tests**: The canonical ABI test suite in `ref/component-model/design/mvp/canonical-abi/run_tests.py` exercises the same ABI rules—use it to cross-check tricky canonical ABI edge cases when changing flattening behavior. Run with `python3 run_tests.py` (requires Python 3.10+).
30
+
- When adding new features to the C++ implementation, verify behavior matches the Python reference by comparing against `definitions.py` logic and running the Python test suite.
25
31
26
32
## Samples & runtimes
27
33
- Enabling `-DBUILD_SAMPLES=ON` builds the WAMR host sample (`samples/wamr`); it wraps host callbacks with `host_function`/`guest_function` helpers defined in `include/wamr.hpp`.
@@ -31,4 +37,5 @@
31
37
## Tooling notes
32
38
- Dependencies are managed through `vcpkg.json` with overlays in `vcpkg_overlays/` (notably for WAMR); stick with preset builds so CMake wires in the correct toolchain file automatically.
33
39
- Cargo manifest (`Cargo.toml`) is only for fetching `wasm-tools` and `wit-bindgen-cli`; if you touch wasm generation logic, update both the manifest and any scripts referencing those versions.
40
+
- Release management uses Release Please with conventional commits (`feat:`, `fix:`, etc.) to automate changelog and version bumps.
34
41
- Keep documentation alongside code: update `README.md` when introducing new host types or workflows so downstream integrators stay aligned with the canonical ABI behavior.
Copy file name to clipboardExpand all lines: .github/instructions/component-model.instructions.md
+34-1Lines changed: 34 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,22 @@ applyTo: '**'
7
7
8
8
This repository implements a C++ ABI (Application Binary Interface) for the WebAssembly Component Model, providing host bindings that allow C++ applications to interact with WebAssembly components.
9
9
10
+
### Relationship to the Official Specification
11
+
12
+
**This implementation directly mirrors the canonical Python reference implementation.** The C++ code in this repository is designed to be a faithful translation of:
13
+
14
+
-**Python definitions**: `ref/component-model/design/mvp/canonical-abi/definitions.py` - The authoritative reference implementation
15
+
-**Specification**: `ref/component-model/design/mvp/CanonicalABI.md` - The formal specification document
The C++ implementation maintains structural and semantic alignment with the Python code:
19
+
- Class names map directly (e.g., `Task`, `Store`, `Thread`, `ComponentInstance`)
20
+
- State machines follow the same transitions (e.g., `Task::State` enum values)
21
+
- Method signatures and behavior match the Python counterparts
22
+
- Error conditions and trap points are equivalent
23
+
24
+
When modifying or extending the C++ implementation, **always cross-reference the Python code** to ensure conformance. Any divergence from the reference implementation should be documented and justified.
25
+
10
26
### WebAssembly Component Model Overview
11
27
The [WebAssembly Component Model](https://github.com/WebAssembly/component-model) is a specification that extends WebAssembly with:
12
28
-**Interface Types**: Rich type system beyond basic WebAssembly types
@@ -21,12 +37,16 @@ The [WebAssembly Component Model](https://github.com/WebAssembly/component-model
-**Header-only Library**: Pure template-based implementation in `include/cmcpp/`
@@ -50,6 +70,19 @@ When working with this library:
50
70
2.**Host Functions**: Implement host functions using the provided type wrappers
51
71
3.**Guest Interaction**: Use lift/lower functions to marshal data between host and guest
52
72
4.**Memory Management**: Use the provided realloc functions for guest memory allocation
73
+
5.**Async Operations**: Use `Store::invoke` and `Store::tick()` for cooperative async execution
74
+
6.**Resource Management**: Use `ComponentInstance::table` for handle tracking and canonical resource operations
75
+
7.**Error Contexts**: Use `canon_error_context_*` functions for debug message handling
76
+
8.**Validation**: Cross-check behavior against the Python reference in `ref/component-model/design/mvp/canonical-abi/definitions.py` when implementing new features
77
+
78
+
### Testing Against the Python Reference
79
+
80
+
When adding or modifying canonical ABI operations:
81
+
1. Read the corresponding Python function in `definitions.py` to understand the expected behavior
82
+
2. Ensure your C++ implementation produces equivalent results for the same inputs
83
+
3. Run `python3 ref/component-model/design/mvp/canonical-abi/run_tests.py` to verify the reference tests still pass
84
+
4. Add corresponding C++ tests in `test/main.cpp` that exercise the same edge cases
85
+
5. Document any intentional deviations (e.g., performance optimizations) with clear justification
53
86
54
87
### References
55
88
-[WebAssembly Component Model Specification](https://github.com/WebAssembly/component-model)
0 commit comments