Skip to content

Instantly share code, notes, and snippets.

@minrk
Created March 6, 2024 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minrk/79120094662266fae8bbe2510a80403b to your computer and use it in GitHub Desktop.
Save minrk/79120094662266fae8bbe2510a80403b to your computer and use it in GitHub Desktop.
FROM ubuntu:22.04
RUN apt-get -y update && apt-get -y dist-upgrade
RUN apt-get -y install cmake ninja-build curl openssl xz-utils build-essential libz-dev libssl-dev
RUN curl -L -O https://www.python.org/ftp/python/3.11.8/Python-3.11.8.tar.xz \
&& tar -xf Python-3.11.8.tar.xz \
&& rm Python-3.11.8.tar.xz
ENV BUILD_PREFIX=/opt/build
ENV PATH=${BUILD_PREFIX}/bin:$PATH
# build our 'build' python
WORKDIR Python-3.11.8
RUN ./configure --prefix=${BUILD_PREFIX} \
&& make -j \
&& make install
# sanity check
RUN python3 -c 'import ssl' \
&& python3 -m ensurepip \
&& python3 -m pip install --upgrade pip
# build our 'host' python
# I'm on aarch64, so use x86_64 as host
ENV HOST="x86_64-linux-gnu"
RUN HOST_PKG=$(echo $HOST | sed s@_@-@g) \
&& apt-get -y install binutils-$HOST_PKG gcc-$HOST_PKG g++-$HOST_PKG
ENV CC=$HOST-gcc \
CXX=$HOST-g++
ENV BUILD="aarch64-linux-gnu"
RUN make clean
ENV HOST_PREFIX=/opt/host
RUN ./configure \
--prefix=${HOST_PREFIX} \
--host=$HOST \
--build=$BUILD \
--with-build-python=$BUILD_PREFIX/bin/python3 \
--without-ensurepip \
ac_cv_buggy_getaddrinfo=no \
ac_cv_file__dev_ptmx=yes \
ac_cv_file__dev_ptc=no \
&& make -j \
&& make install
WORKDIR /src
# (optional) cross-compile libsodium, libzmq
# ENV LIBSODIUM_VERSION=1.0.19
# RUN curl -L -O "https://download.libsodium.org/libsodium/releases/libsodium-${LIBSODIUM_VERSION}.tar.gz" \
# && tar -xzf libsodium-${LIBSODIUM_VERSION}.tar.gz \
# && cd libsodium-*/ \
# && ./configure --prefix="${HOST_PREFIX}" --host=$HOST \
# && make -j \
# && make install
#
# ENV LIBZMQ_VERSION=4.3.5
# RUN curl -L -O "https://github.com/zeromq/libzmq/releases/download/v${LIBZMQ_VERSION}/zeromq-${LIBZMQ_VERSION}.tar.gz" \
# && tar -xzf zeromq-${LIBZMQ_VERSION}.tar.gz \
# && cd zeromq-${LIBZMQ_VERSION} \
# && ./configure --prefix="$HOST_PREFIX" --host=$HOST --disable-perf --without-docs --enable-curve --with-libsodium=$HOST_PREFIX --disable-drafts --disable-libsodium_randombytes_close \
# && make -j \
# && make install
# setup crossenv
ENV CROSS_PREFIX=/opt/cross
RUN python3 -m pip install crossenv \
&& python3 -m crossenv ${HOST_PREFIX}/bin/python3 ${CROSS_PREFIX}
ENV PATH=${CROSS_PREFIX}/bin:$PATH
# install build dependencies in crossenv
RUN . ${CROSS_PREFIX}/bin/activate \
&& build-pip install build pyproject_metadata scikit-build-core pathspec cython
# if pyzmq is bundling libsodium, tell it to cross-compile
# not required if libzmq is already installed
ENV PYZMQ_LIBSODIUM_CONFIGURE_ARGS="--host $HOST"
# build wheel of pyzmq
RUN python3 -m pip download --no-binary pyzmq --pre pyzmq \
&& tar -xzf pyzmq-*.tar.gz \
&& rm pyzmq-*.tar.gz \
&& . ${CROSS_PREFIX}/bin/activate \
&& cross-python -m build --no-isolation --skip-dependency-check --wheel ./pyzmq*
# there is now a pyzmq wheel in /src/pyzmq-26.0.0b2/dist/pyzmq-26.0.0b2-cp311-cp311-linux_x86_64.whl
#
# COPY entrypoint /usr/local/bin/entrypoint
# ENTRYPOINT ["/usr/local/bin/entrypoint"]
# CMD ["bash"]
#!/bin/bash -l
source ${CROSS_PREFIX}/bin/activate
echo "cross-python3 -m build --no-isolation --skip-dependency-check --wheel ."
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment