|
| 1 | + |
| 2 | +ARG UBUNTU=22.04 |
| 3 | +FROM wpilib/roborio-cross-ubuntu-minimal:2024-${UBUNTU} AS pycompile |
| 4 | + |
| 5 | +ENV TARGET_HOST="arm-frc2024-linux-gnueabi" |
| 6 | +ENV AC_TARGET_HOST="armv7l-frc2024-linux-gnueabi" |
| 7 | +ENV BUILD_HOST="x86_64" |
| 8 | +ENV WORKING_DIRECTORY="/build" |
| 9 | +ENV INSTALL_DIRECTORY="/build/crosspy" |
| 10 | +ENV PYTHON_VERSION="3.12.0" |
| 11 | +ENV PYTHON_FTP_VERSION="3.12.0" |
| 12 | +ENV PYTHON_EXE="python3.12" |
| 13 | +ENV SOURCE_DIRECTORY="Python-$PYTHON_VERSION" |
| 14 | +ENV PYTHON_ARCHIVE="Python-$PYTHON_VERSION.tar.xz" |
| 15 | +ENV PREFIX="$INSTALL_DIRECTORY" |
| 16 | + |
| 17 | +# |
| 18 | +# Python compilation prereqs |
| 19 | +# |
| 20 | + |
| 21 | +RUN set -xe; \ |
| 22 | + apt-get update; \ |
| 23 | + apt-get install -y build-essential checkinstall g++ libreadline-dev libncursesw5-dev libssl-dev \ |
| 24 | + libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev liblzma-dev lzma-dev libffi-dev zlib1g-dev; \ |
| 25 | + # cleanup |
| 26 | + rm -rf /var/lib/apt/lists/* |
| 27 | + |
| 28 | +# |
| 29 | +# Python cross-compilation |
| 30 | +# |
| 31 | + |
| 32 | +COPY 0001-Use-specified-host_cpu-when-cross-compiling-for-Linu.patch / |
| 33 | + |
| 34 | +RUN set -xe; \ |
| 35 | + mkdir -p "$PREFIX"; \ |
| 36 | + # Download |
| 37 | + cd $WORKING_DIRECTORY; \ |
| 38 | + wget -c https://www.python.org/ftp/python/$PYTHON_FTP_VERSION/$PYTHON_ARCHIVE; \ |
| 39 | + rm -rf $SOURCE_DIRECTORY; \ |
| 40 | + tar -xf $PYTHON_ARCHIVE; \ |
| 41 | + cd $SOURCE_DIRECTORY; \ |
| 42 | + # patch arm cpu hardcoding |
| 43 | + patch -p1 < /0001-Use-specified-host_cpu-when-cross-compiling-for-Linu.patch; \ |
| 44 | + # Build python for host |
| 45 | + cd $WORKING_DIRECTORY;cd $SOURCE_DIRECTORY; \ |
| 46 | + ./configure --enable-optimizations --with-ensurepip=install; \ |
| 47 | + make -j; \ |
| 48 | + make -j altinstall |
| 49 | + |
| 50 | +RUN set -xe; \ |
| 51 | + # Remove build dependencies -- compilation uses host for some reason |
| 52 | + apt-get remove -y libreadline-dev libncursesw5-dev libssl-dev \ |
| 53 | + libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev liblzma-dev lzma-dev libffi-dev zlib1g-dev; \ |
| 54 | + apt-get autoremove -y; |
| 55 | + |
| 56 | +RUN set -xe; \ |
| 57 | + # cross-compile for frc |
| 58 | + cd $WORKING_DIRECTORY;cd $SOURCE_DIRECTORY; make distclean; \ |
| 59 | + ./configure --host=$TARGET_HOST --build=$BUILD_HOST --prefix=$PREFIX \ |
| 60 | + --with-build-python=$(which $PYTHON_EXE) \ |
| 61 | + --disable-ipv6 \ |
| 62 | + ac_cv_host=$AC_TARGET_HOST \ |
| 63 | + ac_cv_buggy_getaddrinfo=no \ |
| 64 | + ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \ |
| 65 | + ac_cv_have_long_long_format=yes \ |
| 66 | + ac_cv_pthread_is_default=no ac_cv_pthread=yes ac_cv_cxx_thread=yes; \ |
| 67 | + make -j; \ |
| 68 | + # make install here is fine because we include --prefix in the configure statement |
| 69 | + make install |
| 70 | + |
| 71 | + |
| 72 | +# |
| 73 | +# Minimal cross-compilation environment |
| 74 | +# |
| 75 | + |
| 76 | +FROM wpilib/roborio-cross-ubuntu-minimal:2024-${UBUNTU} AS crossenv |
| 77 | + |
| 78 | +RUN set -xe; \ |
| 79 | + apt-get update; \ |
| 80 | + apt-get install -y \ |
| 81 | + binutils libreadline8 libncursesw5 libssl3 \ |
| 82 | + libsqlite3-0 libgdbm6 libbz2-1.0 liblzma5 libffi7 zlib1g; \ |
| 83 | + rm -rf /var/lib/apt/lists/* |
| 84 | + |
| 85 | +COPY --from=pycompile /usr/local /usr/local |
| 86 | +COPY --from=pycompile /build/crosspy /build/crosspy |
| 87 | + |
| 88 | +RUN set -xe; \ |
| 89 | + ldconfig; \ |
| 90 | + python3.12 -m pip install 'crossenv~=1.4.0'; \ |
| 91 | + python3.12 -m crossenv /build/crosspy/bin/python3.12 /build/venv --sysroot=$(arm-frc2024-linux-gnueabi-gcc -print-sysroot) --env UNIXCONFDIR=/build/venv/cross/etc; \ |
| 92 | + /build/venv/bin/cross-pip install wheel; |
| 93 | + |
| 94 | +COPY pip.conf /build/venv/cross/pip.conf |
| 95 | +COPY os-release /build/venv/cross/etc/os-release |
| 96 | + |
| 97 | +ENV RPYBUILD_PARALLEL=1 |
| 98 | + |
0 commit comments