Mesa (master): ci/android: Switch to using the Android NDK.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Oct 14 17:12:31 UTC 2020


Module: Mesa
Branch: master
Commit: 0767af3ffece3b951b567a01a2c0da7218a4c70d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0767af3ffece3b951b567a01a2c0da7218a4c70d

Author: Eric Anholt <eric at anholt.net>
Date:   Wed Sep  9 16:37:54 2020 -0700

ci/android: Switch to using the Android NDK.

To support Android drivers, we're going to want to be tracking that Mesa's
build succeeds on a real android toolchain.  This still uses the android
stubs since these libs aren't in the NDK.

Note that I had to drop the Intel and AMD drivers currently: we don't have
LLVM cross-compiled for Android in this container, and I'm honestly hoping
ACO saves us from that.  Intel has dependencies on libexpat, which AOSP
really doesn't want to bring in, and it looks to me like those dependencies
could be optional.

Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6700>

---

 .gitlab-ci.yml                          | 31 ++++++++++++++---
 .gitlab-ci/container/android_build.sh   | 60 +++++++++++++++++++++++++++++++++
 .gitlab-ci/create-android-cross-file.sh | 33 ++++++++++++++++++
 .gitlab-ci/create-android-ndk-pc.sh     | 38 +++++++++++++++++++++
 4 files changed, 158 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 23f03e4897f..d123d0e6a8b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -309,6 +309,20 @@ s390x_build:
   needs:
     - s390x_build
 
+# Android NDK cross-build image
+android_build:
+  extends:
+    - .use-x86_build-base
+  variables:
+    FDO_DISTRIBUTION_TAG: &android_build "2020-10-05-shrink"
+
+.use-android_build:
+  variables:
+    TAG: *android_build
+  image: "$CI_REGISTRY_IMAGE/debian/android_build:$TAG"
+  needs:
+    - android_build
+
 # Debian 10 based x86 test image base
 x86_test-base:
   extends: x86_build-base
@@ -662,7 +676,9 @@ meson-classic:
       -D werror=true
 
 meson-android:
-  extends: .meson-build
+  extends:
+    - .meson-cross
+    - .use-android_build
   variables:
     UNWIND: "disabled"
     DRI_LOADERS: >
@@ -670,11 +686,9 @@ meson-android:
       -D gbm=disabled
       -D egl=enabled
       -D platforms=android
-    GALLIUM_DRIVERS: freedreno
-    VULKAN_DRIVERS: freedreno,intel,amd
     EXTRA_OPTION: >
       -D android-stub=true
-      -D werror=true
+      -D llvm=disabled
     GALLIUM_ST: >
       -D dri3=disabled
       -D gallium-vdpau=disabled
@@ -684,6 +698,15 @@ meson-android:
       -D gallium-xa=disabled
       -D gallium-nine=false
       -D gallium-opencl=disabled
+    LLVM_VERSION: ""
+  script:
+    # arm64 build: Can't build v3d/vc4 because they require expat for v3d_decode.
+    - PKG_CONFIG_PATH=/usr/local/lib/aarch64-linux-android/pkgconfig/:/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/pkgconfig/ CROSS=aarch64-linux-android GALLIUM_DRIVERS=etnaviv,freedreno,lima,panfrost VULKAN_DRIVERS=freedreno .gitlab-ci/meson-build.sh
+    # x86_64 build:
+    # Can't do Intel because gen_decoder.c currently requires libexpat, which
+    # is not a dependency that AOSP wants to accept.  Can't do Radeon because
+    # it requires LLVM, which we don't have an Android build of.
+    # - PKG_CONFIG_PATH=/usr/local/lib/x86_64-linux-android/pkgconfig/ CROSS=x86_64-linux-android GALLIUM_DRIVERS=iris VULKAN_DRIVERS=intel .gitlab-ci/meson-build.sh
 
 .meson-cross:
   extends:
diff --git a/.gitlab-ci/container/android_build.sh b/.gitlab-ci/container/android_build.sh
new file mode 100644
index 00000000000..ffc42fff149
--- /dev/null
+++ b/.gitlab-ci/container/android_build.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+set -ex
+
+EPHEMERAL="\
+         rdfind \
+         unzip \
+         "
+
+apt-get install -y --no-remove $EPHEMERAL
+
+# Fetch the NDK and extract just the toolchain we want.
+ndk=android-ndk-r21d
+wget -O $ndk.zip https://dl.google.com/android/repository/$ndk-linux-x86_64.zip
+unzip -d / $ndk.zip "$ndk/toolchains/llvm/*"
+rm $ndk.zip
+# Since it was packed as a zip file, symlinks/hardlinks got turned into
+# duplicate files.  Turn them into hardlinks to save on container space.
+rdfind -makehardlinks true -makeresultsfile false /android-ndk-r21d/
+# Drop some large tools we won't use in this build.
+find /android-ndk-r21d/ -type f | egrep -i "clang-check|clang-tidy|lldb" | xargs rm -f
+
+sh .gitlab-ci/create-android-ndk-pc.sh /$ndk zlib.pc "" "-lz" "1.2.3"
+
+sh .gitlab-ci/create-android-cross-file.sh /$ndk x86_64-linux-android x86_64 x86_64
+sh .gitlab-ci/create-android-cross-file.sh /$ndk i686-linux-android x86 x86
+sh .gitlab-ci/create-android-cross-file.sh /$ndk aarch64-linux-android arm armv8
+sh .gitlab-ci/create-android-cross-file.sh /$ndk arm-linux-androideabi arm armv7hl armv7a-linux-androideabi
+
+# Not using build-libdrm.sh because we don't want its cleanup after building
+# each arch.  Fetch and extract now.
+export LIBDRM_VERSION=libdrm-2.4.102
+wget https://dri.freedesktop.org/libdrm/$LIBDRM_VERSION.tar.xz
+tar -xf $LIBDRM_VERSION.tar.xz && rm $LIBDRM_VERSION.tar.xz
+
+for arch in \
+        x86_64-linux-android \
+        i686-linux-android \
+        aarch64-linux-android \
+        arm-linux-androideabi ; do
+
+    cd $LIBDRM_VERSION
+    rm -rf build-$arch
+    meson build-$arch \
+          --cross-file=/cross_file-$arch.txt \
+          --libdir=lib/$arch \
+          -Dlibkms=false \
+          -Dnouveau=false \
+          -Dvc4=false \
+          -Detnaviv=false \
+          -Dfreedreno=false \
+          -Dintel=false \
+          -Dcairo-tests=false
+    ninja -C build-$arch install
+    cd ..
+done
+
+rm -rf $LIBDRM_VERSION
+
+apt-get purge -y $EPHEMERAL
diff --git a/.gitlab-ci/create-android-cross-file.sh b/.gitlab-ci/create-android-cross-file.sh
new file mode 100644
index 00000000000..4590ce172a9
--- /dev/null
+++ b/.gitlab-ci/create-android-cross-file.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+ndk=$1
+arch=$2
+cpu_family=$3
+cpu=$4
+cross_file="/cross_file-$arch.txt"
+
+# armv7 has the toolchain split between two names.
+arch2=${5:-$2}
+
+# Note that we disable C++ exceptions, because Mesa doesn't use exceptions,
+# and allowing it in code generation means we get unwind symbols that break
+# the libEGL and driver symbol tests.
+
+cat >$cross_file <<EOF
+[binaries]
+ar = '$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/$arch-ar'
+c = ['ccache', '$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/${arch2}29-clang', '-fuse-ld=lld', '-fno-exceptions', '-fno-unwind-tables', '-fno-asynchronous-unwind-tables']
+cpp = ['ccache', '$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/${arch2}29-clang++', '-fuse-ld=lld', '-fno-exceptions', '-fno-unwind-tables', '-fno-asynchronous-unwind-tables', '-static-libstdc++']
+strip = '$ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/$arch-strip'
+pkgconfig = ['/usr/bin/pkg-config']
+
+[host_machine]
+system = 'linux'
+cpu_family = '$cpu_family'
+cpu = '$cpu'
+endian = 'little'
+
+[properties]
+needs_exe_wrapper = true
+
+EOF
diff --git a/.gitlab-ci/create-android-ndk-pc.sh b/.gitlab-ci/create-android-ndk-pc.sh
new file mode 100644
index 00000000000..1380cc240be
--- /dev/null
+++ b/.gitlab-ci/create-android-ndk-pc.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+# Makes a .pc file in the Android NDK for meson to find its libraries.
+
+set -ex
+
+ndk="$1"
+pc="$2"
+cflags="$3"
+libs="$4"
+version="$5"
+
+sysroot=$ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot
+
+for arch in \
+        x86_64-linux-android \
+        i686-linux-android \
+        aarch64-linux-android \
+        arm-linux-androideabi; do
+    pcdir=$sysroot/usr/lib/$arch/pkgconfig
+    mkdir -p $pcdir
+
+    cat >$pcdir/$pc <<EOF
+prefix=$sysroot
+exec_prefix=$sysroot
+libdir=$sysroot/usr/lib/$arch/29
+sharedlibdir=$sysroot/usr/lib/$arch
+includedir=$sysroot/usr/include
+
+Name: zlib
+Description: zlib compression library
+Version: $version
+
+Requires:
+Libs: -L$sysroot/usr/lib/$arch/29 $libs
+Cflags: -I$sysroot/usr/include $cflags
+EOF
+done



More information about the mesa-commit mailing list