Skip to content

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Jan 10, 2026

Summary

  • Add -mexec-model=reactor to cpp_component compilation (library components)
  • Add -mexec-model=command to cpp_wasm_binary compilation (CLI executables)
  • Add exec_model to WasmComponentInfo metadata for introspection

Problem

cpp_component was incorrectly producing command-mode components that:

  • Export wasi:cli/[email protected] (CLI interface, not library)
  • Expect a main() function causing undefined_weak:main warnings
  • Cannot be composed with other components

Root Cause

Both cpp_component and cpp_wasm_binary used identical clang invocations without specifying -mexec-model. WASI SDK defaults to command mode.

Solution

Rule Purpose exec-model Entry Point
cpp_component Library component reactor _initialize
cpp_wasm_binary CLI executable command _start (main)

Test plan

  • Build //examples/cpp_component/simple_calculator:simple_calculator
  • Verify component exports with wasm-tools component wit - no wasi:cli/run
  • Build //test/cpp_binary:hello_cpp
  • Run with wasmtime - outputs "Hello from cpp_wasm_binary!"

Fixes #302

cpp_component was incorrectly producing command-mode components that
export wasi:cli/run and expect a main() function. This caused:
- undefined_weak:main warnings during compilation
- Incorrect exports that prevent component composition

Add explicit -mexec-model flags to differentiate:
- cpp_component: -mexec-model=reactor (library, exports _initialize)
- cpp_wasm_binary: -mexec-model=command (CLI, exports _start)

Also add exec_model to WasmComponentInfo metadata for introspection.

Fixes #302

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@avrabe avrabe force-pushed the fix/302-cpp-component-reactor-mode branch from c242167 to 1bf8af8 Compare January 10, 2026 07:18
@avrabe avrabe merged commit 3f62651 into main Jan 10, 2026
27 checks passed
@avrabe avrabe deleted the fix/302-cpp-component-reactor-mode branch January 10, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cpp_component uses command adapter instead of reactor for library components, causing undefined_weak:main

2 participants