Skip to content

Commit ba40464

Browse files
committed
switch to lz4 and preload non pic sdl2
1 parent 30145fd commit ba40464

File tree

4 files changed

+75
-25
lines changed

4 files changed

+75
-25
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ jobs:
3838
run: |
3939
sudo apt-get update --fix-missing
4040
# git clang libffi-dev libssl-dev zlib1g-dev libncursesw5-dev python3-pip make
41-
sudo apt-get install -y bash wget
41+
sudo apt-get install -y bash wget lz4
4242
4343
- name: Build sdk
44-
run: bash ./python-wasm-sdk.sh
44+
run: |
45+
chmod +x ./python-wasm-sdk.sh
46+
bash -c "CIVER=ubuntu-22.04 ./python-wasm-sdk.sh"
4547
4648
- name: Upload sdk to Github artifacts
4749
uses: actions/upload-artifact@v2

README.md

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,64 @@ Tooling for building CPython+Pygame on WebAssembly
55
example building from within own pygame git clone tree on ubuntu 20.04 or linux mint :
66
```bash
77
#!/bin/bash
8+
# update system
9+
sudo apt-get update
10+
sudo apt-get install -y git bash python3-pip curl lz4 pv
11+
sudo mkdir -p /opt/python-wasm-sdk && sudo chown $(whoami) /opt/python-wasm-sdk
12+
813

914
# 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 ]
17+
then
1018

11-
# update system
12-
sudo apt-get update
13-
sudo apt-get install -y bash python3-pip curl pv
19+
# update cython
20+
if [ -f ../dev ]
21+
then
22+
echo " * not upgrading cython"
23+
else
24+
pip3 install git+https://github.com/cython/cython.git --user --upgrade
25+
fi
1426

15-
# update cython
16-
pip3 install git+https://github.com/cython/cython.git --upgrade
27+
# update source tree
28+
git clean -f
29+
git pull
1730

18-
# update source tree
19-
git clean -f
20-
git pull
31+
mkdir -p /opt/python-wasm-sdk
2132

22-
# sdk
23-
sudo mkdir -p /opt/python-wasm-sdk && sudo chown $(whoami) /opt/python-wasm-sdk
24-
curl -sL --retry 5 https://github.com/pygame-web/python-wasm-sdk/releases/download/0.1.0/python-wasm-sdk-stable.tar.bz2 \
25-
| tar xvPj \
26-
| pv -f -c -p -l -s 20626 >/dev/null
33+
# sdk
34+
if [ -f /opt/python-wasm-sdk/python3-wasm ]
35+
then
36+
echo " * not upgrading python-wasm-sdk"
37+
else
38+
echo " * using cached python-wasm-sdk archive"
39+
40+
if [ -f ../python-wasm-sdk-stable.tar.lz4 ]
41+
then
42+
# time tar xfvjP ../python-wasm-sdk-stable.tar.bz2 \
43+
# | pv -f -c -p -l -s 20626 >/dev/null
44+
time tar xfvP ../python-wasm-sdk-stable.tar.lz4 --use-compress-program=lz4 \
45+
| pv -f -c -p -l -s 20626 >/dev/null
46+
else
47+
curl -sL --retry 5 https://github.com/pygame-web/python-wasm-sdk/releases/download/0.2.0/python-wasm-sdk-stable.tar.bz2 \
48+
| tar xvPj \
49+
| pv -f -c -p -l -s 20626 >/dev/null
50+
fi
51+
fi
52+
53+
# build pygame
54+
touch $(find |grep pxd$)
55+
python3 setup.py config cython >/dev/null
56+
57+
/opt/python-wasm-sdk/python3-wasm setup.py -config -auto -sdl2 >/dev/null
2758

28-
# build pygame
29-
touch $(find |grep pxd$)
30-
python3 setup.py config cython
59+
# /opt/python-wasm-sdk/python3-wasm setup.py build
60+
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
3161

32-
/opt/python-wasm-sdk/python3-wasm setup.py -config -auto -sdl2
3362

34-
/opt/python-wasm-sdk/python3-wasm setup.py build
63+
mkdir -p dist
64+
# get static lib
65+
SYS_PYTHON=python3 /opt/python-wasm-sdk/emsdk/upstream/emscripten/emar rcs dist/libpygame.a $(find build/temp.wasm32-*/|grep o$)
3566

36-
# get static lib
37-
SYS_PYTHON=python3 /opt/python-wasm-sdk/emsdk/upstream/emscripten/emar rcs libpygame.a $(find build/temp.wasm32-*/|grep o$)
67+
fi
3868
```

python-wasm-sdk.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ then
3636
then
3737
echo "making tarball"
3838
cd /
39-
rm -rf ${SDKDIR}/emsdk/upstream/emscripten/cache/ports*
39+
4040
mkdir -p /tmp/sdk
41-
tar -cpPRj \
41+
tar -cpPR \
4242
${SDKDIR}/config \
4343
${SDKDIR}/build/pycache/.??* \
4444
${SDKDIR}/build/pycache/sysconfig/_sysconfigdata__emscripten_debug.py \
@@ -47,7 +47,10 @@ then
4747
${SDKDIR}/emsdk \
4848
${SDKDIR}/devices/* \
4949
${SDKDIR}/prebuilt/* \
50-
> /tmp/sdk/python-wasm-sdk-stable.tar.bz2
50+
> /tmp/sdk/python-wasm-sdk-stable.tar
51+
lz4 /tmp/sdk/python-wasm-sdk-${$CIVER:-ubuntu-latest}.tar
52+
# bzip2 will remove original
53+
bzip2 /tmp/sdk/python-wasm-sdk-${$CIVER:-ubuntu-latest}.tar
5154
else
5255
echo " cpython-build-emsdk-deps failed"
5356
exit 2

scripts/emsdk-fetch.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ then
8080
#embuilder build $one
8181
done
8282

83+
if $CI
84+
then
85+
echo "
86+
87+
==========================================================
88+
stripping emsdk
89+
==========================================================
90+
"
91+
rm -rf ${SDKDIR}/emsdk/upstream/emscripten/cache/ports*
92+
# something triggers sdl2 *full* rebuild in pygame.
93+
# but only that one.
94+
embuilder --pic build sdl2
95+
embuilder --pic sdl2
96+
rm -rf ${SDKDIR}/emsdk/upstream/emscripten/tests
97+
fi
8398

8499
# -Wno-limited-postlink-optimizations
85100

0 commit comments

Comments
 (0)