pygame-web / pkg-porting-wasm

Tracks porting efforts on some modules you'd like to have working in pygbag
https://pygame-web.github.io/wiki/pkg/
5 stars 0 forks source link

pygame-ce wheel build (WIP) #20

Open pmp-p opened 1 year ago

pmp-p commented 1 year ago

python-wasm : use pygbag CI

pyodide ( with a pyodide venv ):

#!/bin/bash
TAG=311

REPACK=/data/git/pyodide/packages/pygame-ce/dist/repack

mkdir -p $REPACK
rm $REPACK/../*.whl

. /opt/python-wasm-sdk/wasm32-mvp-emscripten-shell.sh
unset _PYTHON_SYSCONFIGDATA_NAME

cd /data/git/pyodide

[ -f .venv-pyodide/bin/activate ] || pyodide venv .venv-pyodide

source .venv-pyodide/bin/activate
cd packages/pygame-ce

PORTS="-sUSE_SDL=2 -sUSE_SDL_MIXER=2 -sUSE_LIBPNG -sUSE_LIBJPEG -sUSE_SDL_TTF=2"
SDL2_IMAGE="-I/opt/python-wasm-sdk/devices/emsdk/usr/include/SDL2 -L/opt/python-wasm-sdk/devices/emsdk/usr/lib"
SDL2_TTF="-I/opt/python-wasm-sdk/emsdk/upstream/emscripten/cache/sysroot/include/freetype2 -L/opt/python-wasm-sdk/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lSDL2_ttf"

# use bigint
export MVP=false

EMCC_CFLAGS="-sASYNCIFY -sWASM_BIGINT -DBUILD_STATIC -fpic \
 ${SDL2_IMAGE} ${SDL2_TTF} ${PORTS}" \
 PYODIDE_EMSCRIPTEN_VERSION=3.1.34 \
 pyodide build

OBJS=$(find build/temp.emscripten_*/|grep o$)

TARGET=$REPACK/pygame_static.cpython-${TAG}-wasm32-emscripten.so

$SDKROOT/emsdk/upstream/emscripten/emar rcs ${SDKROOT}/prebuilt/emsdk/libpygame${PYBUILD}.a $OBJS
emcc -sWASM_BIGINT -shared -Os -g0 -fpic -o $TARGET $SDKROOT/prebuilt/emsdk/libpygame${PYMAJOR}.${PYMINOR}.a

cd /data/git/pyodide/packages/pygame-ce/dist/repack

unzip -o ../*.whl

grep -v emscripten pygame_ce-2.3.0.dev1.dist-info/RECORD > R
echo "pygame_static.cpython-${TAG}-wasm32-emscripten.so,," >> R
mv R pygame_ce-2.3.0.dev1.dist-info/RECORD

zip ../pygame_ce-2.3.0.dev1-cp311-cp311-emscripten_3_1_34_wasm32.whl -r .

actual result Successfully built /data/git/pyodide/packages/pygame-ce/dist/pygame_ce-2.3.0.dev1-cp311-cp311-emscripten_3_1_34_wasm32.whl

ref: https://pyodide.org/en/stable/development/building-and-testing-packages.html https://github.com/ryanking13/pyodide/blob/94030d71163dbf616b24888a9d99dc3b1b440edd/packages/pygame-ce/meta.yaml

pmp-p commented 1 year ago

i'm quite sure there is a heisenbug in display.init() linked to the way pygame.base is imported ( the wasm part including multiphase init that load all modules at once)

for now pygbag way of loading pygame seems the only "safe" way until pep0723 is adopted