Skip to content

Commit f103132

Browse files
committed
add /opt/python-wasm-sdk/python3-wasm ready to use from CI
1 parent a6d81df commit f103132

File tree

11 files changed

+2310
-62
lines changed

11 files changed

+2310
-62
lines changed

config

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
#!/bin/bash
22
export LC_ALL=C
3+
export ROOT=${ROOT:-/opt/python-wasm-sdk}
4+
35
export PYTHONDONTWRITEBYTECODE=1
46
export REBUILD=${REBUILD:-false}
5-
export ROOT=/opt/python-wasm-sdk
6-
mkdir -p /opt/python-wasm-sdk/build/pycache
7+
export CI=${CI:-false}
8+
79
export HOST_PREFIX=${HOST_PREFIX:-$ROOT/devices/$(arch)/usr}
810
export PREFIX=${PREFIX:-${ROOT}/devices/emsdk/usr}
911
export PYTHONPYCACHEPREFIX=$(realpath ${ROOT}/build/pycache)
1012

1113
export HPY=$(echo -n ${HOST_PREFIX}/bin/python3.1?)
1214
export PIP=$(echo -n ${HOST_PREFIX}/bin/pip3.$(echo $HPY|cut -d. -f2))
1315

14-
export CI=${CI:-false}
16+
# this is python used for emsdk
17+
for py in 10 9 8 7
18+
do
19+
if command -v python3.${py} >/dev/null
20+
then
21+
export SYS_PYTHON=$(command -v python3.${py})
22+
break
23+
fi
24+
done
25+
1526

1627
# cpython build opts
1728
export CPOPTS="-Os -g0 -fPIC"
@@ -21,13 +32,13 @@ export LDFLAGS="-L$PREFIX/lib"
2132
# module build opts
2233
export CFLDPFX="$CPPFLAGS $LDFLAGS -Wno-unused-command-line-argument"
2334

24-
if [ -f dev ]
35+
if [ -f ${ROOT}/dev ]
2536
then
2637
export COPTS="-O0 -g3 -fPIC"
27-
export VERBOSE=""
38+
export QUIET=""
2839
else
2940
export COPTS="-Os -g0 -fPIC"
30-
export VERBOSE="2>&1 > $PYTHONPYCACHEPREFIX/.log"
41+
export QUIET="2>&1 > $PYTHONPYCACHEPREFIX/.log"
3142
fi
3243

3344
#stable

python-wasm-sdk.sh

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ export SDKDIR=/opt/python-wasm-sdk
55
sudo mkdir -p ${SDKDIR}
66
sudo chmod 777 ${SDKDIR}
77

8-
mv * ${SDKDIR}/
8+
cp -Rf * ${SDKDIR}/
99

1010
if cd ${SDKDIR}/
1111
then
12+
pwd
1213
mkdir -p build/pycache
1314
export PYTHONDONTWRITEBYTECODE=1
1415

scripts/cpython-build-emsdk.sh

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# fix /pip/_internal/operations/install/wheel.py
77
# for allowing to avoid pyc creation
88

9+
echo "
10+
* building cpython-wasm EMSDK_PYTHON=$SYS_PYTHON
11+
"
12+
913

1014
export PYTHON_FOR_BUILD=${PYTHON_FOR_BUILD:-${HOST_PREFIX}/bin/python3}
1115

@@ -21,7 +25,7 @@ REBUILD_WASM=${REBUILD_WASMPY:-false}
2125
if $REBUILD || $REBUILD_WASMPY
2226
then
2327
rm -rf build/cpython-wasm/ build/pycache/config.cache
24-
rm build/cpython-wasm/libpython3.??.a
28+
rm build/cpython-wasm/libpython3.??.a 2>/dev/null
2529
REBUILD=true
2630
fi
2731

@@ -63,6 +67,7 @@ else
6367

6468
emmake make install >/dev/null
6569

70+
unset EMCC_CFLAGS
6671
popd
6772

6873
cp -fv ${PREFIX}/lib/libffi.a $EMSDK/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic/
@@ -126,13 +131,13 @@ else
126131
--build=$($ROOT/src/cpython/config.guess) \
127132
--with-emscripten-target=browser \
128133
--prefix=$PREFIX \
129-
--with-build-python=${PYTHON_FOR_BUILD} $VERBOSE
134+
--with-build-python=${PYTHON_FOR_BUILD} $QUIET
130135

131136
#echo "#define HAVE_NCURSES_H" >> pyconfig.h
132137

