Package: exodide
exodide: build_ext for Pyodide1. OverviewPyodideis a WebAssembly
variant ofCPython. 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 tobuiltin packages.
(Update: From v0.21.0, Pyodide started to accept non-builtin C/C++ 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. Usage2.1 Requirement Summary2.3: BuildEmscriptenv3.1.14wheelC/C++ package source working on CPython 3.10.22.4: RunPyodide v0.21.02.5: InspectNumPy2.2 Install exodide2.2.1 Install from PyPIYou can install exodide fromPyPIpip install exodidepip install exodide[build]With build dependenciespip install exodide[inspect]With inspect dependenciespip install exodide[all]With all dependencies2.2.2 Use docker imageWe provide docker imagedockerrun-it-v<yourpackagesourcepath>:/srcghcr.io/ymd-h/exodide:latestbash# Inside docker containersource/emsdk/emsdk_env.sh# Set PATH for emcc/em++2.2.3 Install from SourceSince this repository doesn't contains patched headers, you cannot
install directly from GitHub likepip install git+https://github.com/ymd-h/exodide.gitclone--recursive--depth1https://github.com/ymd-h/exodide.gitcdexodide

make

pipinstall.2.3 Build with exodideThe followings are reuired;Emscripten v3.1.14Set upemccandem++asthe official documentC/C++ extension package source working on Python 3.10wheel(pip install exodide[build]install it, too.)2.3.1 Method 1: Main Usagefrom setuptools import setup
from exodide import build

# omit

setup(
    # omit
    cmdclass=build.cmdclass(), # {'build': build.build, 'build_ext': build.build_ext}
)thenCC=emcc CXX=em++ python setup.py bdist_wheel.2.3.2 Method 2: Fine tuning for Power UserIf your package has special build flow, you might need to call exodide internal API.All internal build API are implemented atexodide.buildmodule.system_include() -> str: System include directory of host Pythonexodide_include() -> List[str]: Include directories inside exodide package.adjust_include(include: List[str]) -> List[str]: Adjust include directoriesInternallysystem_include()andexodide_include()are usedexodide_links() -> List[str]: Linker argumentsexodide_unsupported_links() -> List[str]: Unsupported linker argumentsexodide_platform_tag() -> str: Platform name tag for wheel2.3.3 Method 3: Quick UsageWe also provide custom setup commandexodide_wheel.
The following command have same effect with the first option at '2.3.1 Main Usage'.CC=emccCXX=em++pythonsetup.py--command-packagesexodideexodide_wheel2.3.4 NotesPyodide 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#endif2.4 Install extension package to PyodideNoteSince from Pyodide v0.21.0micropip.install()accepts custom URL,exodide.installmodule become deprecated.Pyodide v0.21 is required.constpyodide=awaitloadPyodide();awaitpyodide.runPythonAsync(`import micropipmicropip.install("example.com/your-package-X.Y.Z-cp310-cp310-emscripten_3_1_14_wasm32.whl")import your_package# omit`);2.5 Inspect Shared Object (for Debugging)Fot inspect,numpyis also required, and you can install withpip install exodide[inspect].python3-mexodide.inspectyour-package/your-module.soCurrently,exodide.inspectmodule printsdylink/dylink.0custom section, which are used for metadata of Wasm dynamic link.3. LICENSEsWe utilize other projects and these codes obey their original lisences.
We distribute patched header files of CPython and NumPy, too.CPython:https://www.python.org/cpythondirectoryPYTHON SOFTWARE FOUNDATION LICENSE VERSION 2NumPy:https://numpy.org/numpydirectory andscript/code_generatorsdirectoryBSD 3-ClausePyodide:https://pyodide.org/en/stable/pyodidedirectoryMPL-2.0Others (exodide original codes)MIT4. Technical DetailsTechnical details are describedhere