Skip to content

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Jan 17, 2026

Summary

Add support for building Python code into WebAssembly components using componentize-py.

  • python_wasm_component: Library component with custom WIT exports
  • python_wasm_binary: CLI binary with wasi:cli/run export
  • Hermetic componentize_py_toolchain with checksum verification
  • Lazy loading via python_wasm extension

New Rules

python_wasm_component

python_wasm_component(
    name = "hello",
    srcs = ["app.py"],
    wit = "hello.wit",
    world = "hello",
)

python_wasm_binary

python_wasm_binary(
    name = "cli_app",
    srcs = ["cli_app.py"],
)

Lazy Loading

# Only download Python toolchain when needed
python_wasm = use_extension("@rules_wasm_component//wasm:language_extensions.bzl", "python_wasm")
python_wasm.configure()
use_repo(python_wasm, "componentize_py_toolchain", ...)

Test plan

  • Build //examples/python_component:hello
  • Build //examples/python_component:cli_app
  • Verify component exports with wasm-tools component wit
  • Test lazy loading extension works correctly

@avrabe avrabe force-pushed the feature/python-wasm-component branch 2 times, most recently from c45c5e0 to 59271f7 Compare January 17, 2026 06:07
Add `python_wasm_component` and `python_wasm_binary` rules for building
Python code into WebAssembly components using componentize-py.

## New Rules

- `python_wasm_component`: Build Python into a library component with
  custom WIT interface exports
- `python_wasm_binary`: Build Python into a CLI binary component with
  wasi:cli/run export

## Toolchain

- Add `componentize_py_toolchain` with hermetic binary downloads
- Add checksums for componentize-py (canary release)
- Integrate with `python_wasm` lazy loading extension

## Example

```starlark
load("@rules_wasm_component//python:defs.bzl", "python_wasm_component")

python_wasm_component(
    name = "hello",
    srcs = ["app.py"],
    wit = "hello.wit",
    world = "hello",
)
```

## Lazy Loading

Use `python_wasm` extension for minimal downloads:

```starlark
python_wasm = use_extension("@rules_wasm_component//wasm:language_extensions.bzl", "python_wasm")
python_wasm.configure()
```
@avrabe avrabe force-pushed the feature/python-wasm-component branch from 59271f7 to 464c421 Compare January 17, 2026 10:14
@avrabe avrabe merged commit 1b693da into main Jan 17, 2026
@avrabe avrabe deleted the feature/python-wasm-component branch January 17, 2026 10:14
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.

2 participants