Skip to content

Commit

Permalink
Add arm64 cross-build images targeting Ubuntu 16.04 (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbomer committed Jan 17, 2023
1 parent efff84f commit 4cc66cd
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ A precondition for building an image is to ensure that the base image specified

In certain cases, it is necessary to run custom logic before and after the Dockerfiles are built. For example, to build the Dockerfiles that are used for cross-gen builds, the rootfs that gets copied into the Docker image needs to be built on the host OS. To support these scenarios a `pre-build` or `post-build` bash or PowerShell script can be placed in a `hooks` folder next to the Dockerfile. The scripts will get invoked by the build process.

Note that multi-stage docker builds can be used to accomplish the same without build hooks, and are easier to iterate on locally because this takes advantage of docker image caching to avoid re-running steps when nothing has changed (whereas pre-build hooks run every time the dockerfile is built).

**Warning:** It is generally recommended to avoid the need to use hooks whenever possible.

### Image-Builder
Expand Down
56 changes: 56 additions & 0 deletions src/ubuntu/20.04/cross/arm64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-20.04-crossdeps-local AS binutils

# Install binutils-aarch64-linux-gnu
RUN apt-get update \
&& apt-get install -y \
binutils-aarch64-linux-gnu \
&& rm -rf /var/lib/apt/lists/*


FROM binutils AS rootfsbuild
ARG ROOTFS_DIR=/crossrootfs

# Build rootfs
RUN git config --global user.email builder@dotnet-buildtools-prereqs-docker && \
git clone --depth 1 --single-branch https://github.com/dotnet/arcade /scripts
RUN /scripts/eng/common/cross/build-rootfs.sh arm64 xenial lldb3.9 --skipunmount
RUN bash -c "rm -rf $ROOTFS_DIR/*/{var/cache/apt/archives/*,var/lib/apt/lists/*,usr/share/doc,usr/share/man}"

# Build llvm-9 compiler-rt profile library for arm64, for PGO support
RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/compiler-rt-9.0.1.src.tar.xz
RUN tar -xf compiler-rt-9.0.1.src.tar.xz && \
rm compiler-rt-9.0.1.src.tar.xz
RUN mkdir compiler-rt-build && \
cd compiler-rt-build && \
\
TARGET_TRIPLE=aarch64-linux-gnu \
BUILD_FLAGS="-v --sysroot=$ROOTFS_DIR" && \
\
cmake ../compiler-rt-9.0.1.src \
-DCOMPILER_RT_BUILD_PROFILE=ON \
-DCOMPILER_RT_BUILD_BUILTINS=OFF \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
\
-DCMAKE_C_COMPILER=/usr/bin/clang-9 \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-9 \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
-DCMAKE_C_COMPILER_TARGET="${TARGET_TRIPLE}" \
-DCMAKE_CXX_COMPILER_TARGET="${TARGET_TRIPLE}" \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DLLVM_CONFIG_PATH=/usr/bin/llvm-config-9 \
\
-DCMAKE_C_FLAGS="${BUILD_FLAGS}" \
-DCMAKE_CXX_FLAGS="${BUILD_FLAGS}"

RUN cd compiler-rt-build && make

# Copy profile library to the rootfs
RUN mkdir -p $ROOTFS_DIR/usr/lib/llvm-9/lib/clang/9.0.1/lib/linux/ && \
cp /compiler-rt-build/lib/linux/libclang_rt.profile-aarch64.a $ROOTFS_DIR/usr/lib/llvm-9/lib/clang/9.0.1/lib/linux/


FROM binutils
ARG ROOTFS_DIR=/crossrootfs
COPY --from=rootfsbuild $ROOTFS_DIR $ROOTFS_DIR
13 changes: 13 additions & 0 deletions src/ubuntu/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,19 @@
}
]
},
{
"platforms": [
{
"dockerfile": "src/ubuntu/20.04/cross/arm64",
"os": "linux",
"osVersion": "focal",
"tags": {
"ubuntu-20.04-cross-arm64-$(System:TimeStamp)-$(System:DockerfileGitCommitSha)": {},
"ubuntu-20.04-cross-arm64$(FloatingTagSuffix)": {}
}
}
]
},
{
"platforms": [
{
Expand Down

0 comments on commit 4cc66cd

Please sign in to comment.