Skip to content

Commit

Permalink
3.13t testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Oct 2, 2024
1 parent 0504945 commit 43a8821
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
runs-on: ubuntu-22.04
env:
SDK_VERSION: 3.1.68.0bi
SDK_VERSION: 3.1.69.0bi
SYS_PYTHON: /usr/bin/python3
PACKAGES: emsdk hpy pygame
BUILD_STATIC: emsdk hpy
Expand Down
181 changes: 101 additions & 80 deletions packages.d/pygame/pygame.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,59 @@ echo "
" 1>&2

sed -i 's|check.warn(importable)|pass|g' ${HOST_PREFIX}/lib/python3.13/site-packages/setuptools/command/build_py.py


CYTHON=${CYTHON:-Cython-3.0.10-py2.py3-none-any.whl}
if echo $GITHUB_WORKSPACE|grep wip

if ${CI:-false}
then
DEV=true
else
DEV=${DEV:-false}
CYTHON_URL=git+https://github.com/pygame-web/cython.git

# update cython
TEST_CYTHON=$($HPY -m cython -V 2>&1)
if echo $TEST_CYTHON| grep -q 3.1.0a0$
CYTHON=${CYTHON:-Cython-3.0.11-py2.py3-none-any.whl}
if echo $GITHUB_WORKSPACE|grep wip
then
echo " * not upgrading cython $TEST_CYTHON
" 1>&2
DEV=true
else
echo " * upgrading cython $TEST_CYTHON to 3.0.10
" 1>&2
DEV=${DEV:-false}

if echo $PYBUILD|grep -q 3.13$
# update cython
TEST_CYTHON=$($HPY -m cython -V 2>&1)
if echo $TEST_CYTHON| grep -q 3\\.1\\.0a0$
then
echo "
echo " * not upgrading cython $TEST_CYTHON
" 1>&2
else
echo " * upgrading cython $TEST_CYTHON to 3.0.10
" 1>&2

================= forcing Cython git instead of release ${CYTHON} =================
if echo $PYBUILD|grep -q 3\\.13$
then
echo "
"
$HPY -m pip install --upgrade --force git+https://github.com/cython/cython.git
/opt/python-wasm-sdk/python3-wasm -m pip install --upgrade --force --no-build-isolation --force git+https://github.com/cython/cython.git
else
echo "
================= forcing Cython git instead of release ${CYTHON} =================
================= Using Cython release ${CYTHON} =================
"
# /opt/python-wasm-sdk/python3-wasm -m pip install --upgrade --force --no-build-isolation git+${CYTHON_URL}
$HPY -m pip install --upgrade --force --no-build-isolation ${CYTHON_URL}
else
echo "
"
pushd build
wget -q -c https://github.com/cython/cython/releases/download/3.0.10/${CYTHON}
$HPY -m pip install $CYTHON
popd
fi
================= Using Cython release ${CYTHON} =================
"
pushd build
wget -q -c https://github.com/cython/cython/releases/download/3.0.11-1/${CYTHON}
$HPY -m pip install $CYTHON
/opt/python-wasm-sdk/python3-wasm -m pip install --upgrade --force $CYTHON
popd
fi

fi
fi
fi

echo "cython ? $(PYTHON_GIL=0 $HPY -m cython -V 2>&1)"


mkdir -p external
pushd $(pwd)/external
Expand All @@ -86,14 +96,19 @@ then
# to upstream after tests
# done wget -O- https://patch-diff.githubusercontent.com/raw/pmp-p/pygame-ce-wasm/pull/7.diff | patch -p1




# unsure : wasm pygame.freetype hack
#wget -O- https://patch-diff.githubusercontent.com/raw/pmp-p/pygame-ce-wasm/pull/3.diff | patch -p1
wget -O- https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/1967.diff | patch -p1

# 313t controller fix
wget -O- https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/3137.diff | patch -p1

# new cython (git)
wget -O- https://patch-diff.githubusercontent.com/raw/pmp-p/pygame-ce-wasm/pull/8.diff | patch -p1


# added Vector2.from_polar and Vector3.from_spherical classmethods
# breaks, left a review !
# wget -O- https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/2141.diff | patch -p1
Expand All @@ -106,6 +121,7 @@ then
# zerodiv mixer.music / merged
# wget -O- https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/2426.diff | patch -p1


