Skip to content

Commit 00aba35

Browse files
committed
linux: install patched versions of setuptools and pip
This is related to https://bugs.python.org/issue37060 and pypa/pip#6543. With patched versions of setuptools and pip installed, we can now `pip install` without issue on non-dynamic Python executables!
1 parent d102229 commit 00aba35

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

cpython-linux/build-cpython.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export LLVM_PROFDATA=/tools/clang-linux64/bin/llvm-profdata
2020
find /tools/deps -name '*.so*' -exec rm {} \;
2121

2222
tar -xf Python-${PYTHON_VERSION}.tar.xz
23+
unzip setuptools-${SETUPTOOLS_VERSION}.zip
24+
tar -xf pip-${PIP_VERSION}.tar.gz
2325

2426
cat Setup.local
2527
mv Setup.local Python-${PYTHON_VERSION}/Modules/Setup.local
@@ -89,6 +91,55 @@ cat ../Makefile.extra >> Makefile
8991
make -j `nproc`
9092
make -j `nproc` install DESTDIR=/build/out/python
9193

94+
# Install pip so we can patch it to work with non-dynamic executables
95+
# and work around https://github.com/pypa/pip/issues/6543. But pip's bundled
96+
# setuptools has the same bug! So we need to install a patched version.
97+
pushd /build/setuptools-${SETUPTOOLS_VERSION}
98+
patch -p1 <<EOF
99+
diff --git a/setuptools/glibc.py b/setuptools/glibc.py
100+
index a134591c..c9c3f378 100644
101+
--- a/setuptools/glibc.py
102+
+++ b/setuptools/glibc.py
103+
@@ -14,7 +14,10 @@ def glibc_version_string():
104+
# manpage says, "If filename is NULL, then the returned handle is for the
105+
# main program". This way we can let the linker do the work to figure out
106+
# which libc our process is actually using.
107+
- process_namespace = ctypes.CDLL(None)
108+
+ try:
109+
+ process_namespace = ctypes.CDLL(None)
110+
+ except OSError:
111+
+ return None
112+
try:
113+
gnu_get_libc_version = process_namespace.gnu_get_libc_version
114+
except AttributeError:
115+
EOF
116+
117+
/build/out/python/install/bin/python3 setup.py install
118+
popd
119+
120+
pushd /build/pip-${PIP_VERSION}
121+
patch -p1 <<EOF
122+
diff --git a/src/pip/_internal/utils/glibc.py b/src/pip/_internal/utils/glibc.py
123+
--- a/src/pip/_internal/utils/glibc.py
124+
+++ b/src/pip/_internal/utils/glibc.py
125+
@@ -18,7 +18,10 @@ def glibc_version_string():
126+
# manpage says, "If filename is NULL, then the returned handle is for the
127+
# main program". This way we can let the linker do the work to figure out
128+
# which libc our process is actually using.
129+
- process_namespace = ctypes.CDLL(None)
130+
+ try:
131+
+ process_namespace = ctypes.CDLL(None)
132+
+ except OSError:
133+
+ return None
134+
try:
135+
gnu_get_libc_version = process_namespace.gnu_get_libc_version
136+
except AttributeError:
137+
138+
EOF
139+
140+
/build/out/python/install/bin/python3 setup.py install
141+
popd
142+
92143
# Downstream consumers don't require bytecode files. So remove them.
93144
# Ideally we'd adjust the build system. But meh.
94145
find /build/out/python/install -type d -name __pycache__ -print0 | xargs -0 rm -rf

cpython-linux/build.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ def process_setup_line(line, variant=None):
626626
def build_cpython(client, image, platform, optimized=False, musl=False):
627627
"""Build CPythin in a Docker image'"""
628628
python_archive = download_entry('cpython-3.7', BUILD)
629+
setuptools_archive = download_entry('setuptools', BUILD)
630+
pip_archive = download_entry('pip', BUILD)
629631

630632
with (SUPPORT / 'static-modules').open('rb') as fh:
631633
static_modules_lines = [l.rstrip() for l in fh if not l.startswith(b'#')]
@@ -661,6 +663,8 @@ def build_cpython(client, image, platform, optimized=False, musl=False):
661663
install_tools_archive(container, BUILD / ('zlib-%s.tar' % dep_platform))
662664
#copy_rust(container)
663665
copy_file_to_container(python_archive, container, '/build')
666+
copy_file_to_container(setuptools_archive, container, '/build')
667+
copy_file_to_container(pip_archive, container, '/build')
664668
copy_file_to_container(SUPPORT / 'build-cpython.sh', container,
665669
'/build')
666670
copy_file_to_container(ROOT / 'python-licenses.rst', container, '/build')
@@ -685,7 +689,9 @@ def build_cpython(client, image, platform, optimized=False, musl=False):
685689

686690
env = {
687691
'CC': 'clang',
692+
'PIP_VERSION': DOWNLOADS['pip']['version'],
688693
'PYTHON_VERSION': DOWNLOADS['cpython-3.7']['version'],
694+
'SETUPTOOLS_VERSION': DOWNLOADS['setuptools']['version'],
689695
}
690696

691697
if musl:

pythonbuild/downloads.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@
201201
'sha256': '8af0ae5ceed63fa8a2ded611d44cc341027a91df22aaaa071efedc81437412a5',
202202
'version': '2.11.06',
203203
},
204+
'pip': {
205+
'url': 'https://files.pythonhosted.org/packages/93/ab/f86b61bef7ab14909bd7ec3cd2178feb0a1c86d451bc9bccd5a1aedcde5f/pip-19.1.1.tar.gz',
206+
'size': 1334144,
207+
'sha256': '44d3d7d3d30a1eb65c7e5ff1173cdf8f7467850605ac7cc3707b6064bddd0958',
208+
'version': '19.1.1',
209+
},
204210
'readline': {
205211
'url': 'ftp://ftp.gnu.org/gnu/readline/readline-6.3.tar.gz',
206212
'size': 2468560,
@@ -212,6 +218,12 @@
212218
'size': 236997689,
213219
'sha256': 'a01a493ed8946fc1c15f63e74fc53299b26ebf705938b4d04a388a746dfdbf9e',
214220
},
221+
'setuptools': {
222+
'url': 'https://files.pythonhosted.org/packages/1d/64/a18a487b4391a05b9c7f938b94a16d80305bf0369c6b0b9509e86165e1d3/setuptools-41.0.1.zip',
223+
'size': 849016,
224+
'sha256': 'a222d126f5471598053c9a77f4b5d4f26eaa1f150ad6e01dcf1a42e185d05613',
225+
'version': '41.0.1',
226+
},
215227
'sqlite': {
216228
'url': 'https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz',
217229
'size': 2810415,

0 commit comments

Comments
 (0)