1 #===----------------------------------------------------------------------===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 #===----------------------------------------------------------------------===##
10 # This Dockerfile extends ldionne/libcxx-builder with Android support, including
11 # Android Clang and sysroot, Android platform-tools, and the Docker client.
13 # $ docker build -t libcxx-builder-android libcxx/utils/ci/vendor/android
16 FROM ldionne/libcxx-builder
18 # Switch back to the root user to install things into /opt and /usr.
22 # Install the Android platform tools (e.g. adb) into /opt/android/sdk.
23 RUN apt-get update && apt-get install -y unzip
24 RUN mkdir -p /opt/android/sdk && cd /opt/android/sdk && \
25 curl -LO https://dl.google.com/android/repository/platform-tools-latest-linux.zip && \
26 unzip platform-tools-latest-linux.zip && \
27 rm platform-tools-latest-linux.zip
29 # Install the current Android compiler. Specify the prebuilts commit to retrieve
30 # this compiler version even after it's removed from HEAD.
31 ENV ANDROID_CLANG_VERSION=r498229b
32 ENV ANDROID_CLANG_PREBUILTS_COMMIT=5186d132c99aa75dc25207c392e3ea5b93d0107e
33 RUN git clone --filter=blob:none --sparse \
34 https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86 \
35 /opt/android/clang && \
36 git -C /opt/android/clang checkout ${ANDROID_CLANG_PREBUILTS_COMMIT} && \
37 git -C /opt/android/clang sparse-checkout add clang-${ANDROID_CLANG_VERSION} && \
38 rm -fr /opt/android/clang/.git && \
39 ln -sf /opt/android/clang/clang-${ANDROID_CLANG_VERSION} /opt/android/clang/clang-current && \
40 # The "git sparse-checkout" and "ln" commands succeed even if nothing was
41 # checked out, so use this "ls" command to fix that.
42 ls /opt/android/clang/clang-current/bin/clang
44 # Install an Android sysroot. New AOSP sysroots are available at
45 # https://ci.android.com/builds/branches/aosp-main/grid, the "ndk" target. The
46 # NDK also makes its sysroot prebuilt available at
47 # https://android.googlesource.com/platform/prebuilts/ndk/+/refs/heads/dev/platform/sysroot.
48 ENV ANDROID_SYSROOT_BID=10957860
49 RUN cd /opt/android && \
50 curl -L -o ndk_platform.tar.bz2 \
51 https://androidbuildinternal.googleapis.com/android/internal/build/v3/builds/${ANDROID_SYSROOT_BID}/ndk/attempts/latest/artifacts/ndk_platform.tar.bz2/url && \
52 tar xf ndk_platform.tar.bz2 && \
53 rm ndk_platform.tar.bz2
55 # Install Docker. Mark the binary setuid so it can be run without prefixing it
56 # with sudo. Adding the container user to the docker group doesn't work because
57 # /var/run/docker.sock is owned by the host's docker GID, not the container's
59 RUN apt-get update && apt-get install -y gpg && \
60 install -m 0755 -d /etc/apt/keyrings && \
61 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
62 chmod a+r /etc/apt/keyrings/docker.gpg && \
63 echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
64 "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
65 tee /etc/apt/sources.list.d/docker.list > /dev/null && \
66 apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && \
67 chmod u+s /usr/bin/docker
69 COPY ./container-setup.sh /opt/android/container-setup.sh
72 WORKDIR /home/libcxx-builder
74 # Add Android platform-tools to the PATH.
75 ENV PATH="/opt/android/sdk/platform-tools:${PATH}"
77 # Reset the buildkite-agent.cfg file. The tags are provided by an environment
79 RUN cp /home/libcxx-builder/.buildkite-agent/buildkite-agent.dist.cfg \
80 /home/libcxx-builder/.buildkite-agent/buildkite-agent.cfg
82 # Modify the Buildkite agent cmdline to do Android setup stuff first.
83 CMD /opt/android/container-setup.sh && buildkite-agent start