patch -p1 <<END
diff --git a/src_c/key.c b/src_c/key.c
index 3a2435d2..a353c24f 100644
Expand Down Expand Up @@ -184,75 +200,78 @@ fi
rm -rf build Setup
# ===================



pwd
env|grep PY

touch $(find | grep pxd$)
if $HPY setup.py cython_only
if ${CI:-false}
then
# do not link -lSDL2 some emmc versions will think .so will use EM_ASM
#SDL_IMAGE="-s USE_SDL=2 -lfreetype -lwebp"
SDL_IMAGE="-lSDL2 -lfreetype -lwebp"
touch $(find | grep pxd$)
if PYTHON_GIL=0 $HPY setup.py cython_only
then
echo -n
else
echo "cythonize failed" 1>&2
exit 208
fi
else
echo "skipping cython regen"
fi

export CFLAGS="-DSDL_NO_COMPAT $SDL_IMAGE"
EMCC_CFLAGS="-I${SDKROOT}/emsdk/upstream/emscripten/cache/sysroot/include/freetype2"
EMCC_CFLAGS="$EMCC_CFLAGS -I$PREFIX/include/SDL2"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-unused-command-line-argument"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-unreachable-code-fallthrough"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-unreachable-code"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-parentheses-equality"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-unknown-pragmas"
#$HPY ${WORKSPACE}/src/replacer.py --go "Py_GIL_DISABLED'\): raise ImportError" "Py_GIL_DISABLED'): print(__name__)"

# do not link -lSDL2 some emmc versions will think .so will use EM_ASM
#SDL_IMAGE="-s USE_SDL=2 -lfreetype -lwebp"
SDL_IMAGE="-lSDL2 -lfreetype -lwebp"

# FIXME 3.13
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-deprecated-declarations"
export CFLAGS="-DSDL_NO_COMPAT $SDL_IMAGE"
EMCC_CFLAGS="-I${SDKROOT}/emsdk/upstream/emscripten/cache/sysroot/include/freetype2"
EMCC_CFLAGS="$EMCC_CFLAGS -I$PREFIX/include/SDL2"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-unused-command-line-argument"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-unreachable-code-fallthrough"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-unreachable-code"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-parentheses-equality"
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-unknown-pragmas"


# FIXME 3.13
EMCC_CFLAGS="$EMCC_CFLAGS -Wno-deprecated-declarations"

export EMCC_CFLAGS="$EMCC_CFLAGS -DHAVE_STDARG_PROTOTYPES -DBUILD_STATIC -ferror-limit=1 -fpic"

export CC=emcc

# remove SDL1 for good
rm -rf /opt/python-wasm-sdk/emsdk/upstream/emscripten/cache/sysroot/include/SDL
export EMCC_CFLAGS="$EMCC_CFLAGS -DHAVE_STDARG_PROTOTYPES -DBUILD_STATIC -ferror-limit=1 -fpic"

[ -d build ] && rm -r build
[ -f Setup ] && rm Setup
[ -f ${SDKROOT}/prebuilt/emsdk/libpygame${PYBUILD}.a ] && rm ${SDKROOT}/prebuilt/emsdk/libpygame${PYBUILD}.a
export CC=emcc

if $SDKROOT/python3-wasm setup.py -config -auto -sdl2
then
$SDKROOT/python3-wasm setup.py build -j1 || echo "encountered some build errors" 1>&2
# remove SDL1 for good
rm -rf /opt/python-wasm-sdk/emsdk/upstream/emscripten/cache/sysroot/include/SDL

[ -d build ] && rm -r build
[ -f Setup ] && rm Setup
[ -f ${SDKROOT}/prebuilt/emsdk/libpygame${PYBUILD}.a ] && rm ${SDKROOT}/prebuilt/emsdk/libpygame${PYBUILD}.a

OBJS=$(find build/temp.wasm32-*/|grep o$)
if PYTHON_GIL=0 $SDKROOT/python3-wasm setup.py -config -auto -sdl2
then
PYTHON_GIL=0 $SDKROOT/python3-wasm setup.py build -j1 || echo "encountered some build errors" 1>&2

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

