Skip to main content

build_ext for Pyodide

Project description

exodide: build_ext for Pyodide

PyPI

1. Overview

Warning This project is still under development.

Pyodide is a WebAssembly variant of CPython. By using it, we can run Python code inside web browser.

Although we can run most of pure-Python packages on Pyodide, however, available C/C++-extension packages are limited to builtin packages.

The motivation of this project (exodide) is providing C/C++-extension builder for Pyodide, and enables users to run your own custom C/C++-extension packages on Pyodide.

2. Usage

2.1 Prerequest

To build C/C++ to WebAssembly, you need Emscripten. We assume you set up emcc and em++ commands as the official document.

Since Pyodide is built with Python 3.10, we only prepare headers for the version. Your custom package must run on Python 3.10.

2.2 Build with exodide

from setuptools import setup
from exodide import build

# omit

setup(
    # omit
    cmdclass=build.cmdclass(), # {'build': exodide.build, 'build_ext': exodide.build_ext}
)

then CC=emcc CXX=em++ python setup.py bdist_wheel.

Pyodide doesn't provide all the functionalities of CPython, so that you might need to modify your package. You can detect Emscripten compiler by __EMSCRIPTEN__ macro (ref).

#ifdef __EMSCRIPTEN__
// Code for Pyodide
#else
// Code for Others
#endif

2.3 Install to Pyodide

const pyodide = await loadPyodide();

await pyodide.runPythonAsync(`
import micropip
micropip.install("exodide")

from exodide.install import fetch_install

await fetch_install("example.com/your-package.whl")

import your_package
# omit
`);

2.4 Inspect Shared Object (for Debugging)

python3 -m exodide.inspect your-package/your-module.so

Currently, exodide.inspect module prints dylink / dylink.0 custom section, which are used for metadata of Wasm dynamic link.

3. LICENSEs

We utilize other projects and these codes obey their original lisences. We distribute patched header files of CPython and NumPy, too.

4. Build exodide

git clone --recursive --depth 1 https://github.com/ymd-h/exodide.git
cd exodide

make

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

exodide-0.0.4-py3-none-any.whl (348.9 kB view details)

Uploaded Python 3

File details

Details for the file exodide-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: exodide-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 348.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for exodide-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0adc20aa58de2115af041ea8d9459446c188c727e6ea6ffab8379abf95cff70b
MD5 f29d890b3dca0ec787fc349788bb4228
BLAKE2b-256 8932bfeebe6d83a6480743a72a6e15122bcd510762df95847a654bb0b5f62707

See more details on using hashes here.

Supported by

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