Skip to content

Commit 9426444

Browse files
committed
unix: upgrade llvm/clang to 13.0.0
Python 3.6+ is now a build dependency. On macOS, the system Python should be sufficiently new. So the build should hopefully pick it up. On Linux, our old Debian version only ships Python 3.4, so we need to install a modern Python. We simply build it from source as part of the clang build script. A better solution would be to establish a dedicated "host Python" artifact. This way we could use this Python build for both Clang and the host Python used in cross-compiles. But the current solution in this patch is much simpler.
1 parent 5e2454b commit 9426444

File tree

5 files changed

+95
-42
lines changed

5 files changed

+95
-42
lines changed

cpython-unix/build-clang-linux64.sh

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ mv ninja /tools/extra/bin/
4747

4848
export PATH=/tools/extra/bin:/tools/host/bin:$PATH
4949

50+
EXTRA_FLAGS=
51+
52+
if [ -x "${SCCACHE}" ]; then
53+
"${SCCACHE}" --start-server
54+
EXTRA_FLAGS="${EXTRA_FLAGS} -DCMAKE_C_COMPILER_LAUNCHER=${SCCACHE} -DCMAKE_CXX_COMPILER_LAUNCHER=${SCCACHE}"
55+
fi
56+
57+
if [ -n "${CI}" ]; then
58+
NUM_JOBS=${NUM_JOBS_AGGRESSIVE}
59+
else
60+
NUM_JOBS=${NUM_CPUS}
61+
fi
62+
63+
# clang requires a modern Python to build.
64+
tar -xf Python-${PYTHON_VERSION}.tar.xz
65+
pushd "Python-${PYTHON_VERSION}"
66+
CC="${HOST_CC}" CFLAGS="${EXTRA_HOST_CFLAGS}" CPPFLAGS="${EXTRA_HOST_CFLAGS}" LDFLAGS="${EXTRA_HOST_LDFLAGS}" ./configure \
67+
--prefix /tools/host \
68+
--without-ensurepip
69+
make -j "${NUM_CPUS}" install
70+
popd
71+
5072
mkdir llvm
5173
pushd llvm
5274
tar --strip-components=1 -xf ${ROOT}/llvm-${LLVM_VERSION}.src.tar.xz
@@ -85,19 +107,6 @@ popd
85107
mkdir llvm-objdir
86108
pushd llvm-objdir
87109

88-
EXTRA_FLAGS=
89-
90-
if [ -x "${SCCACHE}" ]; then
91-
"${SCCACHE}" --start-server
92-
EXTRA_FLAGS="${EXTRA_FLAGS} -DCMAKE_C_COMPILER_LAUNCHER=${SCCACHE} -DCMAKE_CXX_COMPILER_LAUNCHER=${SCCACHE}"
93-
fi
94-
95-
if [ -n "${CI}" ]; then
96-
NUM_JOBS=${NUM_JOBS_AGGRESSIVE}
97-
else
98-
NUM_JOBS=${NUM_CPUS}
99-
fi
100-
101110
# Stage 1: Build with GCC.
102111
mkdir stage1
103112
pushd stage1

cpython-unix/build-cpython.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ rm -rf setuptools-tmp
9393
if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
9494
pushd "Python-${PYTHON_VERSION}"
9595

96+
# Same patch as below. See comment there.
97+
if [ "${CC}" = "clang" ]; then
98+
patch -p1 <<"EOF"
99+
diff --git a/configure b/configure
100+
index 7cad0e2f98..50212236c4 100755
101+
--- a/configure
102+
+++ b/configure
103+
@@ -5196,7 +5196,7 @@ $as_echo "$as_me:
104+
fi
105+
106+
107+
-MULTIARCH=$($CC --print-multiarch 2>/dev/null)
108+
+MULTIARCH=
109+
110+
111+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the platform triplet based on compiler characteristics" >&5
112+
EOF
113+
fi
114+
96115
# When cross-compiling, we need to build a host Python that has working zlib
97116
# and ctypes extensions, otherwise various things fail. (`make install` fails
98117
# without zlib and setuptools / pip used by target install fail due to missing
@@ -309,6 +328,27 @@ index 1252335472..33c11fbade 100755
309328
EOF
310329
fi
311330

331+
# Clang 13 actually prints something with --print-multiarch, confusing CPython's
332+
# configure. This is reported as https://bugs.python.org/issue45405. We nerf the
333+
# check since we know what we're doing.
334+
if [ "${CC}" = "clang" ]; then
335+
patch -p1 <<"EOF"
336+
diff --git a/configure b/configure
337+
index 7cad0e2f98..50212236c4 100755
338+
--- a/configure
339+
+++ b/configure
340+
@@ -5196,7 +5196,7 @@ $as_echo "$as_me:
341+
fi
342+
343+
344+
-MULTIARCH=$($CC --print-multiarch 2>/dev/null)
345+
+MULTIARCH=
346+
347+
348+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the platform triplet based on compiler characteristics" >&5
349+
EOF
350+
fi
351+
312352
# Add a make target to write the PYTHON_FOR_BUILD variable so we can
313353
# invoke the host Python on our own.
314354
patch -p1 << "EOF"

cpython-unix/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def build_clang(client, image, host_platform):
322322
libcxx_archive = download_entry("libc++", DOWNLOADS_PATH)
323323
libcxxabi_archive = download_entry("libc++abi", DOWNLOADS_PATH)
324324
libunwind_archive = download_entry("libunwind", DOWNLOADS_PATH)
325+
python_archive = download_entry("cpython-3.9", DOWNLOADS_PATH)
325326

326327
with build_environment(client, image) as build_env:
327328
install_sccache(build_env)
@@ -337,6 +338,7 @@ def build_clang(client, image, host_platform):
337338
libcxx_archive,
338339
libcxxabi_archive,
339340
libunwind_archive,
341+
python_archive,
340342
):
341343
build_env.copy_file(a)
342344

