Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pmp-p/7c4cf6ac0413d68a939f7447f7ac257a to your computer and use it in GitHub Desktop.
Save pmp-p/7c4cf6ac0413d68a939f7447f7ac257a to your computer and use it in GitHub Desktop.
Build your own third-party pygbag wheels

Introduction

These are the steps I use to build Nova Physics's Python Binding for pygbag. Hope it helps you build your own third-party pygbag wheels 💕

Prerequisites

  • Ubuntu 22 (or higher) WSL works as well. (glibc 2.35+ is required.)

Building

  • Be in the root directory (we will extract stuff into /opt).

  • Download the latest python-wasm-sdk release from here. (I had to download a slightly older release.)

    $ wget https://github.com/pygame-web/python-wasm-sdk/releases/download/3.1.62.1bi/python3.12-wasm-sdk-Ubuntu-22.04.tar.lz4
  • Install lz4 if not already installed.

    $ apt install lz4
  • Decompress python-wasm-sdk. After this step, you should have /opt/python-wasm-sdk.

    $ tar --use-compress-program=lz4 -xvf python3.12-wasm-sdk-Ubuntu-22.04.tar.lz4
  • We're done setting up python-wasm-sdk. Now we need the package we're going to build the wheels for with a setup.py. I will use my own project as an example.

    $ git clone https://github.com/kadir014/nova-physics-python.git
    $ cd nova-physics-python
  • Use the cross-compiler to build the pygbag wheels.

    $ /opt/python-wasm-sdk/python3-wasm setup.py bdist_wheel
  • If successful, you should have the built package under the directory build/lib.wasm32-bi-emscripten-cpython-<version>. And the wheel under dist/.

Problems You May Encounter

  • If your package is a C-extension, you may want to play with compilation optimization levels, -O3 caused few problems to me.
  • emcc doesn't accept -march argument, so remove that when building with python3-wasm.
  • For some reason I also had to download Python 3.10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment