Skip to content

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Nov 18, 2025

Fixes #211

Summary

This PR resolves the issue where C/C++ component rules were ignoring the language attribute and always generating C bindings regardless of user configuration.

Root Cause

The cpp_component and cpp_wit_bindgen rules had hardcoded "c" values in their binding generation code, completely ignoring the ctx.attr.language attribute.

Changes

Core Fixes

  1. cpp/defs.bzl:157 - Fixed cpp_component to use ctx.attr.language instead of hardcoded "c"
  2. cpp/defs.bzl:628 - Fixed cpp_wit_bindgen to use ctx.attr.language instead of hardcoded "c"
  3. cpp/defs.bzl:305-306 - Fixed binding file extensions to match language (.c vs .cpp)
  4. cpp/defs.bzl:116-119 - Added C++ source auto-detection for compilation support
  5. cpp/defs.bzl:340-359 - Added C++ include paths and compilation flags for C++ bindings
  6. cpp/defs.bzl:664-666 - Fixed --string-encoding to only apply to C bindings
  7. cpp/defs.bzl:497-505 - Added cxx_std and optimization to WasmComponentInfo metadata
  8. cpp/defs.bzl - Updated all action mnemonics to be language-specific

Test Framework Improvements

  1. test/cpp/cpp_component_tests.bzl:135-149 - Fixed bindings test to check for directory
  2. test/cpp/cpp_component_tests.bzl:338-347, 404-407 - Fixed optional optimization attribute handling
  3. test/cpp/BUILD.bazel:117-125 - Updated test expectations to use integer values

Example Updates

  1. examples/cpp_component/multi_component_system/BUILD.bazel - Fixed auth_service_cpp to use language="c"
  2. examples/cpp_component/data_structures/BUILD.bazel - Fixed data_structures_component to use language="c"
  3. examples/cpp_component/http_service/BUILD.bazel - Added explicit language="c" and optimize=True
  4. examples/cpp_component/simple_calculator/simple_calculator.cpp - Demonstrates true C++ bindings

Architecture Patterns

This PR establishes three clear patterns:

  1. C++ source with C bindings: Set language="c" - auto-detection enables C++ compilation, generates C-style API
  2. C++ source with C++ bindings: Set language="cpp" - generates namespace-based C++ API
  3. C source with C bindings: Set language="c" - standard C compilation and bindings

Test Results

All 19 C/C++ tests passing
All C/C++ examples building successfully

Verification

# Run all C/C++ tests
bazel test //test/cpp:all_cpp_tests

# Build all examples
bazel build //examples/cpp_component/...

Breaking Changes

None - this fix makes the rules work as originally intended. Users who were relying on the buggy behavior (hardcoded C bindings) may need to add explicit language="c" to their targets if not already specified.

avrabe and others added 4 commits November 18, 2025 17:40
Fixes #211

This commit resolves the issue where C/C++ component rules were ignoring
the language attribute and always generating C bindings regardless of user
configuration.

Changes:
- Fixed hardcoded language in cpp_component binding generation (line 157)
- Fixed hardcoded language in cpp_wit_bindgen binding generation (line 628)
- Fixed binding file extensions to match language (.c vs .cpp)
- Added C++ source auto-detection for compilation support
- Added C++ include paths and compilation flags for C++ bindings
- Fixed string-encoding to only apply to C bindings
- Added cxx_std and optimization fields to WasmComponentInfo metadata
- Fixed all action mnemonics to be language-specific
- Updated test framework to handle optional optimization checks
- Updated examples to use correct language configurations

Test Results:
- All 19 C/C++ tests passing
- All C/C++ examples building successfully

Architecture Patterns:
- C++ source with C bindings: language="c" (auto-detects C++ compilation)
- C++ source with C++ bindings: language="cpp" (namespace-based API)
- C source with C bindings: language="c" (standard C compilation)
- Update wasm-tools: 1.240.0 → 1.241.2
- Update wit-bindgen: 0.46.0 → 0.48.0
- Update wasi-sdk: 27 → 29
- Update rules_cc: 0.2.4 → 0.2.14
- Update bazel_skylib: 1.8.1 → 1.8.2
- Update rules_go: 0.57.0 → 0.59.0
- Update rules_oci: 1.8.0 → 2.2.6
- Update Rust toolchain: 1.90.0 → 1.91.1

NOTE: Updated JSON registry files but registry.bzl embedded fallback
needs to be regenerated to pick up new versions. The checksum_updater
tool should handle this automatically when it's fixed to support
reading from the JSON files.
This fixes the CI failures in PR #212 where builds were failing with
"Unsupported platform linux_amd64 for wasm-tools version 1.241.2".

Changes:
- Update registry.bzl with wasm-tools v1.241.2 checksums for all platforms
- Update wasm-tools.json with v1.241.2 release data
- Fix checksum_updater to use correct marker names (fallback_data vs hardcoded_data)
- Fix checksum_updater to properly reference ChecksumManager field (manager vs checksum_manager)
- Add wasi-sdk tag_prefix support in tool_config.rs
- Fix jco.json to include required sha256/url_suffix fields for NPM packages
- Remove test file nonexistent-tool.json

The registry.bzl update enables wasm-tools v1.241.2 to be properly
downloaded and validated across all supported platforms.

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

Co-Authored-By: Claude <noreply@anthropic.com>
The Windows checksum was incorrect, causing CI failure. Updated to the
correct SHA256: 9eb1af8331ec073d37bb025598426dcb747bd51db085861066e123b9e823fa52

This was discovered from the CI error message which showed the actual
checksum that was downloaded.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@avrabe avrabe merged commit f034afb into main Nov 19, 2025
25 checks passed
avrabe added a commit that referenced this pull request Nov 19, 2025
This fixes the CI failures in PR #212 where builds were failing with
"Unsupported platform linux_amd64 for wasm-tools version 1.241.2".

Changes:
- Update registry.bzl with wasm-tools v1.241.2 checksums for all platforms
- Update wasm-tools.json with v1.241.2 release data
- Fix checksum_updater to use correct marker names (fallback_data vs hardcoded_data)
- Fix checksum_updater to properly reference ChecksumManager field (manager vs checksum_manager)
- Add wasi-sdk tag_prefix support in tool_config.rs
- Fix jco.json to include required sha256/url_suffix fields for NPM packages
- Remove test file nonexistent-tool.json

The registry.bzl update enables wasm-tools v1.241.2 to be properly
downloaded and validated across all supported platforms.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@avrabe avrabe deleted the fix/cpp-language-attribute-issue-211 branch November 19, 2025 06:11
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 rules don't respect the language

2 participants