@@ -356,6 +358,7 @@ def build_clang(client, image, host_platform):
356358
"LIBUNWIND_VERSION": DOWNLOADS["libunwind"]["version"],
357359
"LLD_VERSION": DOWNLOADS["lld"]["version"],
358360
"LLVM_VERSION": DOWNLOADS["llvm"]["version"],
361+
"PYTHON_VERSION": DOWNLOADS["cpython-3.9"]["version"],
359362
}
360363

361364
add_env_common(env)

cpython-unix/clang.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
RUN apt-get install \
33
libc6-dev \
44
libc6-dev:i386 \
5+
libffi-dev \
6+
make \
57
patch \
6-
python3 \
78
tar \
89
xz-utils \
910
unzip \

pythonbuild/downloads.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
"license_file": "LICENSE.bzip2.txt",
3030
},
3131
"clang": {
32-
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/clang-12.0.1.src.tar.xz",
33-
"size": 15323860,
34-
"sha256": "6e912133bcf56e9cfe6a346fa7e5c52c2cde3e4e48b7a6cc6fcc7c75047da45f",
35-
"version": "12.0.1",
32+
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang-13.0.0.src.tar.xz",
33+
"size": 17846828,
34+
"sha256": "5d611cbb06cfb6626be46eb2f23d003b2b80f40182898daa54b1c4e8b5b9e17e",
35+
"version": "13.0.0",
3636
},
3737
"clang-compiler-rt": {
38-
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/compiler-rt-12.0.1.src.tar.xz",
39-
"size": 2201284,
40-
"sha256": "b4c8d5f2a802332987c1c0a95b5afb35b1a66a96fe44add4e4ed4792c4cba0a4",
41-
"version": "12.0.1",
38+
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/compiler-rt-13.0.0.src.tar.xz",
39+
"size": 2287616,
40+
"sha256": "4c3602d76c7868a96b30c36165c4b7643e2a20173fced7e071b4baeb2d74db3f",
41+
"version": "13.0.0",
4242
},
4343
"cmake-linux-bin": {
4444
"url": "https://github.com/Kitware/CMake/releases/download/v3.19.2/cmake-3.19.2-Linux-x86_64.tar.gz",
@@ -126,16 +126,16 @@
126126
"version": "1.0.7",
127127
},
128128
"libc++": {
129-
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/libcxx-12.0.1.src.tar.xz",
130-
"size": 1882840,
131-
"sha256": "a42089cd358f661823c490741f8be98701d983a7ee5152c8649075da681a9d15",
132-
"version": "12.0.1",
129+
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/libcxx-13.0.0.src.tar.xz",
130+
"size": 2086032,
131+
"sha256": "3682f16ce33bb0a8951fc2c730af2f9b01a13b71b2b0dc1ae1e7034c7d86ca1a",
132+
"version": "13.0.0",
133133
},
134134
"libc++abi": {
135-
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/libcxxabi-12.0.1.src.tar.xz",
136-
"size": 552980,
137-
"sha256": "88efe8e391767a1e8f42b509879abe766c9f44b1781ad1900975ae6b516b91d0",
138-
"version": "12.0.1",
135+
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/libcxxabi-13.0.0.src.tar.xz",
136+
"size": 554780,
137+
"sha256": "becd5f1cd2c03cd6187558e9b4dc8a80b6d774ff2829fede88aa1576c5234ce3",
138+
"version": "13.0.0",
139139
},
140140
"libedit": {
141141
"url": "https://thrysoee.dk/editline/libedit-20210910-3.1.tar.gz",
@@ -163,10 +163,10 @@
163163
"version": "0.1",
164164
},
165165
"libunwind": {
166-
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/libunwind-12.0.1.src.tar.xz",
167-
"size": 98348,
168-
"sha256": "0bea6089518395ca65cf58b0a450716c5c99ce1f041079d3aa42d280ace15ca4",
169-
"version": "12.0.1",
166+
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/libunwind-13.0.0.src.tar.xz",
167+
"size": 99668,
168+
"sha256": "36f819091216177a61da639244eda67306ccdd904c757d70d135e273278b65e1",
169+
"version": "13.0.0",
170170
},
171171
"libX11": {
172172
"url": "https://www.x.org/archive/individual/lib/libX11-1.6.8.tar.gz",
@@ -196,16 +196,16 @@
196196
"license_file": "LICENSE.libxcb.txt",
197197
},
198198
"lld": {
199-
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/lld-12.0.1.src.tar.xz",
200-
"size": 1351580,
201-
"sha256": "690b3f6a76310e13a783a142f87500ade9cafe003e088b678364487ed873e361",
202-
"version": "12.0.1",
199+
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/lld-13.0.0.src.tar.xz",
200+
"size": 1472476,
201+
"sha256": "20d1900bcd64ff62047291f6edb6ba2fed34d782675ff68713bf0c2fc9e69386",
202+
"version": "13.0.0",
203203
},
204204
"llvm": {
205-
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/llvm-12.0.1.src.tar.xz",
206-
"size": 42898504,
207-
"sha256": "7d9a8405f557cefc5a21bf5672af73903b64749d9bc3a50322239f56f34ffddf",
208-
"version": "12.0.1",
205+
"url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/llvm-13.0.0.src.tar.xz",
206+
"size": 45471992,
207+
"sha256": "408d11708643ea826f519ff79761fcdfc12d641a2510229eec459e72f8163020",
208+
"version": "13.0.0",
209209
},
210210
"mpc": {
211211
"url": "http://www.multiprecision.org/downloads/mpc-1.0.3.tar.gz",

0 commit comments

Comments
 (0)