Skip to content

Commit cee0594

Browse files
committed
add assimp and emsdk fix 18941
1 parent a041420 commit cee0594

File tree

6 files changed

+72
-96
lines changed

6 files changed

+72
-96
lines changed

README.md

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,12 @@ Tooling for building CPython and various packages (either third parties support
33
n WebAssembly
44

55

6-
example building from within own pygame git clone tree on ubuntu 22.04 or linux mint :
7-
```bash
8-
#!/bin/bash
9-
# update system
10-
sudo apt-get update
11-
sudo apt-get install -y git bash python3-pip curl lz4 pv
12-
sudo mkdir -p /opt/python-wasm-sdk && sudo chown $(whoami) /opt/python-wasm-sdk
6+
see https://github.com/pygame-community/pygame-ce/blob/main/.github/workflows/build-emsdk.yml
7+
for how to use it
138

9+
or use as a cross compiler, after being unpacked in /opt/python-wasm-sdk, from within
10+
a source module distribution :
1411

12+
eg `/opt/python-wasm-sdk/python3-wasm setup.py bdist_wheel`
1513

16-
if [ -d ../pygame ]
17-
then
18-
echo " using local tree"
19-
else
20-
git clone https://github.com/pygame/pygame
21-
cd pygame
22-
fi
2314

24-
25-
# in github CI, current working dir would now be /home/runner/pygame/pygame.
26-
if [ -f setup.py ]
27-
then
28-
echo "cannot find pygame source code"
29-
else
30-
# update cython
31-
if [ -f ../dev ]
32-
then
33-
echo " * not upgrading cython"
34-
else
35-
pip3 install git+https://github.com/cython/cython.git --user --upgrade
36-
fi
37-
38-
# update source tree
39-
git clean -f
40-
git pull
41-
42-
mkdir -p /opt/python-wasm-sdk
43-
44-
# sdk
45-
if [ -f /opt/python-wasm-sdk/python3-wasm ]
46-
then
47-
echo " * not upgrading python-wasm-sdk"
48-
else
49-
echo " * using cached python-wasm-sdk archive"
50-
51-
if [ -f ../python-wasm-sdk-stable.tar.lz4 ]
52-
then
53-
# time tar xfvjP ../python-wasm-sdk-stable.tar.bz2 \
54-
# | pv -f -c -p -l -s 20626 >/dev/null
55-
time tar xfvP ../python-wasm-sdk-stable.tar.lz4 --use-compress-program=lz4 \
56-
| pv -f -c -p -l -s 20626 >/dev/null
57-
else
58-
curl -sL --retry 5 https://github.com/pygame-web/python-wasm-sdk/releases/download/0.2.0/python-wasm-sdk-stable.tar.bz2 \
59-
| tar xvPj \
60-
| pv -f -c -p -l -s 20626 >/dev/null
61-
fi
62-
fi
63-
64-
# build pygame
65-
touch $(find |grep pxd$)
66-
python3 setup.py config cython >/dev/null
67-
68-
/opt/python-wasm-sdk/python3-wasm setup.py -config -auto -sdl2 >/dev/null
69-
70-
# /opt/python-wasm-sdk/python3-wasm setup.py build
71-
EMCC_CFLAGS="-fPIC -I/opt/python-wasm-sdk/devices/emsdk/usr/include/SDL2 -s USE_SDL=2" /opt/python-wasm-sdk/python3-wasm setup.py build -j1
72-
73-
74-
mkdir -p dist
75-
# get static lib
76-
SYS_PYTHON=python3 /opt/python-wasm-sdk/emsdk/upstream/emscripten/emar rcs dist/libpygame.a $(find build/temp.wasm32-*/|grep o$)
77-
78-
fi
79-
```

scripts/cpython-build-emsdk.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313

1414
export PYTHON_FOR_BUILD=${PYTHON_FOR_BUILD:-${HPY}}
1515

16-
# remove old compiler wrapper to avoid conflicts
17-
[ -f $HOST_PREFIX/bin/cc ] && rm $HOST_PREFIX/bin/cc
18-
1916
. ./scripts/emsdk-fetch.sh
2017

2118
REBUILD_WASM=${REBUILD_WASMPY:-false}
@@ -264,9 +261,10 @@ sed -i 's|-g0|-g3|g' ${SDKROOT}/prebuilt/emsdk/${PYBUILD}/_sysconfigdata__emscri
264261
# python setup.py install --single-version-externally-managed --root=/
265262
# pip3 install .
266263

267-
ln -sf ${SDKROOT}/emsdk/upstream/emscripten/emcc $HOST_PREFIX/bin/cc
268264

269-
chmod +x $HOST_PREFIX/bin/cc
265+
# cmake usually wants cc
266+
ln ${SDKROOT}/emsdk/upstream/emscripten/emcc ${SDKROOT}/emsdk/upstream/emscripten/cc
267+
ln ${SDKROOT}/emsdk/upstream/emscripten/emcc.py ${SDKROOT}/emsdk/upstream/emscripten/cc.py
270268

271269
cat > ${PYTHONPYCACHEPREFIX}/.nanorc <<END
272270
set tabsize 4
@@ -288,10 +286,12 @@ export PYBUILD=\${PYBUILD:-$PYBUILD}
288286
export PYMAJOR=\$(echo -n \$PYBUILD|cut -d. -f1)
289287
export PYMINOR=\$(echo -n \$PYBUILD|cut -d. -f2)
290288
291-
export CARGO_HOME=\${CARGO_HOME:-/opt/python-rust-sdk}
292-
export RUSTUP_HOME=\${RUSTUP_HOME:-/opt/python-rust-sdk}
289+
export CARGO_HOME=\${CARGO_HOME:-${SDKROOT}}
290+
export RUSTUP_HOME=\${RUSTUP_HOME:-${SDKROOT}}
293291
export PATH=\${CARGO_HOME}/bin:\$PATH
294292
293+
export PANDA_PRC_DIR=${SDKROOT}/support
294+
295295
export EMSDK_QUIET=1
296296
297297
if [[ ! -z \${EMSDK+z} ]]
@@ -360,13 +360,12 @@ END
360360

361361
chmod +x $HOST_PREFIX/bin/python3-wasm
362362

363+
cp -f $HOST_PREFIX/bin/python3-wasm ${SDKROOT}/
364+
363365
# TODO: FIXME:
364-
echo "368 cannot use python3-wasm as python3 for setup.py in pygame build" 1>&2
366+
echo "366: cannot use python3-wasm as python3 for setup.py in pygame build" 1>&2
365367
ln -sf $HOST_PREFIX/bin/python${PYBUILD} $HOST_PREFIX/bin/python3
366368

367-
cp -f $HOST_PREFIX/bin/python3-wasm ${ROOT}/
368-
369-
370369
HPFX=./devices/$(arch)/usr/lib/python${PYBUILD}
371370
TPFX=./devices/emsdk/usr/lib/python${PYBUILD}
372371

scripts/emsdk-fetch.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ then
2525
echo "FIXME: Applying https://github.com/emscripten-core/emscripten/pull/17956"
2626
wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/17956.diff
2727
patch -p1 < 17956.diff
28+
echo "FIXME: Applying https://github.com/emscripten-core/emscripten/pull/18941"
29+
wget https://patch-diff.githubusercontent.com/raw/emscripten-core/emscripten/pull/18941.diff
30+
patch -p1 < 18941.diff
2831
popd
2932

30-
wget https://raw.githubusercontent.com/paradust7/minetest-wasm/main/emsdk_emcc.patch
31-
patch -p1 < emsdk_emcc.patch
33+
# wget https://raw.githubusercontent.com/paradust7/minetest-wasm/main/emsdk_emcc.patch
34+
# patch -p1 < emsdk_emcc.patch
3235

3336
# https://github.com/paradust7/minetest-wasm/blob/main/emsdk_dirperms.patch
3437
patch -p1 <<END

sources.wasm/assimp.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
4+
5+
. ${CONFIG:-config}
6+
7+
export ASSIMP="assimpjs-wasm"
8+
9+
10+
if [ -f assimp.patched ]
11+
then
12+
echo "
13+
already prepared $PREFIX
14+
"
15+
else
16+
git clone --recursive https://github.com/pmp-p/$ASSIMP
17+
pushd $ASSIMP
18+
19+
# patch -p1 <<END END
20+
21+
touch ../assimp.patched
22+
popd
23+
fi
24+
25+
26+
if [ -f $PREFIX/lib/libassimp.a ]
27+
then
28+
echo "
29+
already built in $PREFIX/lib/libassimp.a
30+
"
31+
else
32+
. $ROOT/scripts/emsdk-fetch.sh
33+
34+
mkdir -p $ROOT/build/assimp
35+
pushd $ROOT/build/assimp
36+
emmake cmake $ROOT/src/$ASSIMP -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_SHARED_LIBS=OFF
37+
emmake make install
38+
popd
39+
fi
40+
41+
cd $SDKROOT

support/__EMSCRIPTEN__.embed/cpython.diff

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- Python-3.11.0b1/Modules/readline.c 2022-05-07 00:56:26.000000000 +0200
2-
+++ Python-3.11.0b1-plus/Modules/readline.c 2022-05-21 22:57:01.680634385 +0200
1+
--- Python-3.11.2/Modules/readline.c 2023-02-07 14:37:51.000000000 +0100
2+
+++ Python-3.11.2-wasm/Modules/readline.c 2023-03-03 16:18:08.616667021 +0100
33
@@ -1326,7 +1326,9 @@
44
int has_input = 0, err = 0;
55

@@ -11,9 +11,9 @@
1111

1212
/* [Bug #1552726] Only limit the pause if an input hook has been
1313
defined. */
14-
--- Python-3.11.0b1/Python/sysmodule.c 2022-05-07 00:56:26.000000000 +0200
15-
+++ Python-3.11.0b1-plus/Python/sysmodule.c 2022-05-21 22:58:12.873024434 +0200
16-
@@ -48,7 +48,7 @@
14+
--- Python-3.11.2/Python/sysmodule.c 2023-02-07 14:37:51.000000000 +0100
15+
+++ Python-3.11.2-wasm/Python/sysmodule.c 2023-03-03 16:18:08.616667021 +0100
16+
@@ -49,7 +49,7 @@
1717
extern const char *PyWin_DLLVersionString;
1818
#endif
1919

@@ -22,7 +22,7 @@
2222
#include <emscripten.h>
2323
#endif
2424

25-
@@ -2692,7 +2692,7 @@
25+
@@ -2748,7 +2748,7 @@
2626
return NULL;
2727
}
2828

