Skip to content

Commit

Permalink
[Docker] Adapt chip-build to build on ARM64
Browse files Browse the repository at this point in the history
Use TARGETPLATFORM to choose the right platform.
Installing the correct version of packages depending on platform.
Support of asan had to be dropped for ARM64 as it doesn't build
properly.

Signed-off-by: Vincent Coubard <vincent.coubard@arm.com>
  • Loading branch information
pan- authored and ATmobica committed May 15, 2023
1 parent a33249d commit 1c9c150
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 21 deletions.
4 changes: 3 additions & 1 deletion integrations/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ VERSION=${DOCKER_BUILD_VERSION:-$(sed 's/ .*//' version)}

if [[ $OSTYPE == 'darwin'* ]]; then
DOCKER_VOLUME_PATH=~/Library/Containers/com.docker.docker/Data/vms/0/
TARGET_PLATFORM_TYPE="linux/arm64"
else
DOCKER_VOLUME_PATH=/var/lib/docker/
TARGET_PLATFORM_TYPE="linux/amd64"
fi

[[ ${*/--help//} != "${*}" ]] && {
Expand Down Expand Up @@ -82,7 +84,7 @@ if [[ ${*/--no-cache//} != "${*}" ]]; then
fi

[[ ${*/--skip-build//} != "${*}" ]] || {
docker build "${BUILD_ARGS[@]}" --build-arg VERSION="$VERSION" -t "$ORG/$IMAGE:$VERSION" .
docker build "${BUILD_ARGS[@]}" --build-arg TARGETPLATFORM="$TARGET_PLATFORM_TYPE" --build-arg VERSION="$VERSION" -t "$ORG/$IMAGE:$VERSION" .
docker image prune --force
}

Expand Down
91 changes: 72 additions & 19 deletions integrations/docker/images/chip-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ FROM ubuntu:focal

VOLUME "/var/source"

ARG TARGETPLATFORM

# Ensure TARGETPLATFORM is set
RUN case ${TARGETPLATFORM} in \
"linux/amd64") \
echo "Building for linux/amd64" \
;; \
"linux/arm64") \
echo "Building for linux/arm64" \
;; \
*) \
if [ -z "$TARGETPLATFORM" ] ;\
then \
echo "TARGETPLATFORM not defined! Please run from buildkit (buildx)." \
&& return 1 ;\
else \
echo "Unsupported platform ${TARGETPLATFORM}." \
&& return 1 ;\
fi \
;; \
esac


# base build and check tools and libraries layer
RUN set -x \
&& apt-get update \
Expand Down Expand Up @@ -75,11 +98,21 @@ RUN set -x \
&& : # last line

# Cmake v3.23.1
RUN set -x \
ENV CMAKE_PLATFORM_VERSION=
RUN case ${TARGETPLATFORM} in \
"linux/amd64") CMAKE_PLATFORM_VERSION="x86_64";; \
"linux/arm64") CMAKE_PLATFORM_VERSION="aarch64";; \
*) \
test -n "$TARGETPLATFORM" \
echo "Unsupported platform ${TARGETPLATFORM}" \
&& return 1 ;\
;; \
esac \
&& set -x \
&& (cd /tmp \
&& wget --progress=dot:giga https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-Linux-x86_64.sh \
&& sh cmake-3.23.1-Linux-x86_64.sh --exclude-subdir --prefix=/usr/local \
&& rm -rf cmake-3.23.1-Linux-x86_64.sh) \
&& wget --progress=dot:giga https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-Linux-$CMAKE_PLATFORM_VERSION.sh \
&& sh cmake-3.23.1-Linux-$CMAKE_PLATFORM_VERSION.sh --exclude-subdir --prefix=/usr/local \
&& rm -rf cmake-3.23.1-Linux-$CMAKE_PLATFORM_VERSION.sh) \
&& exec bash \
&& : # last line

Expand Down Expand Up @@ -165,16 +198,26 @@ RUN set -x \
# report false positives. This case is most prominent with glib-2.0, which has
# a lot of threads-related APIs.
ENV LD_LIBRARY_PATH_TSAN=/usr/lib/x86_64-linux-gnu-tsan
RUN set -x \
&& mkdir -p $LD_LIBRARY_PATH_TSAN \
&& export CCACHE_DISABLE=1 PYTHONDONTWRITEBYTECODE=1 \
&& GLIB_VERSION=$(pkg-config --modversion glib-2.0) \
&& git clone --depth=1 --branch=$GLIB_VERSION https://github.com/GNOME/glib.git \
&& CFLAGS="-O2 -g -fsanitize=thread" meson glib/build glib \
&& DESTDIR=../build-image ninja -C glib/build install \
&& mv glib/build-image/usr/local/lib/x86_64-linux-gnu/lib* $LD_LIBRARY_PATH_TSAN \
&& rm -rf glib \
&& : # last line
RUN case ${TARGETPLATFORM} in \
"linux/amd64") \
set -x \
&& mkdir -p $LD_LIBRARY_PATH_TSAN \
&& export CCACHE_DISABLE=1 PYTHONDONTWRITEBYTECODE=1 \
&& GLIB_VERSION=$(pkg-config --modversion glib-2.0) \
&& git clone --depth=1 --branch=$GLIB_VERSION https://github.com/GNOME/glib.git \
&& CFLAGS="-O2 -g -fsanitize=thread" meson glib/build glib \
&& DESTDIR=../build-image ninja -C glib/build install \
&& mv glib/build-image/usr/local/lib/x86_64-linux-gnu/lib* $LD_LIBRARY_PATH_TSAN \
&& rm -rf glib \
;; \
"linux/arm64") \
echo "ARM64 unsupported with TSAN" \
;; \
*) \
echo "Unsupported platform ${TARGETPLATFORM}" \
&& return 1 ;\
;; \
esac