$SDKROOT/emsdk/upstream/emscripten/emar rcs ${SDKROOT}/prebuilt/emsdk/libpygame${PYBUILD}.a $OBJS
for obj in $OBJS
do
echo $obj
done

# to install python part (unpatched)
cp -r src_py/. ${PKGDIR:-${SDKROOT}/prebuilt/emsdk/${PYBUILD}/site-packages/pygame/}
$SDKROOT/emsdk/upstream/emscripten/emar rcs ${SDKROOT}/prebuilt/emsdk/libpygame${PYBUILD}.a $OBJS
for obj in $OBJS
do
echo $obj
done

# prepare testsuite
[ -d ${ROOT}/build/pygame-test ] && rm -fr ${ROOT}/build/pygame-test
mkdir ${ROOT}/build/pygame-test
cp -r test ${ROOT}/build/pygame-test/test
cp -r examples ${ROOT}/build/pygame-test/test/
cp ${ROOT}/packages.d/pygame/tests/main.py ${ROOT}/build/pygame-test/
# to install python part (unpatched)
cp -r src_py/. ${PKGDIR:-${SDKROOT}/prebuilt/emsdk/${PYBUILD}/site-packages/pygame/}

else
echo "ERROR: pygame configuration failed" 1>&2
exit 109
fi
# prepare testsuite
[ -d ${ROOT}/build/pygame-test ] && rm -fr ${ROOT}/build/pygame-test
mkdir ${ROOT}/build/pygame-test
cp -r test ${ROOT}/build/pygame-test/test
cp -r examples ${ROOT}/build/pygame-test/test/
cp ${ROOT}/packages.d/pygame/tests/main.py ${ROOT}/build/pygame-test/

else
echo "cythonize failed" 1>&2
exit 114
echo "ERROR: pygame configuration failed" 1>&2
exit 109
fi

popd
Expand All @@ -263,8 +282,10 @@ TAG=${PYMAJOR}${PYMINOR}

echo "FIXME: build wheel"


SDL2="-sUSE_ZLIB=1 -sUSE_BZIP2=1 -sUSE_LIBPNG -sUSE_SDL=2 -sUSE_SDL_MIXER=2 -lSDL2 -L/opt/python-wasm-sdk/devices/emsdk/usr/lib -lSDL2_image -lSDL2_gfx -lSDL2_mixer -lSDL2_mixer_ogg -lSDL2_ttf -lvorbis -logg -lwebp -ljpeg -lpng -lharfbuzz -lfreetype"
SDL2="-sUSE_ZLIB=1 -sUSE_BZIP2=1 -sUSE_LIBPNG"
SDL2="$SDL2 -sUSE_FREETYPE -sUSE_SDL=2 -sUSE_SDL_MIXER=2 -lSDL2 -L/opt/python-wasm-sdk/devices/emsdk/usr/lib"
SDL2="$SDL2 -lSDL2_image -lSDL2_gfx -lSDL2_mixer -lSDL2_mixer_ogg -lSDL2_ttf"
SDL2="$SDL2 -lvorbis -logg -lwebp -lwebpdemux -ljpeg -lpng -lharfbuzz -lfreetype"
SDL2="$SDL2 -lssl -lcrypto -lffi -lbz2 -lz -ldl -lm"


Expand Down
4 changes: 2 additions & 2 deletions scripts/build-loader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ then

LDFLAGS="-sUSE_GLFW=3 -sUSE_WEBGL2 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT=1 -sFULL_ES2 -sFULL_ES3"

LDFLAGS="$LDFLAGS -lsqlite3"
# LDFLAGS="$LDFLAGS -lSDL2 -lSDL2_image -lSDL2_mixer_ogg -logg -lvorbis -lwebpdecoder -lfreetype"

LDFLAGS="-L${SDKROOT}/devices/emsdk/usr/lib $LDFLAGS -lssl -lcrypto -lffi -lbz2 -lz -ldl -lm"
LDFLAGS="-L${SDKROOT}/devices/emsdk/usr/lib $LDFLAGS -lssl -lcrypto -lsqlite3 -lffi -lbz2 -lz -ldl -lm"

LINKPYTHON="python mpdec expat"

