From 5d1d5ca45e5e2aff89008aef462a06fbc1169a7d Mon Sep 17 00:00:00 2001 From: Niven Date: Thu, 13 Apr 2023 11:44:53 +0800 Subject: [PATCH] Niven/macos arm64build (#1893) * Build pipeline for building on arm64 macOS host architecture. Included CI build workflow for building the arm64 binaries * Rename to aarch64-apple-darwin to resolve build dependency bug * Amended markdown documentation (cherry picked from commit 29e10bee147c68c22583f8a5752ee4db0e211689) --- .github/workflows/build-dev.yaml | 17 +++++++++++++ .../aarch64-apple-darwin.dockerfile | 24 +++++++++++++++++++ .../dockerfiles/aarch64-linux-gnu.dockerfile | 2 +- .../arm-linux-gnueabihf.dockerfile | 2 +- .../x86_64-apple-darwin.dockerfile | 2 +- .../x86_64-pc-linux-gnu-clang.dockerfile | 4 ++-- .../x86_64-pc-linux-gnu.dockerfile | 4 ++-- .../dockerfiles/x86_64-w64-mingw32.dockerfile | 2 +- doc/build-quick.md | 2 +- make.sh | 8 ++++++- 10 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 contrib/dockerfiles/aarch64-apple-darwin.dockerfile diff --git a/.github/workflows/build-dev.yaml b/.github/workflows/build-dev.yaml index 52e5ac86801..9a28fde28df 100644 --- a/.github/workflows/build-dev.yaml +++ b/.github/workflows/build-dev.yaml @@ -95,3 +95,20 @@ jobs: with: name: defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-apple-darwin.tar.gz + + mac-aarch64: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Populate environment + run: GIT_VERSION=1 ./make.sh ci-export-vars + + - name: Build and package + run: GIT_VERSION=1 TARGET="aarch64-apple-darwin" ./make.sh docker-release + + - name: Publish artifact - aarch64-apple-darwin + uses: actions/upload-artifact@v3 + with: + name: defichain-${{ env.BUILD_VERSION }}-aarch64-apple-darwin + path: ./build/defichain-${{ env.BUILD_VERSION }}-aarch64-apple-darwin.tar.gz diff --git a/contrib/dockerfiles/aarch64-apple-darwin.dockerfile b/contrib/dockerfiles/aarch64-apple-darwin.dockerfile new file mode 100644 index 00000000000..95eec306643 --- /dev/null +++ b/contrib/dockerfiles/aarch64-apple-darwin.dockerfile @@ -0,0 +1,24 @@ +ARG TARGET=aarch64-apple-darwin + +# ----------- +FROM --platform=linux/amd64 ubuntu:latest as builder +ARG TARGET +LABEL org.defichain.name="defichain-builder" +LABEL org.defichain.arch=${TARGET} + +WORKDIR /work +COPY ./make.sh . + +RUN export DEBIAN_FRONTEND=noninteractive && ./make.sh pkg_update_base +RUN export DEBIAN_FRONTEND=noninteractive && ./make.sh pkg_install_deps +RUN export DEBIAN_FRONTEND=noninteractive && ./make.sh pkg_install_deps_osx_tools + +COPY . . +RUN ./make.sh clean-depends && ./make.sh build-deps +RUN ./make.sh clean-conf && ./make.sh build-conf +RUN ./make.sh build-make + +RUN mkdir /app && cd build/${TARGET} && \ + make -s prefix=/ DESTDIR=/app install + +# NOTE: These are not runnable images. So we do not add into a scratch base image. diff --git a/contrib/dockerfiles/aarch64-linux-gnu.dockerfile b/contrib/dockerfiles/aarch64-linux-gnu.dockerfile index 2cbd6f017ff..360fb7357d8 100644 --- a/contrib/dockerfiles/aarch64-linux-gnu.dockerfile +++ b/contrib/dockerfiles/aarch64-linux-gnu.dockerfile @@ -1,7 +1,7 @@ ARG TARGET=aarch64-linux-gnu # ----------- -FROM ubuntu:latest as builder +FROM --platform=linux/amd64 ubuntu:latest as builder ARG TARGET LABEL org.defichain.name="defichain-builder" LABEL org.defichain.arch=${TARGET} diff --git a/contrib/dockerfiles/arm-linux-gnueabihf.dockerfile b/contrib/dockerfiles/arm-linux-gnueabihf.dockerfile index 26c268cafed..54da2680181 100644 --- a/contrib/dockerfiles/arm-linux-gnueabihf.dockerfile +++ b/contrib/dockerfiles/arm-linux-gnueabihf.dockerfile @@ -1,7 +1,7 @@ ARG TARGET=arm-linux-gnueabihf # ----------- -FROM ubuntu:latest as builder +FROM --platform=linux/amd64 ubuntu:latest as builder ARG TARGET LABEL org.defichain.name="defichain-builder" LABEL org.defichain.arch=${TARGET} diff --git a/contrib/dockerfiles/x86_64-apple-darwin.dockerfile b/contrib/dockerfiles/x86_64-apple-darwin.dockerfile index bd644844092..965642ae45c 100644 --- a/contrib/dockerfiles/x86_64-apple-darwin.dockerfile +++ b/contrib/dockerfiles/x86_64-apple-darwin.dockerfile @@ -1,7 +1,7 @@ ARG TARGET=x86_64-apple-darwin # ----------- -FROM ubuntu:latest as builder +FROM --platform=linux/amd64 ubuntu:latest as builder ARG TARGET LABEL org.defichain.name="defichain-builder" LABEL org.defichain.arch=${TARGET} diff --git a/contrib/dockerfiles/x86_64-pc-linux-gnu-clang.dockerfile b/contrib/dockerfiles/x86_64-pc-linux-gnu-clang.dockerfile index cd1e18f61d0..bae87a224ff 100644 --- a/contrib/dockerfiles/x86_64-pc-linux-gnu-clang.dockerfile +++ b/contrib/dockerfiles/x86_64-pc-linux-gnu-clang.dockerfile @@ -1,7 +1,7 @@ ARG TARGET=x86_64-pc-linux-gnu # ----------- -FROM debian:10 as builder +FROM --platform=linux/amd64 debian:10 as builder ARG TARGET ARG CLANG_VERSION=15 LABEL org.defichain.name="defichain-builder" @@ -31,7 +31,7 @@ RUN mkdir /app && cd build/${TARGET} && \ # ----------- ### Actual image that contains defi binaries -FROM debian:10 +FROM --platform=linux/amd64 debian:10 ARG TARGET LABEL org.defichain.name="defichain" LABEL org.defichain.arch=${TARGET} diff --git a/contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile b/contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile index 53d8cbbe868..8a79ca7b066 100644 --- a/contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile +++ b/contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile @@ -1,7 +1,7 @@ ARG TARGET=x86_64-pc-linux-gnu # ----------- -FROM ubuntu:latest as builder +FROM --platform=linux/amd64 ubuntu:latest as builder ARG TARGET LABEL org.defichain.name="defichain-builder" LABEL org.defichain.arch=${TARGET} @@ -23,7 +23,7 @@ RUN mkdir /app && cd build/${TARGET} && \ # ----------- ### Actual image that contains defi binaries -FROM ubuntu:latest +FROM --platform=linux/amd64 ubuntu:latest ARG TARGET LABEL org.defichain.name="defichain" LABEL org.defichain.arch=${TARGET} diff --git a/contrib/dockerfiles/x86_64-w64-mingw32.dockerfile b/contrib/dockerfiles/x86_64-w64-mingw32.dockerfile index d6af1ddb856..35d1f502782 100644 --- a/contrib/dockerfiles/x86_64-w64-mingw32.dockerfile +++ b/contrib/dockerfiles/x86_64-w64-mingw32.dockerfile @@ -1,7 +1,7 @@ ARG TARGET=x86_64-w64-mingw32 # ----------- -FROM ubuntu:latest as builder +FROM --platform=linux/amd64 ubuntu:latest as builder ARG TARGET LABEL org.defichain.name="defichain-builder" LABEL org.defichain.arch=${TARGET} diff --git a/doc/build-quick.md b/doc/build-quick.md index 82c702b0ecd..feeddce2c7e 100644 --- a/doc/build-quick.md +++ b/doc/build-quick.md @@ -61,7 +61,7 @@ an environment with correct arch and pre-requisites configured. - aarch64-linux-gnu - arm-linux-gnueabihf -- arm-apple-darwin +- aarch64-apple-darwin ## Defined `env` variables diff --git a/make.sh b/make.sh index 8bb9d589a38..645a2d3cf70 100755 --- a/make.sh +++ b/make.sh @@ -584,7 +584,13 @@ clean() { _get_default_target() { local default_target="" if [[ "${OSTYPE}" == "darwin"* ]]; then - default_target="x86_64-apple-darwin" + local macos_arch="" + macos_arch=$(uname -m || true) + if [[ "$macos_arch" == "x86_64" ]]; then + default_target="x86_64-apple-darwin" + else + default_target="aarch64-apple-darwin" + fi elif [[ "${OSTYPE}" == "msys" ]]; then default_target="x86_64-w64-mingw32" else