Skip to content

Commit d6a4142

Browse files
committed
support variable PYMINOR
1 parent 9fa6188 commit d6a4142

File tree

13 files changed

+656
-55
lines changed

13 files changed

+656
-55
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@ sudo apt-get install -y git bash python3-pip curl lz4 pv
1111
sudo mkdir -p /opt/python-wasm-sdk && sudo chown $(whoami) /opt/python-wasm-sdk
1212

1313

14-
# in github CI, current working dir would be /home/runner/pygame/pygame.
15-
[ -d ../pygame ] || git clone https://github.com/pygame/pygame
16-
if [ -f setup.py ]
14+
15+
if [ -d ../pygame ]
1716
then
17+
echo " using local tree"
18+
else
19+
git clone https://github.com/pygame/pygame
20+
cd pygame
21+
fi
1822

23+
24+
# in github CI, current working dir would now be /home/runner/pygame/pygame.
25+
if [ -f setup.py ]
26+
then
27+
echo "cannot find pygame source code"
28+
else
1929
# update cython
2030
if [ -f ../dev ]
2131
then

config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ export HOST_PREFIX=${HOST_PREFIX:-$ROOT/devices/$(arch)/usr}
1010
export PREFIX=${PREFIX:-${ROOT}/devices/emsdk/usr}
1111
export PYTHONPYCACHEPREFIX=$(realpath ${ROOT}/build/pycache)
1212

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

1618
# this is python used for emsdk
1719
for py in 10 9 8 7

scripts/cpython-build-emsdk-deps.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
. ./scripts/emsdk-fetch.sh
66

7-
8-
HPFX=./devices/x86_64/usr/lib/python3.11
9-
rm ./devices/emsdk/usr/lib/python3.11/ensurepip/_bundled/setuptools-*-py3-none-any.whl
10-
cp -Rf $HPFX/setuptool* ./devices/emsdk/usr/lib/python3.11/
11-
cp -Rf $HPFX/_distutils* ./devices/emsdk/usr/lib/python3.11/
12-
cp -Rf $HPFX/pkg_resources ./devices/emsdk/usr/lib/python3.11/
13-
7+
# echo " ${PIMINOR}"|grep -q 11$
8+
if true
9+
then
10+
HPFX=./devices/x86_64/usr/lib/python3.${PYMINOR}
11+
rm ./devices/emsdk/usr/lib/python3.${PYMINOR}/ensurepip/_bundled/setuptools-*-py3-none-any.whl
12+
cp -Rf $HPFX/setuptool* ./devices/emsdk/usr/lib/python3.${PYMINOR}/
13+
cp -Rf $HPFX/_distutils* ./devices/emsdk/usr/lib/python3.${PYMINOR}/
14+
cp -Rf $HPFX/pkg_resources ./devices/emsdk/usr/lib/python3.${PYMINOR}/
15+
fi
1416

1517
# ../../devices/x86_64/usr/bin/python3-wasm -mpip install .
1618
# not working because python startup is skipped

scripts/cpython-build-emsdk.sh

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ REBUILD_WASM=${REBUILD_WASMPY:-false}
2525
if $REBUILD || $REBUILD_WASMPY
2626
then
2727
rm -rf build/cpython-wasm/ build/pycache/config.cache
28-
rm build/cpython-wasm/libpython3.??.a 2>/dev/null
28+
rm build/cpython-wasm/libpython3.${PYMINOR}.a 2>/dev/null
2929
REBUILD=true
3030
fi
3131

@@ -96,7 +96,7 @@ TESTSUITE=$TESTSUITE
9696

9797

9898

99-
if [ -f build/cpython-wasm/libpython3.??.a ]
99+
if [ -f build/cpython-wasm/libpython3.${PYMINOR}.a ]
100100
then
101101
echo "
102102
* not rebuilding cpython-wasm for [$PYDK_PYTHON_HOST_PLATFORM]
@@ -133,48 +133,54 @@ else
133133
--prefix=$PREFIX \
134134
--with-build-python=${PYTHON_FOR_BUILD} $QUIET
135135

136+
mkdir -p ${PYTHONPYCACHEPREFIX}/empty
137+
touch ${PYTHONPYCACHEPREFIX}/empty/$($HPY -V|cut -f2 -d' ')
138+
136139
#echo "#define HAVE_NCURSES_H" >> pyconfig.h
140+
cat > Modules/Setup.local <<END
141+
*disabled*
142+
_decimal
143+
END
137144