Expand Down
2 changes: 1 addition & 1 deletion scripts/vendoring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export PACKAGES=${PACKAGES:-emsdk hpy pygame}

export SDKROOT=${SDKROOT:-/opt/python-wasm-sdk}
export SDK_VERSION=${SDK_VERSION:-3.1.64.1bi}
export CYTHON=${CYTHON:-Cython-3.0.10-py2.py3-none-any.whl}
export CYTHON=${CYTHON:-Cython-3.0.11-py2.py3-none-any.whl}
export PYBUILD=${PYBUILD:-3.12}
export LC_ALL=C

Expand Down
24 changes: 21 additions & 3 deletions support/__EMSCRIPTEN__.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ embed_get_sdl_version(PyObject *self, PyObject *_null)
#endif



static PyMethodDef mod_embed_methods[] = {
{"run", (PyCFunction)embed_run, METH_VARARGS | METH_KEYWORDS, "start aio stepping"},
#if TEST_ASYNCSLEEP
Expand Down Expand Up @@ -622,6 +621,20 @@ static PyMethodDef mod_embed_methods[] = {
{NULL, NULL, 0, NULL}
};


/* later for mphase
static struct PyModuleDef_Slot mod_embed_slots[] = {
#if PY_VERSION_HEX >= 0x030D0000
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
#endif
{0, NULL}
};
#if PY_VERSION_HEX >= 0x030D0000
.m_slots = mod_embed_slots,
#endif
*/


static struct PyModuleDef mod_embed = {
PyModuleDef_HEAD_INIT,
"embed",
Expand Down Expand Up @@ -664,6 +677,9 @@ type_init_failed:;
// helper module for pygbag api not well defined and need clean up.
// callable as "platform" module.
PyObject *embed_mod = PyModule_Create(&mod_embed);
#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(embed_mod, Py_MOD_GIL_NOT_USED);
#endif

// from old aiolink poc
//embed_dict = PyModule_GetDict(embed_mod);
Expand Down Expand Up @@ -1005,7 +1021,9 @@ main(int argc, char **argv)
setenv("TERMINFO", "/usr/share/terminfo", 0);
setenv("COLUMNS","132", 0);
setenv("LINES","30", 0);
//
setenv("PYGBAG","1", 1);
setenv("PYTHON_GIL","0", 1);

// setenv("PYTHONINTMAXSTRDIGITS", "0", 0);
setenv("LANG", "en_US.UTF-8", 0);
Expand All @@ -1026,7 +1044,6 @@ main(int argc, char **argv)
setenv("ELECTRIC_TELEMETRY","disabled", 1);
setenv("PSYCOPG_WAIT_FUNC", "wait_select", 1);


status = pymain_init(NULL);

if (PyErr_Occurred()) {
Expand Down Expand Up @@ -1141,7 +1158,8 @@ EM_ASM({

}, FD_BUFFER_MAX, io_shm[0], io_shm[IO_RAW], io_shm[IO_RCON]);

PyRun_SimpleString("import sys, os, json, builtins, time");
PyRun_SimpleString("import sys, os, json, builtins, time, sysconfig");

PyRun_SimpleString("sys.ps1 = ''");

//PyRun_SimpleString("import hpy;import hpy.universal;print('HPy init done')");
Expand Down
3 changes: 3 additions & 0 deletions support/__EMSCRIPTEN__.embed/browsermodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,9 @@ PyObject *PyInit_browser() {
if (module == NULL) {
return NULL;
}
#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
#endif

Object *window = PyObject_New(Object, &Object_Type);
if (PyModule_AddObject(module, "window", (PyObject *)window) < 0) {
Expand Down
8 changes: 7 additions & 1 deletion support/__EMSCRIPTEN__.embed/emscriptenmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,5 +873,11 @@ extern PyObject *PyInit_emscripten();
#endif

PyObject *PyInit_emscripten() {
return PyModule_Create(&emscripten_module);
#ifdef Py_GIL_DISABLED
PyObject *emscripten_mod = PyModule_Create(&emscripten_module);
PyUnstable_Module_SetGIL(emscripten_mod, Py_MOD_GIL_NOT_USED);
return emscripten_mod;
#else
return PyModule_Create(&emscripten_module);
#endif
}

0 comments on commit 43a8821

Please sign in to comment.