From 6b6b1240e2aab4e5c110a08631b9333feadf9155 Mon Sep 17 00:00:00 2001 From: Dmitry Tretyakov Date: Wed, 7 Feb 2024 00:47:09 +0100 Subject: [PATCH] docker: build linux/arm64 images (#398) --- .github/workflows/docker.yml | 43 ++++++++++++++++++++++++++++++++++++ .gitignore | 1 + Dockerfile.toolchain | 41 ++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 Dockerfile.toolchain diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5015a92..6dcf82c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -69,3 +69,46 @@ jobs: - name: Inspect Docker images run: | docker images + + docker-build-toolchain: + needs: [prepare] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ (inputs.commit != '' && inputs.commit) || inputs.branch }} + - name: Download toolchain + uses: dawidd6/action-download-artifact@v3 + with: + workflow: build.yml + workflow_conclusion: success + commit: ${{inputs.commit}} + branch: ${{inputs.branch}} + event: push + name: linux-ucrt-.* + name_is_regexp: true + path: toolchain + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to Docker Hub + if: ${{inputs.login}} + uses: docker/login-action@v3 + with: + username: ${{secrets.DOCKER_USERNAME}} + password: ${{secrets.DOCKER_PASSWORD}} + - name: Build Docker images + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/arm64 + push: ${{inputs.push}} + file: ./Dockerfile.toolchain + load: true + tags: | + mstorsjo/llvm-mingw:latest + mstorsjo/llvm-mingw:${{needs.prepare.outputs.TAG}} + - name: Inspect Docker images + run: | + docker images diff --git a/.gitignore b/.gitignore index 337eb1d..0a98d03 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /libffi /cpython* /python-native +/toolchain diff --git a/Dockerfile.toolchain b/Dockerfile.toolchain new file mode 100644 index 0000000..d00a116 --- /dev/null +++ b/Dockerfile.toolchain @@ -0,0 +1,41 @@ +FROM ubuntu:20.04 + +RUN apt-get update -qq && \ + DEBIAN_FRONTEND="noninteractive" apt-get install -qqy --no-install-recommends \ + git wget bzip2 file unzip libtool pkg-config cmake build-essential \ + automake yasm gettext autopoint vim-tiny python3 python3-distutils \ + ninja-build ca-certificates curl less zip && \ + apt-get clean -y && \ + rm -rf /var/lib/apt/lists/* + +# Manually install a newer version of CMake; this is needed since building +# LLVM requires CMake 3.20, while Ubuntu 20.04 ships with 3.16.3. If +# updating to a newer distribution, this can be dropped. +RUN cd /opt && \ + curl -LO https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4-Linux-$(uname -m).tar.gz && \ + tar -zxf cmake-*.tar.gz && \ + rm cmake-*.tar.gz && \ + mv cmake-* cmake +ENV PATH=/opt/cmake/bin:$PATH + + +RUN git config --global user.name "LLVM MinGW" && \ + git config --global user.email root@localhost + +WORKDIR /build + +ENV TOOLCHAIN_PREFIX=/opt/llvm-mingw + +ARG TOOLCHAIN_ARCHS="i686 x86_64 armv7 aarch64" + +# Copy prebuilt toolchains for the current architecture. +# Test executing a binary, to make sure that it works (i.e. it is not built +# requiring a newer version of glibc or libstdc++ than what is available in +# this container). +RUN --mount=type=bind,source=toolchain,target=/toolchain \ + mkdir -p $TOOLCHAIN_PREFIX && ARCH=$(uname -m) && \ + tar xf /toolchain/linux-ucrt-$ARCH-toolchain/llvm-mingw-*-$ARCH.tar.xz --strip-components 1 -C $TOOLCHAIN_PREFIX && \ + ANY_ARCH=$(echo $TOOLCHAIN_ARCHS | awk '{print $1}') && \ + $TOOLCHAIN_PREFIX/bin/$ANY_ARCH-w64-mingw32-clang --version + +ENV PATH=$TOOLCHAIN_PREFIX/bin:$PATH