138-
if EMCC_CFLAGS="-sUSE_ZLIB -sUSE_BZIP2" eval emmake make -j$(nproc) $QUIET
145+
if EMCC_CFLAGS="-sUSE_ZLIB -sUSE_BZIP2" \
146+
emmake make -j$(nproc) WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/
139147
then
140-
EMCC_CFLAGS="-sUSE_ZLIB -sUSE_BZIP2" eval emmake make install $QUIET
148+
EMCC_CFLAGS="-sUSE_ZLIB -sUSE_BZIP2" \
149+
emmake make WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/ install
141150
else
142-
echo " **** cpython wasm build failed *** "
151+
echo " **** cpython wasm build failed ***
152+
153+
EMCC_CFLAGS="-sUSE_ZLIB -sUSE_BZIP2" emmake make WASM_ASSETS_DIR=$(realpath ${PYTHONPYCACHEPREFIX}/empty)@/ install
154+
155+
" 1>&2
156+
143157
exit 1
144158
fi
145159

146-
rm -rf $(find $ROOT/devices/ -type d|grep __pycache__$)
160+
rm -rf $(find $ROOT/devices/ -type d|grep /__pycache__$)
147161

148162
popd
149163

150164
mkdir -p ${ROOT}/prebuilt/emsdk
151165

152166
# move them to MEMFS
153-
mv $PREFIX/lib/python3.??/lib-dynload/* $ROOT/prebuilt/emsdk/site-packages
167+
mv $PREFIX/lib/python3.${PYMINOR}/lib-dynload/* $ROOT/prebuilt/emsdk/site-packages
154168

155169
# specific platform support
156-
cp -Rfv $ROOT/support/__EMSCRIPTEN__.patches/. $HOST_PREFIX/lib/python3.??/
157-
158-
# TODO: use PYTHONPATH for python3-wasm to pick them in devices/emsdk/usr/lib/python3.11/
159-
#ln $PREFIX/lib/python3.??/_sysconfigdata__emscripten_wasm32-emscripten.py devices/x86_64/usr/lib/python3.??/
160-
170+
cp -Rfv $ROOT/support/__EMSCRIPTEN__.patches/3.${PYMINOR}/. $HOST_PREFIX/lib/python3.${PYMINOR}/
161171

162172
cp -vf build/cpython-wasm/libpython3.*.a prebuilt/emsdk/
163-
rmdir $PREFIX/lib/python3.??/lib-dynload
173+
rmdir $PREFIX/lib/python3.${PYMINOR}/lib-dynload
164174
fi
165175

166176
mkdir -p $PYTHONPYCACHEPREFIX/sysconfig
167177

168178

169179
# FIXME: seems CI cannot locate that one with python3-wasm
170-
cp $PREFIX/lib/python3.??/_sysconfigdata__emscripten_wasm32-emscripten.py $PYTHONPYCACHEPREFIX/sysconfig/_sysconfigdata__emscripten_debug.py
180+
cp $PREFIX/lib/python3.${PYMINOR}/_sysconfigdata__emscripten_wasm32-emscripten.py $PYTHONPYCACHEPREFIX/sysconfig/_sysconfigdata__emscripten_debug.py
171181
sed -i 's|-Os|-O0|g' $PYTHONPYCACHEPREFIX/sysconfig/_sysconfigdata__emscripten_debug.py
172182
sed -i 's|-g0|-g3|g' $PYTHONPYCACHEPREFIX/sysconfig/_sysconfigdata__emscripten_debug.py
173183

174-
#workaround
175-
#cp $PYTHONPYCACHEPREFIX/sysconfig/_sysconfigdata__emscripten_debug.py devices/x86_64/usr/lib/python3.11/_sysconfigdata__emscripten_debug.py
176-
177-
178184

179185
# python setup.py install --single-version-externally-managed --root=/
180186
# pip3 install .
@@ -281,8 +287,8 @@ export PYTHONHOME=$PREFIX
281287
282288
# find sysconfig ( tweaked )
283289
# but still can load dynload and setuptools
284-
PYTHONPATH=$(echo -n ${HOST_PREFIX}/lib/python3.??/site-packages):\$PYTHONPATH
285-
export PYTHONPATH=$PYTHONPYCACHEPREFIX/sysconfig:$(echo -n ${HOST_PREFIX}/lib/python3.??/lib-dynload):\$PYTHONPATH
290+
PYTHONPATH=$(echo -n ${HOST_PREFIX}/lib/python3.${PYMINOR}/site-packages):\$PYTHONPATH
291+
export PYTHONPATH=$PYTHONPYCACHEPREFIX/sysconfig:$(echo -n ${HOST_PREFIX}/lib/python3.${PYMINOR}/lib-dynload):\$PYTHONPATH
286292
287293
288294
#probably useless

scripts/cpython-build-host-deps.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $PIP install pip --upgrade
1515
# to remove ctypes deps
1616
$PIP install setuptools --upgrade
1717

18-
HPFX=./devices/x86_64/usr/lib/python3.11
18+
HPFX=./devices/x86_64/usr/lib/python3.${PYMINOR}
1919
rm $HPFX/ensurepip/_bundled/setuptools-*-py3-none-any.whl
2020
mv $HPFX/site-packages/setuptool* $HPFX/
2121
mv $HPFX/site-packages/_distutils* $HPFX/
@@ -98,12 +98,12 @@ if [ -d pymunk-4.0.0 ]
9898
then
9999
pushd pymunk-4.0.0
100100

101-
[ -d $HOST_PREFIX/lib/python3.11/site-packages/pymunk4 ] && rm -rf $HOST_PREFIX/lib/python3.11/site-packages/pymunk4
101+
[ -d $HOST_PREFIX/lib/python3.${PYMINOR}/site-packages/pymunk4 ] && rm -rf $HOST_PREFIX/lib/python3.${PYMINOR}/site-packages/pymunk4
102102
rm -f build/lib/pymunk/* chipmunk_src/*.so chipmunk_src/*/*.o
103103
$HPY setup.py build_chipmunk
104104
$SPY
105-
mv $HOST_PREFIX/lib/python3.11/site-packages/pymunk/libchipmunk.so $HOST_PREFIX/lib/python3.11/site-packages/pymunk/libchipmunk64.so
106-
mv $HOST_PREFIX/lib/python3.11/site-packages/pymunk $HOST_PREFIX/lib/python3.11/site-packages/pymunk4
105+
mv $HOST_PREFIX/lib/python3.${PYMINOR}/site-packages/pymunk/libchipmunk.so $HOST_PREFIX/lib/python3.${PYMINOR}/site-packages/pymunk/libchipmunk64.so
106+
mv $HOST_PREFIX/lib/python3.${PYMINOR}/site-packages/pymunk $HOST_PREFIX/lib/python3.${PYMINOR}/site-packages/pymunk4
107107
popd
108108
fi
109109

