diff --git a/cpython-unix/base.Dockerfile b/cpython-unix/base.Dockerfile index a07a3319..6ce27211 100644 --- a/cpython-unix/base.Dockerfile +++ b/cpython-unix/base.Dockerfile @@ -1,6 +1,4 @@ -# Debian Jessie. -FROM debian@sha256:734728c8e411698485ae644fc988dad06f757565e292b5b85edc084befa37bbb -MAINTAINER Gregory Szorc +FROM ubuntu:xenial RUN groupadd -g 1000 build && \ useradd -u 1000 -g 1000 -d /build -s /bin/bash -m build && \ @@ -17,10 +15,7 @@ ENV HOME=/build \ CMD ["/bin/bash", "--login"] WORKDIR '/build' -RUN for s in debian_jessie debian_jessie-updates debian-security_jessie/updates; do \ - echo "deb http://snapshot.debian.org/archive/${s%_*}/20200510T203930Z/ ${s#*_} main"; \ - done > /etc/apt/sources.list && \ - ( echo 'quiet "true";'; \ +RUN ( echo 'quiet "true";'; \ echo 'APT::Get::Assume-Yes "true";'; \ echo 'APT::Install-Recommends "false";'; \ echo 'Acquire::Check-Valid-Until "false";'; \ diff --git a/cpython-unix/build-bdb.sh b/cpython-unix/build-bdb.sh index 75dc6954..b6ed30a8 100755 --- a/cpython-unix/build-bdb.sh +++ b/cpython-unix/build-bdb.sh @@ -15,7 +15,7 @@ pushd db-${BDB_VERSION}/build_unix CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ../dist/configure \ --build=${BUILD_TRIPLE} \ - --target=${TARGET_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ --enable-dbm \ --disable-shared diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index 58d46731..ea8ccd11 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -248,6 +248,16 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_lib_intl_textdomain=yes" fi +if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then + CONFIGURE_FLAGS="--build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ + --disable-ipv6 \ + ${CONFIGURE_FLAGS} \ + ac_cv_file__dev_ptmx=no \ + ac_cv_file__dev_ptc=no" + export PYTHON_DECIMAL_WITH_MACHINE=uint128 +fi + CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS LDFLAGS=$LDFLAGS \ ./configure ${CONFIGURE_FLAGS} @@ -276,6 +286,11 @@ else PYTHON_BINARY_SUFFIX= fi +# Python interpreter to use during the build. +if [ -z "${BUILD_PYTHON}" ]; then + BUILD_PYTHON=${ROOT}/out/python/install/bin/python3 +fi + # If we're building a shared library hack some binaries so rpath is set. # This ensures we can run the binary in any location without # LD_LIBRARY_PATH pointing to the directory containing libpython. @@ -346,7 +361,7 @@ index ec9942f0..1b306ca7 100644 except AttributeError: EOF -${ROOT}/out/python/install/bin/python3 setup.py install +${BUILD_PYTHON} setup.py install popd pushd ${ROOT}/pip-${PIP_VERSION} @@ -385,7 +400,7 @@ index 60a69d8..08c0597 100644 except AttributeError: EOF -${ROOT}/out/python/install/bin/python3 setup.py install +${BUILD_PYTHON} setup.py install popd # Emit metadata to be used in PYTHON.json. @@ -428,9 +443,7 @@ with open(sys.argv[1], "w") as fh: json.dump(metadata, fh, sort_keys=True, indent=4) EOF -PYTHON_EXE=${ROOT}/out/python/install/bin/$(readlink ${ROOT}/out/python/install/bin/python3) - -${ROOT}/out/python/install/bin/python3 ${ROOT}/generate_metadata.py ${ROOT}/metadata.json +${BUILD_PYTHON} ${ROOT}/generate_metadata.py ${ROOT}/metadata.json cat ${ROOT}/metadata.json if [ "${CC}" != "musl-clang" ]; then diff --git a/cpython-unix/build-gdbm.sh b/cpython-unix/build-gdbm.sh index 6facfb84..f470baa5 100755 --- a/cpython-unix/build-gdbm.sh +++ b/cpython-unix/build-gdbm.sh @@ -15,9 +15,9 @@ pushd gdbm-${GDBM_VERSION} # CPython setup.py looks for libgdbm_compat and gdbm-ndbm.h, # which require --enable-libgdbm-compat. -CLFAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ +CLFAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LDFLAGS="${EXTRA_TARGET_CFLAGS}" ./configure \ --build=${BUILD_TRIPLE} \ - --target=${TARGET_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ --disable-shared \ --enable-libgdbm-compat diff --git a/cpython-unix/build-gettext.sh b/cpython-unix/build-gettext.sh index 16fe546e..96dd0ae5 100755 --- a/cpython-unix/build-gettext.sh +++ b/cpython-unix/build-gettext.sh @@ -17,7 +17,7 @@ pushd gettext-${GETTEXT_VERSION} # an added dependency. So we force use of the bundled version. CLFAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ --build=${BUILD_TRIPLE} \ - --target=${TARGET_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ --disable-shared \ --disable-java \ diff --git a/cpython-unix/build-inputproto.sh b/cpython-unix/build-inputproto.sh index adaf8096..5395635a 100755 --- a/cpython-unix/build-inputproto.sh +++ b/cpython-unix/build-inputproto.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` pkg-config --version @@ -15,8 +15,10 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig tar -xf inputproto-${INPUTPROTO_VERSION}.tar.gz pushd inputproto-${INPUTPROTO_VERSION} -CFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-kbproto.sh b/cpython-unix/build-kbproto.sh index 501e3efa..becad695 100755 --- a/cpython-unix/build-kbproto.sh +++ b/cpython-unix/build-kbproto.sh @@ -3,9 +3,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. -set -ex - -cd /build +ROOT=`pwd` pkg-config --version @@ -15,8 +13,10 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig tar -xf kbproto-${KBPROTO_VERSION}.tar.gz pushd kbproto-${KBPROTO_VERSION} -CFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-libX11.sh b/cpython-unix/build-libX11.sh index d761d592..d1fa17ad 100755 --- a/cpython-unix/build-libX11.sh +++ b/cpython-unix/build-libX11.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` export PATH=/tools/${TOOLCHAIN}/bin:/tools/host/bin:$PATH export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig:/tools/deps/lib/pkgconfig @@ -41,9 +41,17 @@ if [ "${CC}" = "musl-clang" ]; then EXTRA_FLAGS="--disable-shared" fi -CFLAGS="-fPIC -I/tools/deps/include" ./configure \ +if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then + EXTRA_FLAGS="${EXTRA_FLAGS} \ + --disable-ipv6 \ + xorg_cv_malloc0_returns_null=yes" +fi + +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC -I/tools/deps/include" CFLAGS_FOR_BUILD="-I/tools/deps/include" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ ${EXTRA_FLAGS} make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-libXau.sh b/cpython-unix/build-libXau.sh index 78afe59f..18f4f45c 100755 --- a/cpython-unix/build-libXau.sh +++ b/cpython-unix/build-libXau.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` export PATH=/tools/${TOOLCHAIN}/bin:/tools/host/bin:$PATH export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig:/tools/deps/lib/pkgconfig @@ -17,9 +17,11 @@ if [ "${CC}" = "musl-clang" ]; then EXTRA_FLAGS="--disable-shared" fi -CFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ ${EXTRA_FLAGS} make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-libpthread-stubs.sh b/cpython-unix/build-libpthread-stubs.sh index f7eb5b69..4d071795 100755 --- a/cpython-unix/build-libpthread-stubs.sh +++ b/cpython-unix/build-libpthread-stubs.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` pkg-config --version @@ -15,8 +15,10 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig tar -xf libpthread-stubs-${LIBPTHREAD_STUBS_VERSION}.tar.gz pushd libpthread-stubs-${LIBPTHREAD_STUBS_VERSION} -CFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-libressl.sh b/cpython-unix/build-libressl.sh index 9b7ddfb1..43eba9b6 100755 --- a/cpython-unix/build-libressl.sh +++ b/cpython-unix/build-libressl.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` export PATH=/tools/${TOOLCHAIN}/bin:/tools/host/bin:$PATH @@ -21,4 +21,4 @@ CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./ --disable-shared make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-libxcb.sh b/cpython-unix/build-libxcb.sh index fb853e6f..ba76fd3d 100755 --- a/cpython-unix/build-libxcb.sh +++ b/cpython-unix/build-libxcb.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` export PATH=/tools/${TOOLCHAIN}/bin:/tools/host/bin:$PATH export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig:/tools/deps/lib/pkgconfig @@ -17,9 +17,14 @@ if [ "${CC}" = "musl-clang" ]; then EXTRA_FLAGS="--disable-shared" fi -CFLAGS="-fPIC" ./configure \ +echo "############################################" +echo "##### ${CC}" + +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ ${EXTRA_FLAGS} make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out \ No newline at end of file diff --git a/cpython-unix/build-main.py b/cpython-unix/build-main.py index 092e2d1e..cbb2f37c 100755 --- a/cpython-unix/build-main.py +++ b/cpython-unix/build-main.py @@ -25,6 +25,8 @@ def main(): targets = { default_target_triple, "x86_64-unknown-linux-musl", + "aarch64-unknown-linux-gnu", + "arm-unknown-linux-gnueabihf", } elif sys.platform == "darwin": host_platform = "macos" diff --git a/cpython-unix/build-ncurses.sh b/cpython-unix/build-ncurses.sh index 5ba27838..1ce555ba 100755 --- a/cpython-unix/build-ncurses.sh +++ b/cpython-unix/build-ncurses.sh @@ -13,11 +13,27 @@ tar -xf ncurses-${NCURSES_VERSION}.tar.gz pushd ncurses-${NCURSES_VERSION} +patch -p1 << 'EOF' +diff --git a/configure b/configure +--- a/configure ++++ b/configure +@@ -15350,7 +15350,7 @@ echo "${ECHO_T}$with_stripping" >&6 + + if test "$with_stripping" = yes + then +- INSTALL_OPT_S="-s" ++ INSTALL_OPT_S="-s --strip-program=${STRIP}" + else + INSTALL_OPT_S= + fi +EOF + CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ --build=${BUILD_TRIPLE} \ --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ --without-cxx \ - --enable-widec + --enable-widec \ + --disable-db-install make -j ${NUM_CPUS} make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-openssl.sh b/cpython-unix/build-openssl.sh index 3e12cce9..6ded274b 100755 --- a/cpython-unix/build-openssl.sh +++ b/cpython-unix/build-openssl.sh @@ -25,11 +25,22 @@ fi if [ "${PYBUILD_PLATFORM}" = "macos" ]; then OPENSSL_TARGET=darwin64-x86_64-cc -else +elif [ "${TARGET_TRIPLE}" = "x86_64-unknown-linux-gnu" ]; then OPENSSL_TARGET=linux-x86_64 +elif [ "${TARGET_TRIPLE}" = "aarch64-unknown-linux-gnu" ]; then + OPENSSL_TARGET=linux-aarch64 +elif [ "${TARGET_TRIPLE}" = "arm-unknown-linux-gnueabihf" ]; then + OPENSSL_TARGET=linux-armv4 +else + echo "Error: unsupported target" + exit 1 fi -/usr/bin/perl ./Configure --prefix=/tools/deps ${OPENSSL_TARGET} no-shared ${EXTRA_FLAGS} +CFLAGS="${EXTRA_TARGET_CFLAGS}" /usr/bin/perl ./Configure \ + --prefix=/tools/deps \ + ${OPENSSL_TARGET} \ + no-shared \ + ${EXTRA_FLAGS} make -j ${NUM_CPUS} make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-readline.sh b/cpython-unix/build-readline.sh index 15ed664c..d3cf893c 100755 --- a/cpython-unix/build-readline.sh +++ b/cpython-unix/build-readline.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` export PATH=/tools/${TOOLCHAIN}/bin:/tools/host/bin:$PATH @@ -22,4 +22,4 @@ CLFAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LD --with-curses make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-sqlite.sh b/cpython-unix/build-sqlite.sh index 9053aa4d..38155009 100755 --- a/cpython-unix/build-sqlite.sh +++ b/cpython-unix/build-sqlite.sh @@ -12,7 +12,9 @@ export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:$PATH tar -xf sqlite-autoconf-${SQLITE_VERSION}.tar.gz pushd sqlite-autoconf-${SQLITE_VERSION} -CFLAGS="-fPIC" CPPFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="-fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix /tools/deps \ --disable-shared diff --git a/cpython-unix/build-tcl.sh b/cpython-unix/build-tcl.sh index d77ae571..c0e8a454 100755 --- a/cpython-unix/build-tcl.sh +++ b/cpython-unix/build-tcl.sh @@ -40,6 +40,8 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then fi CFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ --enable-shared=no \ --enable-threads diff --git a/cpython-unix/build-tix.sh b/cpython-unix/build-tix.sh index e3a46d8b..d3f093e3 100755 --- a/cpython-unix/build-tix.sh +++ b/cpython-unix/build-tix.sh @@ -33,7 +33,9 @@ fi # -DUSE_INTERP_RESULT is to allow tix to use deprecated fields or something # like that. -CFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} ${CFLAGS}" CPPFLAGS="${EXTRA_TARGET_CFLAGS} ${CFLAGS}" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ --with-tcl=${TOOLS_PATH}/deps/lib \ --with-tk=${TOOLS_PATH}/deps/lib \ diff --git a/cpython-unix/build-tk.sh b/cpython-unix/build-tk.sh index 97455116..5a136df3 100755 --- a/cpython-unix/build-tk.sh +++ b/cpython-unix/build-tk.sh @@ -110,7 +110,9 @@ else EXTRA_CONFIGURE_FLAGS="--x-includes=${TOOLS_PATH}/deps/include --x-libraries=${TOOLS_PATH}/deps/lib" fi -CFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} ${CFLAGS}" CPPFLAGS="${EXTRA_TARGET_CFLAGS} ${CFLAGS}" LDFLAGS="${LDFLAGS}" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ --with-tcl=${TOOLS_PATH}/deps/lib \ --enable-shared=no \ diff --git a/cpython-unix/build-uuid.sh b/cpython-unix/build-uuid.sh index a2116990..22c10c1f 100755 --- a/cpython-unix/build-uuid.sh +++ b/cpython-unix/build-uuid.sh @@ -12,7 +12,9 @@ export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:$PATH tar -xf libuuid-${UUID_VERSION}.tar.gz pushd libuuid-${UUID_VERSION} -CFLAGS="-fPIC" CPPFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ --disable-shared diff --git a/cpython-unix/build-x11-util-macros.sh b/cpython-unix/build-x11-util-macros.sh index 15289337..0618d415 100755 --- a/cpython-unix/build-x11-util-macros.sh +++ b/cpython-unix/build-x11-util-macros.sh @@ -5,14 +5,16 @@ set -ex -cd /build +ROOT=`pwd` export PATH=/tools/${TOOLCHAIN}/bin:/tools/host/bin:$PATH tar -xzf util-macros-${X11_UTIL_MACROS_VERSION}.tar.gz pushd util-macros-${X11_UTIL_MACROS_VERSION} -./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS}" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-xcb-proto.sh b/cpython-unix/build-xcb-proto.sh index 53b472cb..c3709208 100755 --- a/cpython-unix/build-xcb-proto.sh +++ b/cpython-unix/build-xcb-proto.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` pkg-config --version @@ -15,8 +15,10 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig tar -xf xcb-proto-${XCB_PROTO_VERSION}.tar.gz pushd xcb-proto-${XCB_PROTO_VERSION} -CFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-xextproto.sh b/cpython-unix/build-xextproto.sh index cbb2f0f7..1c5a72a7 100755 --- a/cpython-unix/build-xextproto.sh +++ b/cpython-unix/build-xextproto.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` pkg-config --version @@ -15,8 +15,10 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig tar -xf xextproto-${XEXTPROTO_VERSION}.tar.gz pushd xextproto-${XEXTPROTO_VERSION} -CFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-xorgproto.sh b/cpython-unix/build-xorgproto.sh index 1088f281..27fe9473 100755 --- a/cpython-unix/build-xorgproto.sh +++ b/cpython-unix/build-xorgproto.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` pkg-config --version @@ -15,8 +15,10 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig tar -xf xorgproto-${XORGPROTO_VERSION}.tar.gz pushd xorgproto-${XORGPROTO_VERSION} -CFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out \ No newline at end of file diff --git a/cpython-unix/build-xproto.sh b/cpython-unix/build-xproto.sh index d26b5fc6..fa2c57cb 100755 --- a/cpython-unix/build-xproto.sh +++ b/cpython-unix/build-xproto.sh @@ -15,7 +15,9 @@ export PKG_CONFIG_PATH=${TOOLS_PATH}/deps/share/pkgconfig tar -xf xproto-${XPROTO_VERSION}.tar.gz pushd xproto-${XPROTO_VERSION} -CFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps make -j ${NUM_CPUS} diff --git a/cpython-unix/build-xtrans.sh b/cpython-unix/build-xtrans.sh index ddc22d5d..c116d46b 100755 --- a/cpython-unix/build-xtrans.sh +++ b/cpython-unix/build-xtrans.sh @@ -5,7 +5,7 @@ set -ex -cd /build +ROOT=`pwd` pkg-config --version @@ -15,8 +15,10 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig tar -xf xtrans-${XTRANS_VERSION}.tar.gz pushd xtrans-${XTRANS_VERSION} -CFLAGS="-fPIC" ./configure \ +CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps make -j `nproc` -make -j `nproc` install DESTDIR=/build/out +make -j `nproc` install DESTDIR=${ROOT}/out diff --git a/cpython-unix/build-xz.sh b/cpython-unix/build-xz.sh index 6b2bd82b..4fcf7697 100755 --- a/cpython-unix/build-xz.sh +++ b/cpython-unix/build-xz.sh @@ -14,6 +14,8 @@ tar -xf xz-${XZ_VERSION}.tar.gz pushd xz-${XZ_VERSION} CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CCASFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" ./configure \ + --build=${BUILD_TRIPLE} \ + --host=${TARGET_TRIPLE} \ --prefix=/tools/deps \ --disable-shared \ --disable-xz \ diff --git a/cpython-unix/build.Dockerfile b/cpython-unix/build.Dockerfile index faf7edea..edbbba74 100644 --- a/cpython-unix/build.Dockerfile +++ b/cpython-unix/build.Dockerfile @@ -10,3 +10,6 @@ RUN apt-get install \ tar \ xz-utils \ unzip + +RUN apt-get install crossbuild-essential-arm64 &&\ + apt-get install crossbuild-essential-armhf diff --git a/cpython-unix/build.py b/cpython-unix/build.py index 8c4973f4..163d8e5d 100755 --- a/cpython-unix/build.py +++ b/cpython-unix/build.py @@ -37,15 +37,28 @@ MACOSX_DEPLOYMENT_TARGET = "10.9" +def cross_compiling(host_platform, target_triple): + if "linux" in host_platform and "x86_64" not in target_triple: + return True + else: + return False -def add_target_env(env, platform, build_env): +def add_target_env(env, platform, target_triple, build_env): env["PYBUILD_PLATFORM"] = platform env["NUM_CPUS"] = "%d" % multiprocessing.cpu_count() env["TOOLS_PATH"] = build_env.tools_path if platform == "linux64": env["BUILD_TRIPLE"] = "x86_64-unknown-linux-gnu" - env["TARGET_TRIPLE"] = "x86_64-unknown-linux-gnu" + env["TARGET_TRIPLE"] = target_triple + if "musl" in target_triple: + env["CC_FOR_BUILD"] = "musl-clang" + env["CC"] = "musl-clang" + else: + env["CC_FOR_BUILD"] = "clang" + env["CC"] = "cross-clang" if cross_compiling(platform, target_triple) else "clang" + env["READELF"] = "llvm-readelf" + env["STRIP"] = "llvm-strip" if platform == "macos": env["MACOSX_DEPLOYMENT_TARGET"] = MACOSX_DEPLOYMENT_TARGET @@ -109,6 +122,7 @@ def simple_build( binutils=install_binutils(host_platform), clang=True, musl="musl" in target_triple, + target_triple=target_triple, ) for a in extra_archives or []: @@ -122,10 +136,8 @@ def simple_build( "TOOLCHAIN": "clang-%s" % host_platform, "%s_VERSION" % entry.upper().replace("-", "_"): DOWNLOADS[entry]["version"], } - if "musl" in target_triple: - env["CC"] = "musl-clang" - add_target_env(env, host_platform, build_env) + add_target_env(env, host_platform, target_triple, build_env) build_env.run("build-%s.sh" % entry, environment=env) @@ -271,6 +283,7 @@ def build_libedit( binutils=install_binutils(host_platform), clang=True, musl="musl" in target_triple, + target_triple=target_triple, ) build_env.install_artifact_archive( @@ -285,10 +298,7 @@ def build_libedit( "LIBEDIT_VERSION": DOWNLOADS["libedit"]["version"], } - if "musl" in target_triple: - env["CC"] = "musl-clang" - - add_target_env(env, host_platform, build_env) + add_target_env(env, host_platform, target_triple, build_env) build_env.run("build-libedit.sh", environment=env) build_env.get_tools_archive(dest_archive, "deps") @@ -306,6 +316,7 @@ def build_readline( binutils=True, clang=True, musl="musl" in target_triple, + target_triple=target_triple, ) build_env.install_artifact_archive( @@ -320,10 +331,7 @@ def build_readline( "READLINE_VERSION": DOWNLOADS["readline"]["version"], } - if "musl" in target_triple: - env["CC"] = "musl-clang" - - add_target_env(env, host_platform, build_env) + add_target_env(env, host_platform, target_triple, build_env) build_env.run("build-readline.sh", environment=env) build_env.get_tools_archive(dest_archive, "deps") @@ -341,6 +349,7 @@ def build_tix(client, image, host_platform, target_triple, optimizations, dest_a binutils=install_binutils(host_platform), clang=True, musl="musl" in target_triple, + target_triple=target_triple, ) depends = {"tcl", "tk"} @@ -361,10 +370,7 @@ def build_tix(client, image, host_platform, target_triple, optimizations, dest_a "TK_VERSION": DOWNLOADS["tk"]["version"], } - if "musl" in target_triple: - env["CC"] = "musl-clang" - - add_target_env(env, host_platform, build_env) + add_target_env(env, host_platform, target_triple, build_env) build_env.run("build-tix.sh", environment=env) build_env.get_tools_archive(dest_archive, "deps") @@ -647,6 +653,7 @@ def build_cpython( binutils=install_binutils(host_platform), clang=True, musl="musl" in target_triple, + target_triple=target_triple, ) # TODO support bdb/gdbm toggle @@ -725,9 +732,6 @@ def build_cpython( "TOOLCHAIN": "clang-%s" % host_platform, } - if "musl" in target_triple: - env["CC"] = "musl-clang" - if optimizations == "debug": env["CPYTHON_DEBUG"] = "1" if optimizations in ("pgo", "pgo+lto"): @@ -735,7 +739,12 @@ def build_cpython( if optimizations in ("lto", "pgo+lto"): env["CPYTHON_LTO"] = "1" - add_target_env(env, host_platform, build_env) + if cross_compiling(host_platform, target_triple): + build_env.install_artifact_archive(BUILD, entry_name, "x86_64-unknown-linux-gnu", optimizations) + env["PATH"] = "/tools/python/install/bin:{}".format(os.environ["PATH"]) + env["BUILD_PYTHON"] = "python3" + + add_target_env(env, host_platform, target_triple, build_env) build_env.run("build-cpython.sh", environment=env) diff --git a/cpython-unix/static-modules.3.7.linux64 b/cpython-unix/static-modules.3.7.linux64 index 45ab7adc..da0b2b11 100644 --- a/cpython-unix/static-modules.3.7.linux64 +++ b/cpython-unix/static-modules.3.7.linux64 @@ -8,7 +8,7 @@ _crypt _cryptmodule.c -lcrypt _curses _cursesmodule.c -DHAVE_NCURSESW=1 -I/tools/deps/include/ncursesw -L/tools/deps/lib -lncursesw _curses_panel _curses_panel.c -DHAVE_NCURSESW=1 -I/tools/deps/include/ncursesw -L/tools/deps/lib -lpanelw -lncursesw _ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c -I/tools/deps/lib/libffi-3.2.1/include -lffi -ldl -_decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/constants.c _decimal/libmpdec/context.c _decimal/libmpdec/convolute.c _decimal/libmpdec/crt.c _decimal/libmpdec/difradix2.c _decimal/libmpdec/fnt.c _decimal/libmpdec/fourstep.c _decimal/libmpdec/io.c _decimal/libmpdec/memory.c _decimal/libmpdec/mpdecimal.c _decimal/libmpdec/numbertheory.c _decimal/libmpdec/sixstep.c _decimal/libmpdec/transpose.c -DCONFIG_64=1 -DASM=1 -IModules/_decimal/libmpdec +#_decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/constants.c _decimal/libmpdec/context.c _decimal/libmpdec/convolute.c _decimal/libmpdec/crt.c _decimal/libmpdec/difradix2.c _decimal/libmpdec/fnt.c _decimal/libmpdec/fourstep.c _decimal/libmpdec/io.c _decimal/libmpdec/memory.c _decimal/libmpdec/mpdecimal.c _decimal/libmpdec/numbertheory.c _decimal/libmpdec/sixstep.c _decimal/libmpdec/transpose.c -DCONFIG_64=1 -DASM=1 -IModules/_decimal/libmpdec _dbm _dbmmodule.c -DHAVE_BERKDB_H -DDB_DBM_HSEARCH -I/tools/deps/include -L/tools/deps/lib -ldb _elementtree _elementtree.c -DHAVE_EXPAT_CONFIG_H=1 -DXML_POOR_ENTROPY=1 -DUSE_PYEXPAT_CAPI -IModules/expat # Cannot build _gdbm due to use of bdb. diff --git a/cpython-unix/static-modules.3.8.linux64 b/cpython-unix/static-modules.3.8.linux64 index a7616153..0b5a9d20 100644 --- a/cpython-unix/static-modules.3.8.linux64 +++ b/cpython-unix/static-modules.3.8.linux64 @@ -8,7 +8,7 @@ _crypt _cryptmodule.c -lcrypt _curses _cursesmodule.c -DHAVE_NCURSESW=1 -I/tools/deps/include/ncursesw -L/tools/deps/lib -lncursesw _curses_panel _curses_panel.c -DHAVE_NCURSESW=1 -I/tools/deps/include/ncursesw -L/tools/deps/lib -lpanelw -lncursesw _ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c -I/tools/deps/lib/libffi-3.2.1/include -lffi -ldl -_decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/constants.c _decimal/libmpdec/context.c _decimal/libmpdec/convolute.c _decimal/libmpdec/crt.c _decimal/libmpdec/difradix2.c _decimal/libmpdec/fnt.c _decimal/libmpdec/fourstep.c _decimal/libmpdec/io.c _decimal/libmpdec/memory.c _decimal/libmpdec/mpdecimal.c _decimal/libmpdec/numbertheory.c _decimal/libmpdec/sixstep.c _decimal/libmpdec/transpose.c -DCONFIG_64=1 -DASM=1 -IModules/_decimal/libmpdec +#_decimal _decimal/_decimal.c _decimal/libmpdec/basearith.c _decimal/libmpdec/constants.c _decimal/libmpdec/context.c _decimal/libmpdec/convolute.c _decimal/libmpdec/crt.c _decimal/libmpdec/difradix2.c _decimal/libmpdec/fnt.c _decimal/libmpdec/fourstep.c _decimal/libmpdec/io.c _decimal/libmpdec/memory.c _decimal/libmpdec/mpdecimal.c _decimal/libmpdec/numbertheory.c _decimal/libmpdec/sixstep.c _decimal/libmpdec/transpose.c -IModules/_decimal/libmpdec _dbm _dbmmodule.c -DHAVE_BERKDB_H -DDB_DBM_HSEARCH -I/tools/deps/include -L/tools/deps/lib -ldb _elementtree _elementtree.c -DHAVE_EXPAT_CONFIG_H=1 -DXML_POOR_ENTROPY=1 -DUSE_PYEXPAT_CAPI -IModules/expat # Cannot build _gdbm due to use of bdb. diff --git a/pythonbuild/buildenv.py b/pythonbuild/buildenv.py index 027d4bed..802c07b8 100644 --- a/pythonbuild/buildenv.py +++ b/pythonbuild/buildenv.py @@ -40,6 +40,8 @@ def install_artifact_archive( self, build_dir, package_name, target_triple, optimizations ): entry = DOWNLOADS[package_name] + if package_name.startswith("cpython-"): + package_name = "cpython" basename = "%s-%s-%s-%s.tar" % ( package_name, entry["version"], @@ -60,6 +62,7 @@ def install_toolchain( gcc=False, musl=False, clang=False, + target_triple=None ): if binutils: self.install_toolchain_archive(build_dir, "binutils", host_platform) @@ -69,6 +72,16 @@ def install_toolchain( if clang: self.install_toolchain_archive(build_dir, "clang", host_platform) + if target_triple: + bin_dir = pathlib.Path("/tools") / "clang-{}".format(host_platform) / "bin" + with tempfile.NamedTemporaryFile() as temp: + gnu_triple = target_triple.replace("unknown-", "") + with open(temp.name, "w") as f: + f.write("#!/bin/bash\n"); + f.write("exec {0} --target={1} -I/usr/{2}/include -Wno-incomplete-setjmp-declaration \"$@\"\n" + .format(bin_dir / "clang", target_triple, gnu_triple)) + os.chmod(temp.name, 0o755) + self.copy_file(pathlib.Path(temp.name), bin_dir, "cross-clang") if musl: self.install_toolchain_archive(build_dir, "musl", host_platform)