133-
if EMCC_CFLAGS="-sUSE_ZLIB -sUSE_BZIP2" eval emmake make -j$(nproc) $VERBOSE
138+
if EMCC_CFLAGS="-sUSE_ZLIB -sUSE_BZIP2" eval emmake make -j$(nproc) $QUIET
134139
then
135-
EMCC_CFLAGS="-sUSE_ZLIB -sUSE_BZIP2" eval emmake make install $VERBOSE
140+
EMCC_CFLAGS="-sUSE_ZLIB -sUSE_BZIP2" eval emmake make install $QUIET
136141
else
137142
echo " **** cpython wasm build failed *** "
138143
exit 1
@@ -226,9 +231,8 @@ then
226231
# emsdk_env already parsed
227232
echo -n
228233
else
229-
pushd $ROOT
230-
. scripts/emsdk-fetch.sh
231-
popd
234+
. ${ROOT}/config
235+
. ${ROOT}/emsdk/emsdk_env.sh
232236
fi
233237
234238
export PATH=${HOST_PREFIX}/bin:\$PATH
@@ -248,19 +252,17 @@ export _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata__emscripten_
248252
249253
cat >${PYTHONPYCACHEPREFIX}/.numpy-site.cfg <<NUMPY
250254
[DEFAULT]
251-
library_dirs = $PREFIX//lib
255+
library_dirs = $PREFIX/lib
252256
include_dirs = $PREFIX/include
253257
NUMPY
254258
255-
256259
END
257260

258261
cat > $HOST_PREFIX/bin/python3-wasm <<END
259262
#!/bin/bash
260263
. $ROOT/${PYDK_PYTHON_HOST_PLATFORM}-shell.sh
261264
262265
# most important
263-
#export EMCC_CFLAGS="-sSIDE_MODULE -DBUILD_STATIC -fPIC"
264266
export CC=cc
265267
export _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata__emscripten_debug
266268
@@ -280,30 +282,11 @@ export PYTHONPATH=$PYTHONPYCACHEPREFIX/sysconfig:$(echo -n ${HOST_PREFIX}/lib/py
280282
export _PYTHON_HOST_PLATFORM=${PYDK_PYTHON_HOST_PLATFORM}
281283
export PYTHON_FOR_BUILD=${PYTHON_FOR_BUILD}
282284
283-
$HOST_PREFIX/bin/python3.?? -u -B \$@
285+
$HPY -u -B \$@
284286
END
285287

286288
chmod +x $HOST_PREFIX/bin/python3-wasm
287-
288-
289-
290-
291-
292-
293-
294-
295-
296-
297-
298-
299-
300-
301-
302-
303-
304-
305-
306-
289+
cp -f $HOST_PREFIX/bin/python3-wasm ${ROOT}/
307290

308291

309292
unset PYTHON_FOR_BUILD
@@ -312,19 +295,3 @@ unset EMCC_CFLAGS
312295

313296

314297

315-
316-
317-
318-
319-
320-
321-
322-
323-
324-
325-
326-
327-
328-
329-
330-

scripts/cpython-build-host-deps.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ done
6262

6363

6464
rm cffi-branch-default.zip
65-
wget https://foss.heptapod.net/pypy/cffi/-/archive/branch/default/cffi-branch-default.zip
65+
wget -q https://foss.heptapod.net/pypy/cffi/-/archive/branch/default/cffi-branch-default.zip
6666
unzip -o -q cffi-branch-default.zip
6767

6868
pushd cffi-branch-default
@@ -81,6 +81,7 @@ else
8181
popd
8282
fi
8383

84+
8485
if [ -d pymunk-4.0.0 ]
8586
then
8687
pushd pymunk-4.0.0

scripts/cpython-build-host.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ then
6161
if \
6262
CC=clang CXX=clang++ \
6363
eval ${ROOT}/src/cpython/configure \
64-
--prefix=$HOST_PREFIX $PYOPTS $VERBOSE
64+
--prefix=$HOST_PREFIX $PYOPTS $QUIET
6565
then
66-
eval make -j$(nproc) install $VERBOSE
66+
eval make -j$(nproc) install $QUIET
6767
rm -rf $(find $ROOT/devices/ -type d|grep __pycache__$)
6868

6969
cp -Rfv $ROOT/support/__EMSCRIPTEN__.patches/. $HOST_PREFIX/lib/python3.??/

scripts/cpython-fetch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ else
4242
#tar xf Python-3.11.0b1.tar.xz
4343
#ln -s Python-3.11.0b1 cpython
4444

45-
wget -q -c https://www.python.org/ftp/python/3.11.0/Python-3.11.0b3.tar.xz
46-
tar xf Python-3.11.0b3.tar.xz
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
4747
ln -s Python-3.11.0b3 cpython
4848
fi
4949

scripts/emsdk-fetch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ fi
105105
106106
if \$IS_SHARED
107107
then
108-
$EMSDK_PYTHON -E \$0.py $SHARED $LDFLAGS -Wno-unused-command-line-argument "\$@"
108+
\$SYS_PYTHON -E \$0.py $SHARED $LDFLAGS -Wno-unused-command-line-argument "\$@"
109109
else
110-
$EMSDK_PYTHON -E \$0.py $CPPFLAGS -Wno-unused-command-line-argument "\$@"
110+
\$SYS_PYTHON -E \$0.py $CPPFLAGS -Wno-unused-command-line-argument "\$@"
111111
fi
112112
END
113113
cat emsdk/upstream/emscripten/emcc > emsdk/upstream/emscripten/em++
@@ -126,7 +126,7 @@ END
126126

127127
cat > emsdk/upstream/emscripten/emconfigure <<END
128128
#!/bin/bash
129-
$EMSDK_PYTHON -E \$0.py "\$@"
129+
\$SYS_PYTHON -E \$0.py "\$@"
130130
END
131131

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

0 commit comments

Comments
 (0)