-
Notifications
You must be signed in to change notification settings - Fork 0
/
python-wasi-sdk.sh
executable file
·224 lines (157 loc) · 5.5 KB
/
python-wasi-sdk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
reset
# TODO: check how dbg tools work with default settings
# https://developer.chrome.com/blog/wasm-debugging-2020/
. /etc/lsb-release
DISTRIB="${DISTRIB_ID}-${DISTRIB_RELEASE}"
SDKROOT=${SDKROOT:-/opt/python-wasm-sdk}
export SDKROOT
export CIVER=${CIVER:-$DISTRIB}
export CI=true
if echo $0|grep -q python-wasm-sdk
then
echo " * adding emsdk to wasm-sdk"
emsdk=true
wasisdk=${wasisdk:-false}
nimsdk=${nimsdk:-false}
else
emsdk=false
BUILDS=3.13
wasisdk=true
nimsdk=true
fi
if $wasisdk
then
echo " * adding wasi-sdk to wasm-sdk"
fi
if $nimsdk
then
echo " * adding nim-sdk to wasm-sdk"
fi
if [ -d ${SDKROOT} ]
then
echo "Assuming destination $SDKROOT is ready"
else
sudo mkdir -p ${SDKROOT}
sudo chmod 777 ${SDKROOT}
fi
chmod +x ${SDKROOT}/scripts/*
ORIGIN=$(pwd)
# 3.12 3.11 3.10
BUILDS=${BUILDS:-3.12 3.13}
for PYBUILD in $BUILDS
do
cd "$ORIGIN"
if [ -f ${SDKROOT}/dev ]
then
echo "${SDKROOT}/dev found : using build cache"
else
echo "doing a clean build"
rm -rf ${SDKROOT}/* ${SDKROOT}/.??*
fi
cp -Rf * ${SDKROOT}/
if cd ${SDKROOT}/
then
mkdir -p build/pycache
export PYTHONDONTWRITEBYTECODE=1
# make install cpython will force bytecode generation
export PYTHONPYCACHEPREFIX="$(realpath build/pycache)"
# reset config
unset CONFIG_ENV
. ${CONFIG:-config}
cd ${SDKROOT}
if [ -f $HPY ]
then
echo " re-using host python HPY=$HPY"
else
cd ${SDKROOT}
. scripts/cpython-fetch.sh
cd ${SDKROOT}
# generic wasm patchwork
. support/__EMSCRIPTEN__.sh
. scripts/cpython-build-host.sh 2>&1 >/dev/null
. scripts/cpython-build-host-deps.sh >/dev/null
fi
cat > /opt/python-wasm-sdk/devices/$(arch)/usr/bin/py <<END
#!/bin/bash
export XDG_SESSION_TYPE=x11
export SDKROOT=${SDKROOT}
export PYTHONPATH=/data/git/pygbag/src:/data/git/platform_wasm:${PYTHONPATH}
export PYTHONPYCACHEPREFIX=$PYTHONPYCACHEPREFIX
export HOME=${SDKROOT}
export PATH=${SDKROOT}/devices/$(arch)/usr/bin:\$PATH
export LD_LIBRARY_PATH=${SDKROOT}/devices/$(arch)/usr/lib:${SDKROOT}/devices/$(arch)/usr/lib64:$LD_LIBRARY_PATH
${SDKROOT}/devices/$(arch)/usr/bin/python\${PYBUILD:-$PYBUILD} \$@
END
chmod +x /opt/python-wasm-sdk/devices/$(arch)/usr/bin/py
if $emsdk
then
cd ${SDKROOT}
mkdir -p src build ${SDKROOT}/devices/emsdk ${SDKROOT}/prebuilt/emsdk
# use ./ or emsdk will pollute env
./scripts/emsdk-fetch.sh
echo " ------------ building cpython wasm ${PYBUILD} ${CIVER} ----------------" 1>&2
if ./scripts/cpython-build-emsdk.sh > /dev/null
then
echo " ---------- building cpython wasm plus ${PYBUILD} ${CIVER} -----------" 1>&2
if ./scripts/cpython-build-emsdk-deps.sh > /dev/null
then
echo " --------- adding some usefull pkg ${PYBUILD} ${CIVER} ---------" 1>&2
./scripts/cpython-build-emsdk-prebuilt.sh
echo "
==========================================================
stripping emsdk ${PYBUILD} ${CIVER}
==========================================================
" 1>&2
rm -rf ${SDKROOT}/emsdk/upstream/emscripten/cache/ports*
rm -rf ${SDKROOT}/emsdk/upstream/emscripten/cache/ports/sdl2/SDL-*
rm -rf ${SDKROOT}/emsdk/upstream/emscripten/cache/ports
rm -rf ${SDKROOT}/emsdk/upstream/emscripten/cache/ports-builds
rm -rf ${SDKROOT}/emsdk/upstream/emscripten/tests
else
echo " cpython-build-emsdk-deps failed" 1>&2
exit 124
fi
else
echo " cpython-build-emsdk failed" 1>&2
exit 119
fi
fi
# compile wasi last because of configure patches
if $wasisdk
then
cd ${SDKROOT}
mkdir -p src build ${SDKROOT}/devices/wasisdk ${SDKROOT}/prebuilt/wasisdk
# do not source to protect env
./scripts/cpython-build-wasisdk.sh
> ${SDKROOT}/python3-wasi
# ROOT=/opt/python-wasm-sdk SDKROOT=/opt/python-wasm-sdk
# HOST_PREFIX=/opt/python-wasm-sdk/devices/$(arch)/usr
> ${SDKROOT}/wasm32-wasi-shell.sh
CPU=wasm32 TARGET=wasi \
PYDK_PYTHON_HOST_PLATFORM=wasm32-wasi \
PREFIX=/opt/python-wasm-sdk/devices/wasisdk/usr \
./scripts/make-shells.sh
cat >> $ROOT/wasm32-wasi-shell.sh <<END
#!/bin/bash
. ${WASISDK}/wasisdk_env.sh
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="[PyDK:wasi] \[\e[32m\]\w \[\e[91m\]\$(parse_git_branch)\[\e[00m\]\$ "
END
chmod +x ${SDKROOT}/python3-wasi ${SDKROOT}/wasm32-wasi-shell.sh
fi
if $nimsdk
then
${SDKROOT}/python-nim-sdk.sh
fi
wget https://github.com/bytecodealliance/wasmtime/releases/download/v17.0.1/wasmtime-v17.0.1-x86_64-linux.tar.xz -O-|xzcat|tar xfv -
mv -vf $(find wasmtime*|grep /wasmtime$) ${WASISDK}/bin/
. ${SDKROOT}/scripts/pack-sdk.sh
else
echo "cd failed" 1>&2
exit 208
fi
done
exit 0