@@ -31,7 +31,7 @@
3131

3232
PyDoc_STRVAR(emscripten_info__doc__,
3333
"sys._emscripten_info\n\
34-
@@ -2928,7 +2928,7 @@
34+
@@ -2988,7 +2988,7 @@
3535
}
3636
}
3737

@@ -40,7 +40,7 @@
4040
if (EmscriptenInfoType == NULL) {
4141
EmscriptenInfoType = PyStructSequence_NewType(&emscripten_info_desc);
4242
if (EmscriptenInfoType == NULL) {
43-
@@ -3183,7 +3183,7 @@
43+
@@ -3243,7 +3243,7 @@
4444
#endif
4545
_PyStructSequence_FiniType(&Hash_InfoType);
4646
_PyStructSequence_FiniType(&AsyncGenHooksType);

support/__EMSCRIPTEN__.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ else
1919
echo 3.12 does not need patching for interactive FD
2020
else
2121
[ -f "Parser/pegen_errors.c" ] && patch -p1 <<END
22-
diff --git a/Parser/pegen_errors.c b/Parser/pegen_errors.c
23-
index 489699679633e..78266f712c05c 100644
24-
--- a/Parser/pegen_errors.c
25-
+++ b/Parser/pegen_errors.c
26-
@@ -245,7 +245,7 @@ get_error_line_from_tokenizer_buffers(Parser *p, Py_ssize_t lineno)
22+
--- Python-3.11.2/Parser/pegen_errors.c 2023-02-07 14:37:51.000000000 +0100
23+
+++ Python-3.11.2-wasm/Parser/pegen_errors.c 2023-03-03 16:18:08.672666445 +0100
24+
@@ -249,7 +249,7 @@
2725
* (multi-line) statement are stored in p->tok->interactive_src_start.
2826
* If not, we're parsing from a string, which means that the whole source
2927
* is stored in p->tok->str. */

0 commit comments

Comments
 (0)