Skip to content

feat: shared component utils + unified extension (Phase 1-2 of #250, #253)#416

Merged
avrabe merged 7 commits intomainfrom
feat/shared-component-utils
Mar 22, 2026
Merged

feat: shared component utils + unified extension (Phase 1-2 of #250, #253)#416
avrabe merged 7 commits intomainfrom
feat/shared-component-utils

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Mar 22, 2026

Summary — Phase 1-2 of unified architecture (#250, #253, #257)

Phase 1: Shared Utilities

Create common/wasm_component_utils.bzl and migrate all 7 language rules:

Shared Utility Replaces
create_component_info() 7 identical WasmComponentInfo blocks
normalize_wit_info() 3 incompatible WIT handling patterns
validate_component_action() Validation only in Rust+Go → available to all
WASI_VERSION_ATTR_KWARGS 4+ separate wasi_version definitions

All 7 rules migrated: Rust, Python (component + binary), Go, C++, JS.
~170 LOC eliminated. wasi_version now consistent across all languages.

Phase 2: Unified Extension (#250)

New wasm/unified_extension.bzl with language selection:

wasm = use_extension("@rules_wasm_component//wasm:unified_extension.bzl", "wasm")
wasm.toolchains(
    bundle = "stable-2026-03",
    languages = ["rust", "go"],
    include_p3 = True,
)
  • languages parameter controls downloads (~50MB Rust-only vs ~950MB all)
  • Core tools (wasm-tools, wasmtime, wkg) always loaded
  • Language-specific tools conditional (go→tinygo+binaryen, cpp→wasi-sdk, js→jco, python→componentize-py)
  • Backward compatible — existing individual extensions unchanged

Test plan

  • Rust: //examples/basic:hello_component builds
  • Go: //examples/go_component:calculator_component builds
  • JS: //examples/js_component:simple_js_component builds
  • P2/P3: //test/p3:all passes
  • CI passes

🤖 Generated with Claude Code

avrabe and others added 3 commits March 22, 2026 06:52
Create common/wasm_component_utils.bzl with:
- WASI_VERSION_ATTR_KWARGS, VALIDATE_WIT_ATTR_KWARGS (shared attr definitions)
- create_component_info() factory (replaces 7 identical WasmComponentInfo blocks)
- normalize_wit_info() (unifies 3 incompatible WIT handling patterns)
- validate_component_action() (shared validation, previously only Rust+Go)

Refactor rust_wasm_component.bzl to use shared utils:
- WasmComponentInfo creation: 15 lines → 5 lines
- WIT validation: 78 lines → 6 lines
- Attribute definitions: shared kwargs

No behavioral changes — all existing builds and tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace WasmComponentInfo creation in python_wasm_component and
python_wasm_binary with create_component_info() factory. Use shared
WASI_VERSION_ATTR_KWARGS for consistent attribute definitions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Migrate WasmComponentInfo creation in Go, C++, and JS rules to use
create_component_info() factory from shared wasm_component_utils.bzl.

Add wasi_version attribute to Go, C++, and JS rules (previously only
Rust and Python had it). All 7 language rules now consistently support
wasi_version = "p2" | "p3" via shared WASI_VERSION_ATTR_KWARGS.

Use shared VALIDATE_WIT_ATTR_KWARGS in Go (C++ already had custom).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe changed the title refactor: extract shared wasm_component_utils, migrate Rust + Python refactor: extract shared wasm_component_utils, migrate all 7 language rules Mar 22, 2026
New unified_extension.bzl provides a single entry point for all
toolchain setup with a languages parameter that controls what gets
downloaded:

    wasm = use_extension("@rules_wasm_component//wasm:unified_extension.bzl", "wasm")
    wasm.toolchains(
        bundle = "stable-2026-03",
        languages = ["rust", "go"],
    )

Key features:
- languages parameter: only download toolchains you need
- bundle parameter: pre-validated version combinations
- include_p3: opt-in P3 WIT definitions
- Core tools (wasm-tools, wasmtime, wkg) always loaded
- Language-specific tools loaded conditionally:
  - go: tinygo + binaryen
  - cpp: wasi-sdk + cpp_component
  - javascript: jco + binaryen
  - python: componentize-py (lazy)

Existing individual extensions remain unchanged for backward compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe changed the title refactor: extract shared wasm_component_utils, migrate all 7 language rules feat: shared component utils + unified extension (Phase 1-2 of #250, #253) Mar 22, 2026
avrabe and others added 3 commits March 22, 2026 09:33
Safe minor/patch dependency bumps. Major bumps deferred:
- aspect_bazel_lib 2→3 (breaking), rules_go 0.59→0.60 (TinyGo risk),
  buildifier_prebuilt 6→8 (breaking)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe merged commit ff00196 into main Mar 22, 2026
28 checks passed
@avrabe avrabe deleted the feat/shared-component-utils branch March 22, 2026 12:09
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.

1 participant