@@ -20,8 +20,71 @@ export LLVM_PROFDATA=${TOOLS_PATH}/${TOOLCHAIN}/bin/llvm-profdata
20
20
find ${TOOLS_PATH} /deps -name ' *.so*' -exec rm {} \;
21
21
22
22
tar -xf Python-${PYTHON_VERSION} .tar.xz
23
- tar -xf setuptools-${SETUPTOOLS_VERSION} .tar.gz
24
- tar -xf pip-${PIP_VERSION} .tar.gz
23
+
24
+ PIP_WHEEL=" ${ROOT} /pip-${PIP_VERSION} -py3-none-any.whl"
25
+ SETUPTOOLS_WHEEL=" ${ROOT} /setuptools-${SETUPTOOLS_VERSION} -py3-none-any.whl"
26
+
27
+ # pip and setuptools don't properly handle the case where the current executable
28
+ # isn't dynamic. This is tracked by https://github.com/pypa/pip/issues/6543.
29
+ # We need to patch both.
30
+ #
31
+ # Ideally we'd do this later in the build. However, since we use the pip
32
+ # wheel to bootstrap itself, we need to patch the wheel before it is used.
33
+ #
34
+ # Wheels are zip files. So we simply unzip, patch, and rezip.
35
+ mkdir pip-tmp
36
+ pushd pip-tmp
37
+ unzip " ${PIP_WHEEL} "
38
+
39
+ patch -p1 << EOF
40
+ diff --git a/pip/_internal/utils/glibc.py b/pip/_internal/utils/glibc.py
41
+ index 819979d80..4ae91e364 100644
42
+ --- a/pip/_internal/utils/glibc.py
43
+ +++ b/pip/_internal/utils/glibc.py
44
+ @@ -47,7 +47,10 @@ def glibc_version_string_ctypes():
45
+ # manpage says, "If filename is NULL, then the returned handle is for the
46
+ # main program". This way we can let the linker do the work to figure out
47
+ # which libc our process is actually using.
48
+ - process_namespace = ctypes.CDLL(None)
49
+ + try:
50
+ + process_namespace = ctypes.CDLL(None)
51
+ + except OSError:
52
+ + return None
53
+ try:
54
+ gnu_get_libc_version = process_namespace.gnu_get_libc_version
55
+ except AttributeError:
56
+ EOF
57
+
58
+ zip -r " ${PIP_WHEEL} " *
59
+ popd
60
+ rm -rf pip-tmp
61
+
62
+ mkdir setuptools-tmp
63
+ pushd setuptools-tmp
64
+ unzip " ${SETUPTOOLS_WHEEL} "
65
+
66
+ patch -p1 << EOF
67
+ diff --git a/setuptools/_vendor/packaging/tags.py b/setuptools/_vendor/packaging/tags.py
68
+ index 9064910b..c541e648 100644
69
+ --- a/setuptools/_vendor/packaging/tags.py
70
+ +++ b/setuptools/_vendor/packaging/tags.py
71
+ @@ -475,7 +475,10 @@ def _glibc_version_string_ctypes():
72
+ # which libc our process is actually using.
73
+ #
74
+ # Note: typeshed is wrong here so we are ignoring this line.
75
+ - process_namespace = ctypes.CDLL(None) # type: ignore
76
+ + try:
77
+ + process_namespace = ctypes.CDLL(None) # type: ignore
78
+ + except OSError:
79
+ + return None
80
+ try:
81
+ gnu_get_libc_version = process_namespace.gnu_get_libc_version
82
+ except AttributeError:
83
+ EOF
84
+
85
+ zip -r " ${SETUPTOOLS_WHEEL} " *
86
+ popd
87
+ rm -rf setuptools-tmp
25
88
26
89
# If we are cross-compiling, we need to build a host Python to use during
27
90
# the build.
@@ -50,7 +113,9 @@ if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
50
113
;;
51
114
esac
52
115
53
- CC=" ${HOST_CC} " CFLAGS=" ${EXTRA_HOST_CFLAGS} " CPPFLAGS=" ${EXTRA_HOST_CFLAGS} " LDFLAGS=" ${EXTRA_HOST_LDFLAGS} " ./configure --prefix " ${TOOLS_PATH} /pyhost"
116
+ CC=" ${HOST_CC} " CFLAGS=" ${EXTRA_HOST_CFLAGS} " CPPFLAGS=" ${EXTRA_HOST_CFLAGS} " LDFLAGS=" ${EXTRA_HOST_LDFLAGS} " ./configure \
117
+ --prefix " ${TOOLS_PATH} /pyhost" \
118
+ --without-ensurepip
54
119
55
120
# When building on macOS 10.15 (and possibly earlier) using the 11.0
56
121
# SDK, the _ctypes extension fails to import due to a missing symbol on
@@ -741,63 +806,17 @@ if [ "${PYBUILD_SHARED}" = "1" ]; then
741
806
fi
742
807
fi
743
808
744
- # Install pip so we can patch it to work with non-dynamic executables
745
- # and work around https://github.com/pypa/pip/issues/6543. But pip's bundled
746
- # setuptools has the same bug! So we need to install a patched version.
747
- pushd ${ROOT} /setuptools-${SETUPTOOLS_VERSION}
748
- patch -p1 << EOF
749
- diff --git a/setuptools/_vendor/packaging/tags.py b/setuptools/_vendor/packaging/tags.py
750
- index 9064910b..c541e648 100644
751
- --- a/setuptools/_vendor/packaging/tags.py
752
- +++ b/setuptools/_vendor/packaging/tags.py
753
- @@ -475,7 +475,10 @@ def _glibc_version_string_ctypes():
754
- # which libc our process is actually using.
755
- #
756
- # Note: typeshed is wrong here so we are ignoring this line.
757
- - process_namespace = ctypes.CDLL(None) # type: ignore
758
- + try:
759
- + process_namespace = ctypes.CDLL(None) # type: ignore
760
- + except OSError:
761
- + return None
762
- try:
763
- gnu_get_libc_version = process_namespace.gnu_get_libc_version
764
- except AttributeError:
765
- EOF
766
-
767
- ${BUILD_PYTHON} setup.py install
768
- popd
769
-
770
- pushd ${ROOT} /pip-${PIP_VERSION}
771
-
772
- # pip 21 shipped DOS line endings. https://github.com/pypa/pip/issues/9638.
773
- # Let's fix that.
774
- if [ " ${PYBUILD_PLATFORM} " = " macos" ]; then
775
- find . -name ' *.py' -exec perl -i -pe ' s/\r\n$/\n/g' {} \;
776
- else
777
- find . -name ' *.py' -exec sed -i ' s/\r$//g' {} \;
778
- fi
779
-
780
- patch -p1 << EOF
781
- diff --git a/src/pip/_internal/utils/glibc.py b/src/pip/_internal/utils/glibc.py
782
- index 819979d80..4ae91e364 100644
783
- --- a/src/pip/_internal/utils/glibc.py
784
- +++ b/src/pip/_internal/utils/glibc.py
785
- @@ -47,7 +47,10 @@ def glibc_version_string_ctypes():
786
- # manpage says, "If filename is NULL, then the returned handle is for the
787
- # main program". This way we can let the linker do the work to figure out
788
- # which libc our process is actually using.
789
- - process_namespace = ctypes.CDLL(None)
790
- + try:
791
- + process_namespace = ctypes.CDLL(None)
792
- + except OSError:
793
- + return None
794
- try:
795
- gnu_get_libc_version = process_namespace.gnu_get_libc_version
796
- except AttributeError:
797
- EOF
809
+ # Install setuptools and pip as they are common tools that should be in any
810
+ # Python distribution.
811
+ #
812
+ # We disabled ensurepip because we insist on providing our own pip and don't
813
+ # want the final product to possibly be contaminated by another version.
814
+ #
815
+ # It is possible for the Python interpreter to run wheels directly. So we
816
+ # simply use our pip to install self. Kinda crazy, but it works!
798
817
799
- ${BUILD_PYTHON} setup.py install
800
- popd
818
+ ${BUILD_PYTHON} " ${PIP_WHEEL} /pip " install --prefix= " ${ROOT} /out/python/install " --no-cache-dir --no-index " ${PIP_WHEEL} "
819
+ ${BUILD_PYTHON} " ${PIP_WHEEL} /pip " install --prefix= " ${ROOT} /out/python/install " --no-cache-dir --no-index " ${SETUPTOOLS_WHEEL} "
801
820
802
821
# Emit metadata to be used in PYTHON.json.
803
822
cat > ${ROOT} /generate_metadata.py << EOF
0 commit comments