@@ -386,8 +386,8 @@ public:
386386### Language Features
387387- **Templates**: Full template metaprogramming support
388388- **STL**: Standard Template Library available
389- - **Exceptions**: Optional exception handling support
390- - **RTTI**: Runtime Type Information (limited)
389+ - **Exceptions**: Currently not supported by WASI SDK (see limitations below)
390+ - **RTTI**: Runtime Type Information (limited, disabled by default )
391391- **Threading**: Limited threading support (single-threaded execution)
392392
393393### Memory Management
@@ -414,13 +414,13 @@ cpp_component(
414414 # ... other attributes
415415 optimize = True , # Enable -O2 optimization
416416 cxx_std = " c++20" , # Use latest standard
417- enable_exceptions = False , # Disable exceptions for size
417+ enable_exceptions = False , # Required: WASI SDK doesn't support exceptions
418418)
419419```
420420
421421### Best Practices
4224221 . ** Minimize allocations** : Use stack allocation when possible
423- 2 . ** Avoid exceptions ** : For smaller component size (optional )
423+ 2 . ** Use error codes or Result types ** : Instead of exceptions (required )
4244243 . ** Use const correctness** : Enable compiler optimizations
4254254 . ** Profile memory usage** : WebAssembly has limited memory
4264265 . ** Optimize hot paths** : Focus on frequently called functions
@@ -500,16 +500,99 @@ wasm_component_test(
500500)
501501```
502502
503+ ## WASI SDK Limitations
504+
505+ ### C++ Exception Handling
506+
507+ ** Current Status** : WASI SDK does not support C++ exceptions. Components must be built with ` enable_exceptions = False ` .
508+
509+ ** Technical Details** :
510+ - WASI SDK's libc++abi is compiled without exception handling support
511+ - Missing runtime symbols: ` __cxa_allocate_exception ` , ` __cxa_throw ` , ` __cxa_free_exception `
512+ - WebAssembly exception handling proposal is available but not yet integrated in WASI SDK
513+
514+ ** Required Configuration** :
515+ ``` python
516+ cpp_component(
517+ name = " my_component" ,
518+ # ... other attributes
519+ enable_exceptions = False , # Required - must be False
520+ )
521+
522+ cc_component_library(
523+ name = " my_library" ,
524+ # ... other attributes
525+ enable_exceptions = False , # Required - must be False
526+ )
527+ ```
528+
529+ ** Error Handling Alternatives** :
530+ ``` cpp
531+ // ✅ Use Result types or error codes instead of exceptions
532+ std::variant<double , std::string> divide (double a, double b) {
533+ if (b == 0.0 ) {
534+ return std::string (" Division by zero" );
535+ }
536+ return a / b ;
537+ }
538+
539+ // ✅ Use optional types for operations that might fail
540+ std::optional<double > safe_sqrt(double x) {
541+ if (x < 0 ) {
542+ return std::nullopt ; // Instead of throwing
543+ }
544+ return std ::sqrt (x );
545+ }
546+
547+ // ✅ Use error codes
548+ enum class CalculationError { DivisionByZero , InvalidInput } ;
549+ struct Result {
550+ bool success ;
551+ double value ;
552+ CalculationError error ;
553+ } ;
554+ ```
555+
556+ ### Component Validation
557+
558+ Components built with rules_wasm_component include automatic validation to ensure they conform to the WebAssembly Component Model specification.
559+
560+ **Enable Validation**:
561+ ```python
562+ cpp_component(
563+ name = "validated_component",
564+ # ... other attributes
565+ validate_wit = True, # Enable WIT compliance validation
566+ )
567+ ```
568+
569+ ** Validation Process** :
570+ 1 . ** WIT Interface Check** : Ensures component exports match WIT specification
571+ 2 . ** Component Model Compliance** : Validates against WebAssembly Component Model format
572+ 3 . ** Type Safety** : Verifies that exported functions have correct signatures
573+
574+ ** Validation Output** :
575+ ``` bash
576+ # Validation creates a log file showing results
577+ bazel build //:my_component
578+ # Creates: bazel-bin/my_component_wit_validation.log
579+ ```
580+
581+ ** Common Validation Errors** :
582+ - ** Export mismatch** : Component doesn't export all functions declared in WIT
583+ - ** Type signature mismatch** : Function parameters or return types don't match WIT
584+ - ** Missing world implementation** : WIT world not properly implemented
585+
503586## Troubleshooting
504587
505588### Common Issues
506589
507- ** Linker errors with undefined symbols:**
590+ ** Linker errors with C++ exception symbols:**
508591```
509- Error: undefined symbol: std::__throw_bad_alloc
592+ wasm-ld: error: undefined symbol: __cxa_allocate_exception
593+ wasm-ld: error: undefined symbol: __cxa_throw
510594```
511- - Enable exceptions: ` enable_exceptions = True `
512- - Or avoid code paths that throw (recommended)
595+ ** Solution** : Set ` enable_exceptions = False ` (required for WASI SDK)
513596
514597** Memory allocation failures:**
515598```
@@ -527,10 +610,18 @@ Error: 'pthread_create' undefined
527610- Use single-threaded algorithms
528611- Consider async patterns instead of threads
529612
613+ ** Validation failures:**
614+ ```
615+ Error: Component doesn't export function 'calculate'
616+ ```
617+ - Check WIT file matches component implementation
618+ - Ensure all exported functions are implemented
619+ - Verify function signatures match exactly
620+
530621### Performance Issues
531622
532623** Large component size:**
533- - Disable exceptions: ` enable_exceptions = False `
624+ - Always use ` enable_exceptions = False ` (required)
534625- Use smaller standard library subset
535626- Enable optimization: ` optimize = True `
536627- Consider C instead of C++ for minimal components
0 commit comments