Skip to content

Commit

Permalink
bump sdk, add 3.14
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Oct 19, 2024
1 parent 70dd152 commit e96269d
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 41 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down Expand Up @@ -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
Expand Down
51 changes: 43 additions & 8 deletions packages.d/pygame/pygame.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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 "
================= forcing Cython git instead of 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}
NO_CYTHON_COMPILE=true $HPY -m pip install --upgrade --force --no-build-isolation ${CYTHON_URL}
else
echo "
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 <<END
diff --git a/src_c/cython/pygame/_sdl2/audio.pyx b/src_c/cython/pygame/_sdl2/audio.pyx
index c3667d5e3..dfe85fb72 100644
--- a/src_c/cython/pygame/_sdl2/audio.pyx
+++ b/src_c/cython/pygame/_sdl2/audio.pyx
@@ -68,7 +68,7 @@ def get_audio_device_names(iscapture = False):
return names
import traceback
-cdef void recording_cb(void* userdata, Uint8* stream, int len) nogil:
+cdef int recording_cb(void* userdata, Uint8* stream, int len) nogil:
""" This is called in a thread made by SDL.
So we need the python GIL to do python stuff.
"""
diff --git a/src_c/cython/pygame/_sdl2/mixer.pyx b/src_c/cython/pygame/_sdl2/mixer.pyx
index ebc23b992..c70cebab6 100644
--- a/src_c/cython/pygame/_sdl2/mixer.pyx
+++ b/src_c/cython/pygame/_sdl2/mixer.pyx
@@ -14,7 +14,7 @@ import traceback
# Mix_SetPostMix(noEffect, NULL);
-cdef void recording_cb(void* userdata, Uint8* stream, int len) nogil:
+cdef int recording_cb(void* userdata, Uint8* stream, int len) nogil:
""" This is called in a thread made by SDL.
So we need the python GIL to do python stuff.
"""
END


patch -p1 <<END
diff --git a/src_c/key.c b/src_c/key.c
index 3a2435d2..a353c24f 100644
Expand Down Expand Up @@ -195,7 +230,7 @@ fi
if ${CI:-false}
then
touch $(find | grep pxd$)
if PYTHON_GIL=0 $HPY setup.py cython_only
if $HPY setup.py cython_only
then
echo -n
else
Expand Down Expand Up @@ -238,9 +273,9 @@ rm -rf /opt/python-wasm-sdk/emsdk/upstream/emscripten/cache/sysroot/include/SDL
[ -f Setup ] && rm Setup
[ -f ${SDKROOT}/prebuilt/emsdk/libpygame${PYBUILD}.a ] && rm ${SDKROOT}/prebuilt/emsdk/libpygame${PYBUILD}.a

if PYTHON_GIL=0 $SDKROOT/python3-wasm setup.py -config -auto -sdl2
if $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
$SDKROOT/python3-wasm setup.py build -j1 || echo "encountered some build errors" 1>&2

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

Expand Down
26 changes: 14 additions & 12 deletions scripts/build-loader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -323,7 +326,7 @@ then
PG=/pgdata
cat > final_link.sh <<END
#!/bin/bash
emcc \\
emcc -sENVIRONMENT=web \\
$FINAL_OPTS \\
$LOPTS \\
-D__PYDK__=1 -DNDEBUG \\
Expand All @@ -340,12 +343,11 @@ emcc \\
-o ${DIST_DIR}/${DISTRO}${PYMAJOR}${PYMINOR}/${MODE}.js build/${MODE}.o \\
$LDFLAGS
END
chmod +x ./final_link.sh
if ./final_link.sh
then
rm build/${MODE}.o
#rm build/${MODE}.o
du -hs ${DIST_DIR}/*
echo Total
echo _________
Expand Down
6 changes: 5 additions & 1 deletion scripts/build-rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ $HPY -u -I -B <<END
import sys, os
stdlp=""
if os.environ.get('PYBUILD','')=='3.13':
threading_model = os.popen('${HPY}-config --abiflags').read().strip()
if 't' in threading_model:
SCD="_sysconfigdata_t"
else:
SCD="_sysconfigdata_"
Expand Down
2 changes: 1 addition & 1 deletion src/pygbag/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

DEFAULT_SCRIPT = "main.py"
DEFAULT_CONSOLE = 25
DEFAULT_LINES = 57
DEFAULT_LINES = 50
DEFAULT_COLUMNS = 132
DEFAULT_PYBUILD = "3.12"

Expand Down
10 changes: 6 additions & 4 deletions src/pygbag/support/cross/aio/pep0723.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
sys.path.append(sconf["platlib"])

PATCHLIST = []

# fast skip list
HISTORY = ["pyodide"]
HISTORY = ["pyodide", "pytest", "pytest-ruff", "ruff"]

hint_failed = []

Expand Down Expand Up @@ -315,9 +316,10 @@ async def pip_install(pkg, sysconf={}):
wheel_url = ""

# hack for WASM wheel repo
if pkg.lower() in Config.mapping:
pkg = Config.mapping[pkg.lower()]
print("294: package renamed to", pkg)
remap = pkg.lower().replace('-','_')
if remap in Config.mapping:
pkg = Config.mapping[remap]
print(f"294: {remap} package renamed to {pkg}")

if pkg in HISTORY:
print(f"# 322: pip_install: {pkg} already installed")
Expand Down
4 changes: 2 additions & 2 deletions static/default.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
print("""
Loading {{cookiecutter.title}} from {{cookiecutter.archive}}.apk
Pygbag Version : {{cookiecutter.version}}
Template Version : 0.9.2
Template Version : 0.9.3
Python : {{cookiecutter.PYBUILD}}
CDN URL : {{cookiecutter.cdn}}
Screen : {{cookiecutter.width}}x{{cookiecutter.height}}
Expand Down Expand Up @@ -256,7 +256,7 @@ config = {
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes"/>

<link rel="prefetch" href="{{cookiecutter.cdn}}pythonrc.py">
<link rel="prefetch" href="{{cookiecutter.cdn}}cpythonrc.py">
<link rel="prefetch" href="{{cookiecutter.cdn}}vt/xterm.js">
<link rel="prefetch" href="{{cookiecutter.cdn}}vt/xterm-addon-image.js">

Expand Down
4 changes: 1 addition & 3 deletions static/pythons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -910,7 +909,6 @@ console.log(" @@@@@@@@@@@@@@@@@@@@@@ 3D CANVAS @@@@@@@@@@@@@@@@@@@@@@")




function readFileAsArrayBuffer(file, success, error) {
const fr = new FileReader();
fr.addEventListener('error', error, false);
Expand Down Expand Up @@ -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
Expand Down
52 changes: 45 additions & 7 deletions support/__EMSCRIPTEN__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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()) {
Expand Down

0 comments on commit e96269d

Please sign in to comment.