Skip to content

Commit 4ce6c37

Browse files
committed
b4
1 parent 8d8d115 commit 4ce6c37

File tree

15 files changed

+184
-79
lines changed

15 files changed

+184
-79
lines changed

buildapp.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ TMPL=$(realpath $TMPL)
4242
APK=$(realpath $APK)
4343

4444
mkdir -p prebuilt/emsdk/site-packages
45+
mkdir -p prebuilt/emsdk/lib-dynload
4546

4647
# pre populated site-packages
4748
REQUIREMENTS=$(realpath prebuilt/emsdk/site-packages)
49+
DYNLOAD=$(realpath prebuilt/emsdk/lib-dynload)
50+
51+
mv $ROOT/devices/emsdk/usr/lib/python3.${PYMINOR}/lib-dynload/*.so $DYNLOAD/ 2>/dev/null
4852

4953
# runtime patches on known modules for specific platform
5054
# applies to prebuilt/emsdk/site-packages at preload stage.
@@ -57,8 +61,9 @@ cp -Rf ${PLATFORM}.overlay/* ${REQUIREMENTS}/
5761
CROSS=$(realpath support/cross)
5862

5963

64+
6065
# clean up untested modules
61-
rm -fr $PREFIX/lib/python3.${PYMINOR}/site-packages/*
66+
#rm -fr $PREFIX/lib/python3.${PYMINOR}/site-packages/*
6267
touch $(echo -n $PREFIX/lib/python3.${PYMINOR}/site-packages)/README.txt
6368

6469

@@ -227,16 +232,28 @@ STDLIBFS="--preload-file $PYTHONPYCACHEPREFIX/stdlib-coldstart/python3.${PYMINOR
227232

228233
# --preload-file /usr/share/terminfo/x/xterm@/usr/share/terminfo/x/xterm \
229234

235+
236+
237+
CPY_EXTRALIB=""
238+
for cpylib in Modules/_decimal/libmpdec/libmpdec.a Modules/expat/libexpat.a
239+
do
240+
[ -f $cpylib ] && CPY_EXTRALIB="$CPY_EXTRALIB $cpylib"
241+
done
242+
243+
244+
230245
time emcc $FINAL_OPTS $LOPTS -std=gnu99 -D__PYDK__=1 -DNDEBUG\
231246
-s TOTAL_MEMORY=512MB -s ALLOW_TABLE_GROWTH \
232247
-s USE_BZIP2=1 -s USE_ZLIB=1 $CF_SDL \
233248
--use-preload-plugins \
234249
$STDLIBFS \
235250
$ALWAYS_FS \
251+
--preload-file ${DYNLOAD}@/usr/lib/python3.${PYMINOR}/lib-dynload \
236252
--preload-file ${CROSS}@/data/data/org.python/assets/site-packages \
237253
--preload-file ${REQUIREMENTS}@/data/data/org.python/assets/site-packages \
238254
--preload-file $ROOT/support/xterm@/etc/termcap \
239-
-o ${MODE}.js Programs/${MODE}.o ${ROOT}/prebuilt/emsdk/libpython3.*.a Modules/_decimal/libmpdec/libmpdec.a Modules/expat/libexpat.a \
255+
-o ${MODE}.js Programs/${MODE}.o ${ROOT}/prebuilt/emsdk/libpython3.${PYMINOR}.a \
256+
$CPY_EXTRALIB \
240257
${ROOT}/prebuilt/emsdk/libpygame.a $CFLDPFX -lffi -lSDL2_gfx -lSDL2_mixer -lwebp \
241258
$LD_SDL -ldl -lm
242259

config

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
#!/bin/bash
22
export LC_ALL=C
3-
export ROOT=${ROOT:-/opt/python-wasm-sdk}
3+
export ROOT=$(pwd)
4+
export SDKROOT=${SDKROOT:-$ROOT}
45

56
export PYTHONDONTWRITEBYTECODE=1
67
export REBUILD=${REBUILD:-false}
78
export CI=${CI:-false}
89

9-
export HOST_PREFIX=${HOST_PREFIX:-$ROOT/devices/$(arch)/usr}
10-
export PREFIX=${PREFIX:-${ROOT}/devices/emsdk/usr}
11-
export PYTHONPYCACHEPREFIX=$(realpath ${ROOT}/build/pycache)
10+
export PYBUILD=${PYBUILD:-3.11}
11+
12+
export HOST_PREFIX=${HOST_PREFIX:-${SDKROOT}/devices/$(arch)/usr}
13+
export PREFIX=${PREFIX:-${SDKROOT}/devices/emsdk/usr}
14+
export PYTHONPYCACHEPREFIX=$(realpath ${SDKROOT}/build/pycache)
1215

1316
export PYMAJOR=3
14-
export HPY=$(echo -n ${HOST_PREFIX}/bin/python3.1?)
15-
export PYMINOR=$(echo $HPY|cut -d. -f2)
16-
export PIP=${HOST_PREFIX}/bin/pip3.${PYMINOR}
1717

18-
# this is python used for emsdk
18+
export HPY=${HOST_PREFIX}/bin/python${PYBUILD}
19+
20+
if [ -f $HPY ]
21+
then
22+
echo -n # host python has been built successfully
23+
else
24+
export HPY=$(ls ${HOST_PREFIX}/bin/python3.?? 2>/dev/null | sort | tail -n 1)
25+
fi
26+
27+
if [ -f $HPY ]
28+
then
29+
export PYMINOR=$(echo $HPY|cut -d. -f2)
30+
export PIP=${HOST_PREFIX}/bin/pip3.${PYMINOR}
31+
fi
32+
33+
# this is python used for emsdk : ${SYS_PYTHON} -> ${EMSDK_PYTHON}
1934
for py in 10 9 8 7
2035
do
2136
if command -v python3.${py} >/dev/null
@@ -69,3 +84,4 @@ else
6984
export PATH="${HOST_PREFIX}/bin:$PATH"
7085
export PYDK=minimal
7186
fi
87+

python-wasm-sim.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ export __FILE__="$1"
2424
cat $ROOT/support/cross/aio/simulator.py | envsubst > $ROOT/build/pycache/.pythonrc.py
2525

2626
unset PYTHONHOME
27+
unset _PYTHON_SYSCONFIGDATA_NAME
2728

28-
export PYTHONSTARTUP=$ROOT/build/pycache/.pythonrc.py
2929
export PYTHONPATH=$(pwd):$ROOT/support/cross:$ROOT/support/sim.links:$PYTHONPATH
3030

31+
export _PYTHON_SYSCONFIGDATA_NAME=$($ROOT/devices/$(arch)/usr/bin/python3 -c 'import sys;print(f"""_sysconfigdata_{sys.abiflags}_{sys.platform}_{getattr(sys.implementation, "_multiarch", "")}""")')
32+
echo "_PYTHON_SYSCONFIGDATA_NAME=$_PYTHON_SYSCONFIGDATA_NAME"
33+
34+
export PYTHONSTARTUP=$ROOT/build/pycache/.pythonrc.py
35+
3136

3237
if false
3338
then

scripts/cpython-build-host-deps.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,26 @@ echo "
99
# python3 setup.py install --single-version-externally-managed --root=/
1010
SPY="$HPY setup.py install --single-version-externally-managed --root=/"
1111

12+
1213
# just in case
1314
$PIP install pip --upgrade
1415

15-
# to remove ctypes deps
16-
$PIP install setuptools --upgrade
17-
18-
HPFX=./devices/x86_64/usr/lib/python3.${PYMINOR}
19-
rm $HPFX/ensurepip/_bundled/setuptools-*-py3-none-any.whl
20-
mv $HPFX/site-packages/setuptool* $HPFX/
21-
mv $HPFX/site-packages/_distutils* $HPFX/
22-
mv $HPFX/site-packages/pkg_resources $HPFX/
2316

17+
if [ -d $HPFX/site-packages/setuptools ]
18+
then
19+
echo "
20+
* setuptools/_distutils/pkg_resources already migrated
21+
"
22+
else
23+
# to remove ctypes deps
24+
$PIP install setuptools --upgrade
25+
26+
HPFX=./devices/x86_64/usr/lib/python3.${PYMINOR}
27+
rm $HPFX/ensurepip/_bundled/setuptools-*-py3-none-any.whl
28+
mv $HPFX/site-packages/setuptools* $HPFX/
29+
mv $HPFX/site-packages/_distutils* $HPFX/
30+
mv $HPFX/site-packages/pkg_resources* $HPFX/
31+
fi
2432

2533

2634
export CC=clang

scripts/cpython-build-host.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mkdir -p build/cpython-host
99
if $REBUILD
1010
then
1111
echo "
12-
* building cpython
12+
* building cpython $PYBUILD $CIVER
1313
"
1414
else
1515
if [ -f ${PYTHON_FOR_BUILD} ]

scripts/cpython-fetch.sh

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33
. ${CONFIG:-config}
44

55
echo "
6-
*cpython-fetch*
6+
*cpython-fetch $PYBUILD*
77
"
88

99

1010
pushd src 2>&1 >/dev/null
1111

12-
1312
NOPATCH=false
13+
[ -L cpython ] && rm cpython
1414

15-
if false
15+
if echo $PYBUILD |grep -q 12$
1616
then
17-
18-
# same goal as "python-wasm/fetch-python.sh"
19-
# get python from git ( actually the only one supporting emsdk without patches)
20-
21-
if [ -d cpython ]
17+
if [ -d cpython-git ]
2218
then
23-
pushd cpython 2>&1 >/dev/null
19+
pushd cpython-git 2>&1 >/dev/null
2420
# put the tree back to original state so we can pull
2521
# Programs/python.c Modules/readline.c
2622
git restore .
@@ -35,41 +31,55 @@ then
3531
#cat $ROOT/support/compilenone.py > ./Lib/compileall.py
3632
popd
3733
else
38-
git clone https://github.com/python/cpython.git
34+
git clone --depth 1 https://github.com/python/cpython.git cpython-git
3935
export REBUILD=true
4036
fi
4137

42-
else
43-
if [ -L cpython ]
44-
then
45-
echo "
46-
* cpython source tree already linked $(file cpython)"
47-
NOPATCH=true
48-
else
49-
wget -q -c https://www.python.org/ftp/python/3.11.0/Python-3.11.0b3.tgz
50-
tar xf Python-3.11.0b3.tgz
51-
ln -s Python-3.11.0b3 cpython
52-
fi
38+
ln -s cpython-git cpython
39+
5340
fi
5441

42+
if echo $PYBUILD | grep -q 11$
43+
then
44+
#wget -q -c https://www.python.org/ftp/python/3.11.0/Python-3.11.0b3.tgz
45+
wget -q https://www.python.org/ftp/python/3.11.0/Python-3.11.0b4.tar.xz
46+
47+
#tar xf Python-3.11.0b3.tgz
48+
tar xf Python-3.11.0b4.tar.xz
49+
#ln -s Python-3.11.0b3 cpython
50+
ln -s Python-3.11.0b4 cpython
51+
export REBUILD=true
52+
fi
53+
54+
if echo $PYBUILD | grep -q 10$
55+
then
56+
tar xfj /data/git/python-wasm-sdk/src/Python-3.10.5-pydk.tar.bz2
57+
ln -s Python-3.10.5-pydk cpython
58+
NOPATCH=true
59+
export REBUILD=true
60+
fi
61+
62+
5563
popd
5664

65+
5766
if $NOPATCH
5867
then
5968
echo "
6069
* assuming cpython tree already patched, press <enter>
6170
"
62-
63-
6471
else
6572
# do some patching
6673
pushd src/cpython 2>&1 >/dev/null
6774
patch -p1 < ../../support/__EMSCRIPTEN__.embed/cpython.diff
6875
popd
6976
fi
7077

78+
7179
echo "
7280
* fetched cpython source, status is :
7381
REBUILD=${REBUILD}
7482
"
7583

84+
[ -d build/cpython-host ] && rm -rf build/cpython-host
85+
[ -d build/cpython-wasm ] && rm -rf build/cpython-wasm

scripts/emsdk-fetch.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ then
3232
* activating emsdk via emsdk_env.sh
3333
"
3434
. emsdk/emsdk_env.sh 2>&1 > /dev/null
35-
35+
export EMSDK_PYTHON=$SYS_PYTHON
3636
else
3737
echo "
3838
ERROR cannot find emsdk/emsdk_env.sh in $(pwd)
@@ -135,9 +135,9 @@ done
135135
136136
if \$IS_SHARED
137137
then
138-
\$SYS_PYTHON -E \$0.py $SHARED $LDFLAGS "\$@" $COMMON
138+
\$EMSDK_PYTHON -E \$0.py $SHARED $LDFLAGS "\$@" $COMMON
139139
else
140-
\$SYS_PYTHON -E \$0.py $CPPFLAGS "\$@" $COMMON
140+
\$EMSDK_PYTHON -E \$0.py $CPPFLAGS "\$@" $COMMON
141141
fi
142142
END
143143
cat emsdk/upstream/emscripten/emcc > emsdk/upstream/emscripten/em++
@@ -149,14 +149,14 @@ unset _PYTHON_SYSCONFIGDATA_NAME
149149
unset PYTHONHOME
150150
unset PYTHONPATH
151151
152-
\$SYS_PYTHON -E \$0.py "\$@"
152+
\$EMSDK_PYTHON -E \$0.py "\$@"
153153
END
154154

155155
cat emsdk/upstream/emscripten/emar > emsdk/upstream/emscripten/emcmake
156156

157157
cat > emsdk/upstream/emscripten/emconfigure <<END
158158
#!/bin/bash
159-
\$SYS_PYTHON -E \$0.py "\$@"
159+
\$EMSDK_PYTHON -E \$0.py "\$@"
160160
END
161161

162162
chmod +x emsdk/upstream/emscripten/em*

scripts/make_coldstartfs.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ try:
2929
except:
3030
pass
3131
32+
# for dom event subscriptions
33+
import webbrowser
34+
35+
# pygame_gui
36+
import html.parser
37+
import importlib.readers
38+
3239
#pymunk tests
3340
import unittest, locale
3441

scripts/pygame-all.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ then
99
"
1010
else
1111
pushd src
12-
#git clone -b pygame-wasm-upstream https://github.com/pmp-p/pygame-wasm pygame-wasm
13-
git clone https://github.com/pygame/pygame pygame-wasm
12+
if echo $GITHUB_WORKSPACE|grep -q /python-wasm-plus/
13+
then
14+
# pygame-wasm testing
15+
git clone -b pygame-wasm https://github.com/pmp-p/pygame-wasm pygame-wasm
16+
else
17+
# git pygame
18+
git clone https://github.com/pygame/pygame pygame-wasm
19+
fi
1420
popd
1521
fi
1622

@@ -34,7 +40,7 @@ pushd src/pygame-wasm 2>&1 >/dev/null
3440
if [ -f dev ]
3541
then
3642
#TODO: $HPY setup.py cython config
37-
python3 setup.py config cython
43+
python3 setup.py cython_only
3844
fi
3945

4046

support/__EMSCRIPTEN__.overlay/pygame/wasm_patches.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def patch_set_timer(cust_event_no, millis, loops=0):
2323
dlay = float(millis) / 1000
2424
cevent = pygame.event.Event(cust_event_no)
2525
async def fire_event():
26-
while not aio.exit:
26+
while true:
2727
await asyncio.sleep( dlay )
28+
if aio.exit:
29+
break
2830
pygame.event.post(cevent)
2931
Thread(target=fire_event).start()
3032

0 commit comments

Comments
 (0)