scripts/cpython-build-host.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ END
6161
# Prevent freezing bytecode with a different magic
6262
rm -f $HOST_PREFIX/bin/python3*
6363

64-
if command -v python3.11
64+
if command -v python3.${PYMINOR}
6565
then
6666
echo "
6767
6868
===================================================================================
6969
70-
it's not safe to have a python3.11 in the path :
71-
$(command -v python3.11)
70+
it's not safe to have a python3.${PYMINOR} in the path :
71+
$(command -v python3.${PYMINOR})
7272
while in pre-release cycle : _sre.MAGIC / bytecode weird errors etc ...
7373
7474
===================================================================================
@@ -87,10 +87,10 @@ END
8787
eval make -j$(nproc) install $QUIET
8888
rm -rf $(find $ROOT/devices/ -type d|grep __pycache__$)
8989

90-
patchelf --remove-needed libintl.so.8 $HOST_PREFIX/bin/python3.11
91-
sed -i 's|-lintl ||g' /opt/python-wasm-sdk/devices/x86_64/usr/bin/python3.11-config
90+
patchelf --remove-needed libintl.so.8 $HOST_PREFIX/bin/python3.${PYMINOR}
91+
sed -i 's|-lintl ||g' /opt/python-wasm-sdk/devices/x86_64/usr/bin/python3.${PYMINOR}-config
9292

93-
cp -Rfv $ROOT/support/__EMSCRIPTEN__.patches/. $HOST_PREFIX/lib/python3.??/
93+
cp -Rfv $ROOT/support/__EMSCRIPTEN__.patches/. $HOST_PREFIX/lib/python3.${PYMINOR}/
9494
else
9595
echo "
9696
==========================================================================

scripts/cpython-fetch.sh

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ echo "
99

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

12+
13+
NOPATCH=false
14+
1215
if false
1316
then
1417

@@ -37,26 +40,33 @@ then
3740
fi
3841

3942
else
40-
rm cpython 2>/dev/null
41-
#wget -q -c https://www.python.org/ftp/python/3.11.0/Python-3.11.0b1.tar.xz
42-
#tar xf Python-3.11.0b1.tar.xz
43-
#ln -s Python-3.11.0b1 cpython
44-
45-
wget -q -c https://www.python.org/ftp/python/3.11.0/Python-3.11.0b3.tgz
46-
tar xf Python-3.11.0b3.tgz
47-
ln -s Python-3.11.0b3 cpython
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
4853
fi
4954

5055
popd
5156

57+
if $NOPATCH
58+
then
59+
echo "
60+
* assuming cpython tree already patched, press <enter>
61+
"
5262

53-
# do some patching
54-
55-
pushd src/cpython 2>&1 >/dev/null
56-
57-
patch -p1 < ../../support/__EMSCRIPTEN__.embed/cpython.diff
5863

59-
popd
64+
else
65+
# do some patching
66+
pushd src/cpython 2>&1 >/dev/null
67+
patch -p1 < ../../support/__EMSCRIPTEN__.embed/cpython.diff
68+
popd
69+
fi
6070

6171
echo "
6272
* fetched cpython source, status is :

0 commit comments

Comments
 (0)