@@ -29,40 +29,36 @@ unpack () {
29
29
quilt push -a
30
30
}
31
31
32
- # TODO: multiple partially supported use cases:
33
- # - python and pgen for emscripten() below
34
- # - compiling .pyo files, in emscripten() and package-xxx.sh
35
- # - building static/dynamic wasm modules (but lacks setuptools and its
36
- # threads dependency)
37
- # - mock-ing emscripten environment through static desktop python (but with signal module)
38
- # Make several builds?
39
- native () {
32
+ # use cases:
33
+ # - python/pgen/.pyo for emscripten() below
34
+ # - common basis for crosspython below
35
+ hostpython () {
40
36
cd $BUILD /Python-$VERSION /
41
37
mkdir -p native
42
38
(
43
39
cd native/
44
- # --without-signal-module: not disabled because needed by setup.py
45
40
if [ ! -e config.status ]; then
41
+ # --without-pymalloc: prevents segfault during 'make' (sysconfigdata)
46
42
../configure \
47
- --prefix=$BUILD /hostpython/ \
48
- --without-threads --without- pymalloc --disable-shared --disable-ipv6
43
+ --prefix=' ' \
44
+ --without-pymalloc
49
45
fi
50
- echo ' *static*' > Modules/Setup.local
51
- cat $SETUPLOCAL >> Modules/Setup.local
52
46
53
- # used by a Python script in 'make install' - or not
54
- # echo '_struct _struct.c' >> Modules/Setup.local
55
- # echo 'unicodedata unicodedata.c' >> Modules/Setup.local
56
-
57
- make -j$( nproc) Parser/pgen python
58
-
59
47
make -j$( nproc)
60
- DESTDIR= make install
48
+ make install DESTDIR= $BUILD /hostpython
61
49
62
50
# emcc should disregard '-fPIC' during non-SIDE_MODULE builds,
63
51
# otherwise _sysconfigdata.build_time_vars['CCSHARED'] is the culprit:
64
52
# sed -i -e 's/-fPIC//' $BUILD/hostpython/lib/python2.7/_sysconfigdata.py
65
53
)
54
+
55
+ # setuptools for 3rd-party module installers
56
+ wget -c https://files.pythonhosted.org/packages/11/0a/7f13ef5cd932a107cd4c0f3ebc9d831d9b78e1a0e8c98a098ca17b1d7d97/setuptools-41.6.0.zip -P $CACHEROOT /
57
+ cd $BUILD /hostpython/
58
+ rm -rf setuptools-41.6.0/
59
+ unzip $CACHEROOT /setuptools-41.6.0.zip
60
+ cd setuptools-41.6.0/
61
+ ../bin/python setup.py install
66
62
}
67
63
68
64
emscripten () {
@@ -129,14 +125,81 @@ emscripten () {
129
125
)
130
126
}
131
127
128
+ # For mock-ing emscripten environment through static desktop python
129
+ mock () {
130
+ cd $BUILD /Python-$VERSION /
131
+ mkdir -p native
132
+ (
133
+ cd native/
134
+ if [ ! -e config.status ]; then
135
+ ../configure \
136
+ --prefix=$BUILD /hostpython/ \
137
+ --without-threads --without-pymalloc --without-signal-module --disable-ipv6 \
138
+ --disable-shared
139
+ fi
140
+ echo ' *static*' > Modules/Setup.local
141
+ cat $SETUPLOCAL >> Modules/Setup.local
142
+
143
+ make -j$( nproc) Parser/pgen python
144
+
145
+ make -j$( nproc)
146
+ DESTDIR= make install
147
+ )
148
+ }
149
+
150
+ # python aimed at compiling third-party Python modules to WASM
151
+ # - building static/dynamic wasm modules
152
+ # - compiling .pyo files, in emscripten() and package-xxx.sh
153
+ # Uses hostpython; detects its PYTHONHOME through ../lib AFAICS, no need to recompile
154
+ # Usage:
155
+ # .../crosspython-static/bin/python setup.py xxx --root=.../destdir/ --prefix=''
156
+ # .../crosspython-dynamic/bin/python setup.py xxx --root=.../destdir/ --prefix=''
157
+ # .../crosspython-static/bin/python -OO -m py_compile xxx.py
158
+ crosspython () {
159
+ cd $( dirname $( readlink -f $0 ) )
160
+ # Copy-link hostpython except for include/ and
161
+ # lib/python2.7/_sysconfigdata.py
162
+ for variant in static dynamic; do
163
+ rm -rf crosspython-$variant
164
+ mkdir crosspython-$variant
165
+ (
166
+ cd crosspython-$variant
167
+ for i in $( cd ../build/hostpython && ls -A) ; do
168
+ ln -s ../build/hostpython/$i $i
169
+ done
170
+ rm include lib
171
+ mkdir lib
172
+ for i in $( cd ../build/hostpython/lib && ls -A) ; do
173
+ ln -s ../../build/hostpython/lib/$i lib/$i
174
+ done
175
+ rm lib/python2.7
176
+ mkdir lib/python2.7
177
+ for i in $( cd ../build/hostpython/lib/python2.7 && ls -A) ; do
178
+ ln -s ../../../build/hostpython/lib/python2.7/$i lib/python2.7/$i
179
+ done
180
+
181
+ # Use Python.h configured for WASM
182
+ ln -s $DESTDIR /include include
183
+
184
+ # Use compiler settings configured for WASM
185
+ rm lib/python2.7/_sysconfigdata.*
186
+ cp -a $DESTDIR /lib/python2.7/_sysconfigdata.* lib/python2.7/
187
+ )
188
+ done
189
+ # 'CCSHARED': 'xxx',
190
+ sed -i -e " s/'CCSHARED': .*/'CCSHARED': '-fPIC -s SIDE_MODULE=1',/" \
191
+ crosspython-dynamic/lib/python2.7/_sysconfigdata.py
192
+ }
193
+
132
194
case " $1 " in
133
- unpack|native |emscripten)
195
+ unpack|hostpython |emscripten|mock|crosspython )
134
196
" $1 "
135
197
;;
136
198
' ' )
137
199
unpack
138
- native
200
+ hostpython
139
201
emscripten
202
+ crosspython
140
203
;;
141
204
* )
142
205
echo " Usage: $0 unpack|native|emscripten"
0 commit comments