Skip to content

Commit d37d308

Browse files
committed
Fix crosspython
1 parent f6bca15 commit d37d308

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

2.7.10/python.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ emscripten () {
6666
# OPT=-Oz: TODO
6767
# CONFIG_SITE: deals with cross-compilation https://bugs.python.org/msg136962
6868
# not needed as emcc has a single arch: BASECFLAGS=-m32 LDFLAGS=-m32
69+
# PATH: detect our Python, beware of conflict with emcc's python3
70+
# don't use PYTHON_FOR_BUILD which is high-level / lots of options
6971
# --without-threads: pthreads experimental as of 2020-05
7072
# cf. https://emscripten.org/docs/porting/pthreads.html
7173
# --without-signal-module: no process signals in Emscripten
@@ -74,14 +76,14 @@ emscripten () {
7476
# --disable-shared: compile statically for Emscripten perfs + incomplete PIC support
7577
if [ ! -e config.status ]; then
7678
CONFIG_SITE=../config.site BASECFLAGS='-s USE_ZLIB=1' \
77-
PYTHON_FOR_BUILD=$BUILD/Python-$VERSION/native/python \
79+
PATH=$BUILD/Python-$VERSION/native:$PATH \
7880
emconfigure ../configure \
7981
--host=asmjs-unknown-emscripten --build=$(../config.guess) \
8082
--prefix='' \
8183
--without-threads --without-pymalloc --without-signal-module --disable-ipv6 \
8284
--disable-shared
8385
fi
84-
# Fix bad detection
86+
# Fix bad detection
8587
sed -i -e 's,^#define HAVE_GCC_ASM_FOR_X87.*,/* & */,' pyconfig.h
8688

8789
# pgen native setup
@@ -96,13 +98,15 @@ emscripten () {
9698
# drop -I/-L/-lz, we USE_ZLIB=1 (keep it in SETUPLOCAL for mock)
9799
sed -i -e 's/^\(zlib zlibmodule.c\).*/\1/' Modules/Setup.local
98100

99-
emmake make -j$(nproc)
100-
101-
# setup.py install_lib doesn't respect DESTDIR
102-
echo -e 'sharedinstall:\n\ttrue' >> Makefile
103-
# decrease .pyo size by dropping docstrings
104-
sed -i -e '/compileall.py/ s/ -O / -OO /' Makefile
105-
emmake make install DESTDIR=$DESTDIR
101+
(
102+
export PATH=$BUILD/Python-$VERSION/native:$PATH
103+
emmake make -j$(nproc)
104+
# setup.py install_lib doesn't respect DESTDIR
105+
echo -e 'sharedinstall:\n\ttrue' >> Makefile
106+
# decrease .pyo size by dropping docstrings
107+
sed -i -e '/compileall.py/ s/ -O / -OO /' Makefile
108+
emmake make install DESTDIR=$DESTDIR
109+
)
106110

107111
# Basic trimming
108112
# Disabled for now, better cherry-pick the files we need
@@ -201,7 +205,7 @@ case "$1" in
201205
crosspython
202206
;;
203207
*)
204-
echo "Usage: $0 unpack|native|emscripten"
208+
echo "Usage: $0 unpack|hostpython|emscripten|mock|crosspython"
205209
exit 1
206210
;;
207211
esac

3.8/python.sh

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ emscripten () {
5656
cd emscripten/
5757
# OPT=-Oz: TODO
5858
# CONFIG_SITE: deals with cross-compilation https://bugs.python.org/msg136962
59+
# PATH: detect our Python, beware of conflict with emcc's python3
60+
# don't use PYTHON_FOR_BUILD which is high-level / lots of options
5961
# --without-pymalloc: ?
6062
# --disable-ipv6: ?
61-
# --disable-shared: compile statically for Emscripten perfs + incomplete PIC support
63+
# --disable-shared: compile statically for Emscripten perfs + incomplete PIC support
6264
if [ ! -e config.status ]; then
6365
CONFIG_SITE=../config-emscripten.site BASECFLAGS='-s USE_ZLIB=1' READELF=true \
64-
PYTHON_FOR_BUILD=$BUILD/Python-$VERSION/native/python \
66+
PATH=$BUILD/Python-$VERSION/native:$PATH \
6567
emconfigure ../configure \
6668
--host=asmjs-unknown-emscripten --build=$(../config.guess) \
6769
--prefix='' \
@@ -84,11 +86,13 @@ EOF
8486
# decrease .pyo size by dropping docstrings
8587
sed -i -e '/compileall.py/ s/ -O / -OO /' Makefile
8688

87-
# Trigger setup.py:CROSS_COMPILING (introduced in 3.8)
88-
export _PYTHON_HOST_PLATFORM=emscripten
89-
90-
emmake make -j$(nproc)
91-
emmake make install DESTDIR=$DESTDIR
89+
(
90+
export PATH=$BUILD/Python-$VERSION/native:$PATH
91+
# Trigger setup.py:CROSS_COMPILING (introduced in 3.8)
92+
export _PYTHON_HOST_PLATFORM=emscripten
93+
emmake make -j$(nproc)
94+
emmake make install DESTDIR=$DESTDIR
95+
)
9296

9397
# Basic trimming
9498
# Disabled for now, better cherry-pick the files we need
@@ -166,14 +170,14 @@ crosspython () {
166170
# Use Python.h configured for WASM
167171
ln -s $DESTDIR/include include
168172

169-
# TODO: Use compiler settings configured for WASM
170-
#rm lib/python3.8/_sysconfigdata.*
171-
#cp -a $DESTDIR/lib/python3.8/_sysconfigdata.* lib/python3.8/
173+
# Use compiler settings configured for WASM
174+
cp -a $DESTDIR/lib/python3.8/_sysconfigdata__emscripten_.py \
175+
lib/python3.8/_sysconfigdata_*.py
172176
)
173177
done
174-
# TODO: 'CCSHARED': 'xxx',
175-
#sed -i -e "s/'CCSHARED': .*/'CCSHARED': '-fPIC -s SIDE_MODULE=1',/" \
176-
# crosspython-dynamic/lib/python3.8/_sysconfigdata.py
178+
# 'CCSHARED': 'xxx',
179+
sed -i -e "s/'CCSHARED': .*/'CCSHARED': '-fPIC -s SIDE_MODULE=1',/" \
180+
crosspython-dynamic/lib/python3.8/_sysconfigdata_*.py
177181
}
178182

179183
case "$1" in
@@ -187,7 +191,7 @@ case "$1" in
187191
crosspython
188192
;;
189193
*)
190-
echo "Usage: $0 unpack|native|emscripten"
194+
echo "Usage: $0 unpack|hostpython|emscripten|mock|crosspython"
191195
exit 1
192196
;;
193197
esac

0 commit comments

Comments
 (0)