Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / taskcluster / scripts / misc / build-cpython.sh
blob95b5e8173371c88dc857da48909048f0147d8630
1 #!/bin/sh
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 # This script builds the official interpreter for the python language,
7 # while also packing in a few default extra packages.
9 set -e
10 set -x
12 # Required fetch artifact
13 clang_bindir=${MOZ_FETCHES_DIR}/clang/bin
14 clang_libdir=${MOZ_FETCHES_DIR}/clang/lib
15 python_src=${MOZ_FETCHES_DIR}/cpython-source
16 xz_prefix=${MOZ_FETCHES_DIR}/xz
18 # Make the compiler-rt available to clang.
19 env UPLOAD_DIR= $GECKO_PATH/taskcluster/scripts/misc/repack-clang.sh
21 # Extra setup per platform
22 case `uname -s` in
23 Darwin)
24 # Use taskcluster clang instead of host compiler on OSX
25 export PATH=${clang_bindir}:${PATH}
26 export CC=clang
27 export CXX=clang++
28 export LDFLAGS=-fuse-ld=lld
30 case `uname -m` in
31 aarch64)
32 macosx_version_min=11.0
35 macosx_version_min=10.12
37 esac
38 macosx_sdk=14.4
39 # NOTE: both CFLAGS and CPPFLAGS need to be set here, otherwise
40 # configure step fails.
41 sysroot_flags="-isysroot ${MOZ_FETCHES_DIR}/MacOSX${macosx_sdk}.sdk -mmacosx-version-min=${macosx_version_min}"
42 export CPPFLAGS="${sysroot_flags} -I${xz_prefix}/include"
43 export CFLAGS=${sysroot_flags}
44 export LDFLAGS="${LDFLAGS} ${sysroot_flags} -L${xz_prefix}/lib"
45 configure_flags_extra=--with-openssl=/usr/local/opt/openssl
47 # see https://bugs.python.org/issue22490
48 unset __PYVENV_LAUNCHER__
50 # see https://bugs.python.org/issue44065
51 sed -i -e 's,$CC --print-multiarch,:,' ${python_src}/configure
52 export LDFLAGS="${LDFLAGS} -Wl,-rpath -Wl,@loader_path/../.."
54 Linux)
55 # Use host gcc on Linux
56 export LDFLAGS="${LDFLAGS} -Wl,-rpath,\\\$ORIGIN/../.."
58 esac
60 # Patch Python to honor MOZPYTHONHOME instead of PYTHONHOME. That way we have a
61 # relocatable python for free, while not interfering with the system Python that
62 # already honors PYTHONHOME.
63 find ${python_src} -type f -print0 | xargs -0 perl -i -pe "s,PYTHONHOME,MOZPYTHONHOME,g"
65 # Actual build
66 work_dir=`pwd`
67 tardir=python
69 cd `mktemp -d`
70 ${python_src}/configure --prefix=/${tardir} --enable-optimizations ${configure_flags_extra} || { exit_status=$? && cat config.log && exit $exit_status ; }
72 export MAKEFLAGS=-j`nproc`
73 make
74 make DESTDIR=${work_dir} install
75 cd ${work_dir}
77 ${work_dir}/python/bin/python3 -m pip install --upgrade pip==23.0
78 ${work_dir}/python/bin/python3 -m pip install -r ${GECKO_PATH}/build/psutil_requirements.txt -r ${GECKO_PATH}/build/zstandard_requirements.txt
80 case `uname -s` in
81 Darwin)
83 cp /usr/local/opt/openssl/lib/libssl*.dylib ${work_dir}/python/lib/
84 cp /usr/local/opt/openssl/lib/libcrypto*.dylib ${work_dir}/python/lib/
85 cp ${xz_prefix}/lib/liblzma.dylib ${work_dir}/python/lib/
87 # Instruct the loader to search for the lib in rpath instead of the one used during linking
88 install_name_tool -change /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib @rpath/libssl.1.1.dylib ${work_dir}/python/lib/python3.*/lib-dynload/_ssl.cpython-3*-darwin.so
89 install_name_tool -change /usr/local/opt/openssl@1.1/lib/libcrypto.1.1.dylib @rpath/libcrypto.1.1.dylib ${work_dir}/python/lib/python3.*/lib-dynload/_ssl.cpython-3*-darwin.so
90 otool -L ${work_dir}/python/lib/python3.*/lib-dynload/_ssl.cpython-3*-darwin.so | grep @rpath/libssl.1.1.dylib
93 install_name_tool -change /xz/lib/liblzma.5.dylib @rpath/liblzma.5.dylib ${work_dir}/python/lib/python3.*/lib-dynload/_lzma.cpython-3*-darwin.so
94 otool -L ${work_dir}/python/lib/python3.*/lib-dynload/_lzma.cpython-3*-darwin.so | grep @rpath/liblzma.5.dylib
96 # Also modify the shipped libssl to use the shipped libcrypto
97 install_name_tool -change /usr/local/Cellar/openssl@1.1/1.1.1h/lib/libcrypto.1.1.dylib @rpath/libcrypto.1.1.dylib ${work_dir}/python/lib/libssl.1.1.dylib
98 otool -L ${work_dir}/python/lib/libssl.1.1.dylib | grep @rpath/libcrypto.1.1.dylib
100 # sanity check
101 ${work_dir}/python/bin/python3 -c "import ssl"
102 ${work_dir}/python/bin/python3 -c "import lzma"
104 # We may not have access to system certificate on OSX
105 ${work_dir}/python/bin/python3 -m pip install certifi==2024.2.2
107 Linux)
108 cp /usr/lib/x86_64-linux-gnu/libffi.so.* ${work_dir}/python/lib/
109 cp /usr/lib/x86_64-linux-gnu/libssl.so.* ${work_dir}/python/lib/
110 cp /usr/lib/x86_64-linux-gnu/libcrypto.so.* ${work_dir}/python/lib/
111 cp /lib/x86_64-linux-gnu/libncursesw.so.* ${work_dir}/python/lib/
112 cp /lib/x86_64-linux-gnu/libtinfo.so.* ${work_dir}/python/lib/
114 esac
116 $(dirname $0)/pack.sh ${tardir}