Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pmp-p/7c4cf6ac0413d68a939f7447f7ac257a to your computer and use it in GitHub Desktop.

Select an option

Save pmp-p/7c4cf6ac0413d68a939f7447f7ac257a to your computer and use it in GitHub Desktop.

Revisions

  1. @kadir014 kadir014 created this gist Apr 5, 2025.
    41 changes: 41 additions & 0 deletions pygbag_build_custom_wheel.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    # Introduction
    These are the steps I use to build [Nova Physics's Python Binding](https://github.com/kadir014/nova-physics-python) 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.](https://github.com/pygame-web/python-wasm-sdk/releases) (I had to download a slightly older release.)
    ```sh
    $ 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.
    ```sh
    $ apt install lz4
    ```

    - Decompress `python-wasm-sdk`. After this step, you should have `/opt/python-wasm-sdk`.
    ```sh
    $ 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.
    ```sh
    $ git clone https://github.com/kadir014/nova-physics-python.git
    $ cd nova-physics-python
    ```

    - Use the cross-compiler to build the pygbag wheels.
    ```sh
    $ /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.