Skip to content

Commit 737ffc3

Browse files
author
me
committed
Better support for building 3rd-party modules and static/dynamic compilation
1 parent 4bd62b0 commit 737ffc3

File tree

3 files changed

+121
-22
lines changed

3 files changed

+121
-22
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Ignore OpenSSL detection: Python 2.7.10 uses openssl 1.0.2 but tries
2+
to compile with 1.1 if present, and compilation fails.
3+
4+
Taken from
5+
https://github.com/renpy/renpy-deps/blob/master/source/python-minimize-openssl.diff
6+
7+
--- a/setup.py 2015-05-23 12:09:25.000000000 -0400
8+
+++ b/setup.py 2017-11-02 23:20:09.131537016 -0400
9+
@@ -842,7 +842,7 @@
10+
have_usable_openssl = (have_any_openssl and
11+
openssl_ver >= min_openssl_ver)
12+
13+
- if have_any_openssl:
14+
+ if False and have_any_openssl:
15+
if have_usable_openssl:
16+
# The _hashlib module wraps optimized implementations
17+
# of hash functions from the OpenSSL library.
18+
@@ -854,7 +854,7 @@
19+
print ("warning: openssl 0x%08x is too old for _hashlib" %
20+
openssl_ver)
21+
missing.append('_hashlib')
22+
- if COMPILED_WITH_PYDEBUG or not have_usable_openssl:
23+
+ if True or COMPILED_WITH_PYDEBUG or not have_usable_openssl:
24+
# The _sha module implements the SHA1 hash algorithm.
25+
exts.append( Extension('_sha', ['shamodule.c']) )
26+
# The _md5 module implements the RSA Data Security, Inc. MD5
27+
@@ -865,7 +865,7 @@
28+
depends = ['md5.h']) )
29+
30+
min_sha2_openssl_ver = 0x00908000
31+
- if COMPILED_WITH_PYDEBUG or openssl_ver < min_sha2_openssl_ver:
32+
+ if True or COMPILED_WITH_PYDEBUG or openssl_ver < min_sha2_openssl_ver:
33+
# OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash
34+
exts.append( Extension('_sha256', ['sha256module.c']) )
35+
exts.append( Extension('_sha512', ['sha512module.c']) )

2.7.10/patches/series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ python2-cross_compile.patch
22
python2-no_popen.patch
33
python2-static_submodules.patch
44
python2-webbrowser.patch
5+
python2-no-openssl.patch

2.7.10/python.sh

Lines changed: 85 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,36 @@ unpack () {
2929
quilt push -a
3030
}
3131

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 () {
4036
cd $BUILD/Python-$VERSION/
4137
mkdir -p native
4238
(
4339
cd native/
44-
# --without-signal-module: not disabled because needed by setup.py
4540
if [ ! -e config.status ]; then
41+
# --without-pymalloc: prevents segfault during 'make' (sysconfigdata)
4642
../configure \
47-
--prefix=$BUILD/hostpython/ \
48-
--without-threads --without-pymalloc --disable-shared --disable-ipv6
43+
--prefix='' \
44+
--without-pymalloc
4945
fi
50-
echo '*static*' > Modules/Setup.local
51-
cat $SETUPLOCAL >> Modules/Setup.local
5246

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-
5947
make -j$(nproc)
60-
DESTDIR= make install
48+
make install DESTDIR=$BUILD/hostpython
6149

6250
# emcc should disregard '-fPIC' during non-SIDE_MODULE builds,
6351
# otherwise _sysconfigdata.build_time_vars['CCSHARED'] is the culprit:
6452
# sed -i -e 's/-fPIC//' $BUILD/hostpython/lib/python2.7/_sysconfigdata.py
6553
)
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
6662
}
6763

6864
emscripten () {
@@ -129,14 +125,81 @@ emscripten () {
129125
)
130126
}
131127

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+
132194
case "$1" in
133-
unpack|native|emscripten)
195+
unpack|hostpython|emscripten|mock|crosspython)
134196
"$1"
135197
;;
136198
'')
137199
unpack
138-
native
200+
hostpython
139201
emscripten
202+
crosspython
140203
;;
141204
*)
142205
echo "Usage: $0 unpack|native|emscripten"

0 commit comments

Comments
 (0)