https://github.com/olivi-r/wasmpy-build
WebAssembly build tool for CPython C/C++ extensions
https://github.com/olivi-r/wasmpy-build
c cplusplus cpp cpython cpython-extensions cython python python3 wasi wasi-libc wasi-sdk wasm webassembly
Last synced: 3 months ago
JSON representation
WebAssembly build tool for CPython C/C++ extensions
- Host: GitHub
- URL: https://github.com/olivi-r/wasmpy-build
- Owner: olivi-r
- License: mit
- Created: 2020-12-22T21:11:09.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-27T13:14:04.000Z (almost 2 years ago)
- Last Synced: 2025-08-22T22:34:46.642Z (11 months ago)
- Topics: c, cplusplus, cpp, cpython, cpython-extensions, cython, python, python3, wasi, wasi-libc, wasi-sdk, wasm, webassembly
- Language: C
- Homepage: https://pypi.org/project/wasmpy-build
- Size: 509 KB
- Stars: 22
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wasmpy-build
[](https://ci.appveyor.com/project/olivi-r/wasmpy-build)
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](https://github.com/WebAssembly/wasi-sdk) is automatically downloaded on first use.
# Usage
Wasmpy-build can be easily integrated into an existing project by the use of a drop-in `build_ext` override:
## From a `pyproject.toml` file
This uses an experimental feature and may not work verbatim in the future.
```toml
[build-system]
requires = ["setuptools", "wasmpy-build"]
build-backend = "setuptools.build_meta"
[project]
# ...
[tool.setuptools.cmdclass]
build_ext = "wasmpy_build.build_ext"
[[tool.setuptools.ext-modules]]
name = "mymodule"
sources = ["mymodule.c"]
```
## From a `setup.py` script
```python
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:
```python
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},
)
```
## From the command line
### C
```bash
wasmpy-build my_file.c -o my_file.wasm
```
### C++
```bash
wasmpy-build++ my_file.cpp -o my_file.wasm
```
or
```bash
wasmpy-build-cpp my_file.cpp -o my_file.wasm
```
# Installation
### Install with pip
```bash
pip install wasmpy-build
```
### Build from source
```bash
git clone --recurse-submodules https://github.com/olivi-r/wasmpy-build
cd wasmpy-build
python generate.py
python -m pip install .
```