Skip to main content

WebAssembly build tool for CPython C/C++ extensions

Project description

wasmpy-build

appveyor-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 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.

[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

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},
)

From the command line

C

wasmpy-build my_file.c -o my_file.wasm

C++

wasmpy-build++ my_file.cpp -o my_file.wasm

or

wasmpy-build-cpp my_file.cpp -o my_file.wasm

Installation

Install with pip

pip install wasmpy-build

Build from source

git clone --recurse-submodules https://github.com/olivi-r/wasmpy-build
cd wasmpy-build
python generate.py
python -m pip install .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wasmpy_build-1.1.0.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wasmpy_build-1.1.0-py3-none-any.whl (2.8 MB view details)

Uploaded Python 3

File details

Details for the file wasmpy_build-1.1.0.tar.gz.

File metadata

  • Download URL: wasmpy_build-1.1.0.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for wasmpy_build-1.1.0.tar.gz
Algorithm Hash digest
SHA256 dab11964e9695dec13f0f3fa8e1ae6e4928bc756d16ee40c9a4c8573a37f7217
MD5 041ce52a2c689a16b07724c8097f4afe
BLAKE2b-256 ca2c8ce2fd64d14f92feef93365a31d2a11cf273829338dcd38fdeb2e703c398

See more details on using hashes here.

File details

Details for the file wasmpy_build-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: wasmpy_build-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for wasmpy_build-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f08e69dc678b484261c88d5568c753b0d30005c9a3b79ccf6576daa0bda6726
MD5 271f105fde146ee1c30feb08a31fb6bb
BLAKE2b-256 b3fc0ea75b4bc0d9e5fa3f42061a759b243cd1ca1b3ceb1634c7afa39c023c1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page