From e96269db8cbdbb09ea0d0a43a2cb93d525dfad73 Mon Sep 17 00:00:00 2001 From: pmp-p Date: Sat, 19 Oct 2024 02:18:24 +0200 Subject: [PATCH] bump sdk, add 3.14 --- .github/workflows/ci.yml | 17 ++++++-- packages.d/pygame/pygame.sh | 51 ++++++++++++++++++++---- scripts/build-loader.sh | 26 +++++++------ scripts/build-rootfs.sh | 6 ++- src/pygbag/app.py | 2 +- src/pygbag/support/cross/aio/pep0723.py | 10 +++-- static/default.tmpl | 4 +- static/pythons.js | 4 +- support/__EMSCRIPTEN__.c | 52 +++++++++++++++++++++---- 9 files changed, 131 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81e133a..b4ca13d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,14 +6,14 @@ jobs: build: runs-on: ubuntu-22.04 env: - SDK_VERSION: 3.1.69.0bi + SDK_VERSION: 3.1.70.6bi SYS_PYTHON: /usr/bin/python3 PACKAGES: emsdk hpy pygame BUILD_STATIC: emsdk hpy STATIC: false - BUILDS: 3.12 3.13 + BUILDS: 3.12 3.13 3.14 CYTHON: Cython-3.0.11-py2.py3-none-any.whl - LD_VENDOR: -sUSE_GLFW=3 +# LD_VENDOR: -sUSE_GLFW=3 steps: - uses: actions/checkout@v4.1.0 @@ -68,6 +68,17 @@ jobs: cd $GITHUB_WORKSPACE PYBUILD=3.13 bash ./scripts/build-loader.sh + - name: build 3.14 packages + run: | + cd $GITHUB_WORKSPACE + PYBUILD=3.14 bash ./scripts/build-pkg.sh + + - name: build 3.14 loader + run: | + cd $GITHUB_WORKSPACE + PYBUILD=3.14 bash ./scripts/build-loader.sh + + - name: build PkPy loader run: | cd $GITHUB_WORKSPACE diff --git a/packages.d/pygame/pygame.sh b/packages.d/pygame/pygame.sh index 42e434b..ad7765e 100755 --- a/packages.d/pygame/pygame.sh +++ b/packages.d/pygame/pygame.sh @@ -35,7 +35,7 @@ then echo " * upgrading cython $TEST_CYTHON to at least 3.0.11 " 1>&2 - if echo $PYBUILD|grep -q 3\\.13$ + if [ ${PYMINOR} -ge 13 ] then echo " @@ -43,7 +43,7 @@ then " # /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} + NO_CYTHON_COMPILE=true $HPY -m pip install --upgrade --force --no-build-isolation ${CYTHON_URL} else echo " @@ -60,7 +60,11 @@ then fi fi -echo "cython ? $(PYTHON_GIL=0 $HPY -m cython -V 2>&1)" +# PYTHON_GIL=0 +# Fatal Python error: config_read_gil: Disabling the GIL is not supported by this build +# Python runtime state: preinitialized + +echo "cython ? $( $HPY -m cython -V 2>&1)" mkdir -p external @@ -95,8 +99,8 @@ then #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 + # 313t controller fix merged + # 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 @@ -114,6 +118,37 @@ then # wget -O- https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/2426.diff | patch -p1 + # remove cython/gil warnings + patch -p1 <&2 + $SDKROOT/python3-wasm setup.py build -j1 || echo "encountered some build errors" 1>&2 OBJS=$(find build/temp.wasm32-*/|grep o$) diff --git a/scripts/build-loader.sh b/scripts/build-loader.sh index 445d188..d907b4e 100755 --- a/scripts/build-loader.sh +++ b/scripts/build-loader.sh @@ -252,7 +252,7 @@ if emcc -fPIC -std=gnu99 -D__PYDK__=1 -DNDEBUG $MIMALLOC $CPY_CFLAGS $CF_SDL $CP -I${PYDIR}/internal -I${PYDIR} -I./support -I./external/hpy/hpy/devel/include -DPy_BUILD_CORE \ -o build/${MODE}.o support/__EMSCRIPTEN__-pymain.c then - if echo $PYBUILD | grep -q 13$ + if ${HPY}-config --abiflags| grep -q t$ then STDLIBFS="--preload-file build/stdlib-rootfs/python${PYBUILD}t@/usr/lib/python${PYBUILD}t" else @@ -268,24 +268,19 @@ then # TODO: test -sWEBGL2_BACKWARDS_COMPATIBILITY_EMULATION -# +# --use-port=contrib.glfw3 LDFLAGS="-sUSE_GLFW=3 -sUSE_WEBGL2 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT=1 -sFULL_ES2 -sFULL_ES3" + LDFLAGS="-sUSE_WEBGL2 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT=1 -sFULL_ES2 -sFULL_ES3" - # LDFLAGS="$LDFLAGS -lSDL2 -lSDL2_image -lSDL2_mixer_ogg -logg -lvorbis -lwebpdecoder -lfreetype" LDFLAGS="-L${SDKROOT}/devices/emsdk/usr/lib $LDFLAGS -lssl -lcrypto -lsqlite3 -lffi -lbz2 -lz -ldl -lm" LINKPYTHON="python mpdec expat" - if echo $PYBUILD|grep -q 3.12 + if [ ${PYMINOR} -ge 12 ] then LINKPYTHON="Hacl_Hash_SHA2 $LINKPYTHON" - else - if echo $PYBUILD|grep -q 3.13 - then - LINKPYTHON="Hacl_Hash_SHA2 $LINKPYTHON" - fi fi for lib in $LINKPYTHON @@ -299,6 +294,14 @@ then fi done + # 3.13 and up may rely on system mpdec + if echo $LDFLAGS|grep libmpdec + then + echo -n + else + LDFLAGS="$LDFLAGS -lmpdec" + fi + for lib in $PACKAGES do @@ -323,7 +326,7 @@ then PG=/pgdata cat > final_link.sh < - + diff --git a/static/pythons.js b/static/pythons.js index 14524e1..26e61be 100644 --- a/static/pythons.js +++ b/static/pythons.js @@ -864,7 +864,6 @@ console.warn("TODO: user defined canvas") } function window_resize_3d(gui_divider) { -console.log(" @@@@@@@@@@@@@@@@@@@@@@ 3D CANVAS @@@@@@@@@@@@@@@@@@@@@@") setTimeout(window_canvas_adjust_3d, 200, gui_divider); setTimeout(window.focus, 300); } @@ -910,7 +909,6 @@ console.log(" @@@@@@@@@@@@@@@@@@@@@@ 3D CANVAS @@@@@@@@@@@@@@@@@@@@@@") - function readFileAsArrayBuffer(file, success, error) { const fr = new FileReader(); fr.addEventListener('error', error, false); @@ -1067,7 +1065,7 @@ async function feat_vtx(debug_hidden) { const { WasmTerminal } = await import("./vtx.js") const lines = get_terminal_lines() + cons // including virtual get_terminal_console() const py = window.document.body.clientHeight - var fntsize = Math.floor(py/lines) - 1 + var fntsize = Math.floor(py/lines) - 3 if (lines<=33) { fntsize = ( fntsize - 6 ) / console_divider diff --git a/support/__EMSCRIPTEN__.c b/support/__EMSCRIPTEN__.c index 3d16abe..2adc8e6 100644 --- a/support/__EMSCRIPTEN__.c +++ b/support/__EMSCRIPTEN__.c @@ -578,6 +578,23 @@ embed_get_sdl_version(PyObject *self, PyObject *_null) } #endif +#if PY_VERSION_HEX >= 0x030D0000 +# if !defined(Py_GIL_DISABLED) + #pragma message "unsupported Py_LIMITED_API/Py_GIL_DISABLED combination" +EMSCRIPTEN_KEEPALIVE void +_Py_DecRefShared(PyObject *o) { + Py_XDECREF(o); +} +EMSCRIPTEN_KEEPALIVE uintptr_t +_Py_GetThreadLocal_Addr(void) { + return 0; +} +EMSCRIPTEN_KEEPALIVE void +_Py_MergeZeroLocalRefcount(PyObject *op) { + _Py_Dealloc(op); +} +# endif +#endif static PyMethodDef mod_embed_methods[] = { {"run", (PyCFunction)embed_run, METH_VARARGS | METH_KEYWORDS, "start aio stepping"}, @@ -677,7 +694,7 @@ 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 +#if defined(Py_GIL_DISABLED) PyUnstable_Module_SetGIL(embed_mod, Py_MOD_GIL_NOT_USED); #endif @@ -1002,6 +1019,9 @@ main_(int argc, char **argv) #else #define CPY 1 + +//#include "pycore_initconfig.h" // _PyArgv + int main(int argc, char **argv) #endif @@ -1019,11 +1039,15 @@ main(int argc, char **argv) // defaults setenv("LC_ALL", "C.UTF-8", 0); setenv("TERMINFO", "/usr/share/terminfo", 0); - setenv("COLUMNS","132", 0); - setenv("LINES","30", 0); + setenv("COLUMNS", "132", 0); + setenv("LINES", "30", 0); // - setenv("PYGBAG","1", 1); - setenv("PYTHON_GIL","0", 1); + setenv("PYGBAG", "1", 1); + + #if defined(Py_GIL_DISABLED) + setenv("PYTHON_GIL", "0", 1); + #endif + // setenv("PYTHONINTMAXSTRDIGITS", "0", 0); setenv("LANG", "en_US.UTF-8", 0); @@ -1033,9 +1057,9 @@ main(int argc, char **argv) setenv("MPLBACKEND", "Agg", 0); // force - setenv("PYTHONHOME","/usr", 1); + setenv("PYTHONHOME", "/usr", 1); setenv("PYTHONUNBUFFERED", "1", 1); - setenv("PYTHONINSPECT","1",1); + setenv("PYTHONINSPECT", "1",1); setenv("PYTHONDONTWRITEBYTECODE","1",1); setenv("HOME", "/home/web_user", 1); setenv("APPDATA", "/home/web_user", 1); @@ -1044,6 +1068,20 @@ main(int argc, char **argv) setenv("ELECTRIC_TELEMETRY","disabled", 1); setenv("PSYCOPG_WAIT_FUNC", "wait_select", 1); +// rich + setenv("FORCE_COLOR", "1", 1); + +/* + puts(" ---------- pymain_init ------------"); + _PyArgv args = { + .argc = argc, + .use_bytes_argv = 0, + .bytes_argv = NULL, + .wchar_argv = argv + }; + + status = pymain_init(&args); +*/ status = pymain_init(NULL); if (PyErr_Occurred()) {