# NodeJS: install a newer version than what apt-get would read
# This installs the latest LTS version of nodejs
Expand All @@ -184,13 +227,23 @@ RUN set -x \
#
# This is not a CHIP dependency directly, but used by CI
ENV CHIP_NODE_VERSION=v16.13.2
RUN set -x \
ENV NODE_PLATFORM_VERSION=
RUN case ${TARGETPLATFORM} in \
"linux/amd64") NODE_PLATFORM_VERSION=x64;; \
"linux/arm64") NODE_PLATFORM_VERSION=arm64;; \
*) \
test -n "$TARGETPLATFORM" \
echo "Unsupported platform ${TARGETPLATFORM}" \
&& return 1 ;\
;; \
esac \
&& set -x \
&& mkdir node_js \
&& cd node_js \
&& wget https://nodejs.org/dist/$CHIP_NODE_VERSION/node-$CHIP_NODE_VERSION-linux-x64.tar.xz \
&& tar xfvJ node-$CHIP_NODE_VERSION-linux-x64.tar.xz \
&& mv node-$CHIP_NODE_VERSION-linux-x64 /opt/ \
&& ln -s /opt/node-$CHIP_NODE_VERSION-linux-x64 /opt/node \
&& wget https://nodejs.org/dist/$CHIP_NODE_VERSION/node-$CHIP_NODE_VERSION-linux-$NODE_PLATFORM_VERSION.tar.xz \
&& tar xfvJ node-$CHIP_NODE_VERSION-linux-$NODE_PLATFORM_VERSION.tar.xz \
&& mv node-$CHIP_NODE_VERSION-linux-$NODE_PLATFORM_VERSION /opt/ \
&& ln -s /opt/node-$CHIP_NODE_VERSION-linux-$NODE_PLATFORM_VERSION /opt/node \
&& ln -s /opt/node/bin/* /usr/bin \
&& cd .. \
&& rm -rf node_js \
Expand Down
2 changes: 1 addition & 1 deletion integrations/docker/images/chip-build/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.9 Version bump reason: Fix path for sysroot for crosscompile image
0.7.10 Version bump reason: Enable ARM64 build

0 comments on commit 1c9c150

Please sign in to comment.