This tool can compile CPython C extension files, such as the ones created by Cython, to WebAssembly so that the extensions are platform independent.
Currently supports CPython 3.6 to 3.12.
wasi-sdk is automatically downloaded on first use.
Wasmpy-build can be easily integrated into an existing project by the use of a drop-in build_ext
override:
from wasmpy_build import build_ext
from setuptools import setup, Extension
setup(
ext_modules=[Extension("mymodule", ["mymodule.c"])],
cmdclass={"build_ext": build_ext},
)
This also works with generated sources, like from Cython:
from Cython.Build import cythonize
from wasmpy_build import build_ext
from setuptools import setup, Extension
setup(
ext_modules=cythonize([
Extension("mymodule", ["mymodule.pyx"])
]),
cmdclass={"build_ext": build_ext},
)
wasmpy-build my_file.c -o my_file.wasm
wasmpy-build++ my_file.cpp -o my_file.wasm
or
wasmpy-build-cpp my_file.cpp -o my_file.wasm
pip install wasmpy-build
git clone --recurse-submodules https://github.com/olivi-r/wasmpy-build
cd wasmpy-build
python generate.py
python -m pip install .