From 21ef064e0bf3faf83a9150084c4e669f445285a4 Mon Sep 17 00:00:00 2001 From: Patrick Quist Date: Thu, 26 Sep 2024 20:24:57 +0200 Subject: [PATCH] attempt to crosscompile heaptrack (#92) --- .github/workflows/build.yml | 29 +++++++- Dockerfile.heaptrack | 20 ++++-- heaptrack/build-cross.sh | 134 ++++++++++++++++++++++++++++++++++++ heaptrack/build.sh | 23 +++++-- 4 files changed, 192 insertions(+), 14 deletions(-) create mode 100755 heaptrack/build-cross.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2f740b0..98bdce7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,8 +2,8 @@ name: Build on: push: workflow_dispatch: -jobs: - build: +jobs: + build-x86_64: runs-on: ubuntu-latest strategy: matrix: @@ -41,3 +41,28 @@ jobs: file: Dockerfile.${{ matrix.image }} - name: Docker Hub Image Digest run: echo ${{ steps.hub_build.outputs.digest }} + build-arm64: + runs-on: [self-hosted, ce, linux, arm64] + strategy: + matrix: + image: + - heaptrack + steps: + - name: Docker Setup Buildx + uses: docker/setup-buildx-action@v2 + - name: Docker Login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Build and push to Docker Hub + id: hub_build + uses: docker/build-push-action@v5 + with: + push: ${{ github.ref == 'refs/heads/main' && 'true' || 'false' }} + tags: compilerexplorer/${{ matrix.image }}-builder:latest + cache-from: type=registry,ref=compilerexplorer/${{ matrix.image }}-builder:latest + cache-to: type=inline,mode=max + file: Dockerfile.${{ matrix.image }} + - name: Docker Hub Image Digest + run: echo ${{ steps.hub_build.outputs.digest }} diff --git a/Dockerfile.heaptrack b/Dockerfile.heaptrack index d89c73f..971fc49 100644 --- a/Dockerfile.heaptrack +++ b/Dockerfile.heaptrack @@ -1,23 +1,31 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 ARG DEBIAN_FRONTEND=noninteractive + RUN apt update -y -q && apt upgrade -y -q && apt update -y -q && \ apt install -y -q \ build-essential \ + binutils-multiarch \ curl \ git \ + autopoint \ + pkg-config \ libunwind-dev \ elfutils \ libdw-dev \ libboost-all-dev \ - libzstd-dev - -RUN apt install -y -q \ + libzstd-dev \ cmake \ + gawk \ unzip -RUN curl -L -o ninja-linux.zip https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip && \ - unzip ninja-linux.zip && \ +RUN [ "$(uname -m)" = "arm64" ]; \ + curl -L -o ninja-linux.zip https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux-aarch64.zip + +RUN [ "$(uname -m)" = "x86_64" ]; \ + curl -L -o ninja-linux.zip https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip + +RUN unzip ninja-linux.zip && \ mv ninja /usr/bin/ninja RUN mkdir -p /root diff --git a/heaptrack/build-cross.sh b/heaptrack/build-cross.sh new file mode 100755 index 0000000..4d7ee25 --- /dev/null +++ b/heaptrack/build-cross.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +set -ex +source common.sh + +VERSION=$1 + +URL=https://github.com/KDE/heaptrack.git + +FULLNAME=heaptrack-${VERSION}.tar.xz +OUTPUT=$2/${FULLNAME} + +REVISION="heaptrack-${VERSION}" +LAST_REVISION="${3:-}" + +initialise "${REVISION}" "${OUTPUT}" "${LAST_REVISION}" + +ROOT=$(pwd) +DIR=$(pwd)/build +INFRA=$(pwd)/infra + +mkdir "${DIR}" +cd "${DIR}" + +if [[ $VERSION == 'trunk' ]]; then + git clone --depth 1 ${URL} +else + git clone --depth 1 ${URL} -b "${VERSION}" +fi; + +cd "${ROOT}" +git clone https://github.com/compiler-explorer/infra +cd "${INFRA}" +make ce +mkdir -p /opt/compiler-explorer/staging +bin/ce_install install 'gcc/arm64 13.2.0' + +BUILDDIR=${DIR}/heaptrack/build +mkdir "${BUILDDIR}" +cd "${BUILDDIR}" + + +PREFIX=$(pwd)/amd64 + +# cmake -DCMAKE_BUILD_TYPE=Release .. +# cmake --build . --target heaptrack_unwind heaptrack_preload heaptrack_print heaptrack_interpret heaptrack_inject + +# mkdir -p ${PREFIX}/bin ${PREFIX}/lib ${PREFIX}/libexec +# cp ${BUILDDIR}/bin/heaptrack ${PREFIX}/bin +# cp ${BUILDDIR}/bin/heaptrack_print ${PREFIX}/bin +# cp ${BUILDDIR}/lib/heaptrack/libheaptrack_preload.so ${PREFIX}/lib +# cp ${BUILDDIR}/lib/heaptrack/libheaptrack_inject.so ${PREFIX}/lib +# cp ${BUILDDIR}/lib/heaptrack/libexec/heaptrack_interpret ${PREFIX}/libexec +# cp /lib/x86_64-linux-gnu/libboost_iostreams.* ${PREFIX}/lib +# cp /lib/x86_64-linux-gnu/libboost_program_options.* ${PREFIX}/lib +# cp /lib/x86_64-linux-gnu/libboost_filesystem.* ${PREFIX}/lib + + +# rm -Rf * + +curl -sL -o boost.tgz https://conan.compiler-explorer.com/downloadpkg/boost_bin/1.85.0/arm64g1320 +curl -sL -o zlib.tgz https://conan.compiler-explorer.com/downloadpkg/zlib/1.3.1/arm64g1320 +curl -sL -o libunwind.zip https://github.com/libunwind/libunwind/archive/refs/tags/v1.8.1.zip +curl -sL -o elfutils.tar.bz2 https://sourceware.org/elfutils/ftp/0.191/elfutils-0.191.tar.bz2 + +mkdir -p /usr/local/boost +tar -xzf boost.tgz -C /usr/local/boost + +mkdir -p /usr/local/zlib +tar -xzf zlib.tgz -C /usr/local/zlib + +mkdir -p /usr/local/elfutils/src +tar -xjf elfutils.tar.bz2 -C /usr/local/elfutils/src + +mkdir -p /usr/local/libunwind/src +cd /usr/local/libunwind/src +unzip -q "${BUILDDIR}/libunwind.zip" + +PREFIX=$(pwd)/aarch64 +export CXX=/opt/compiler-explorer/arm64/gcc-13.2.0/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-g++ +export CC=/opt/compiler-explorer/arm64/gcc-13.2.0/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc + +export TARGET=aarch64-linux-gnu + +cd /usr/local/libunwind/src/libunwind* +autoreconf -i +./configure --prefix=/usr/local/libunwind --build=x86_64-linux-gnu --host=aarch64-linux-gnu +make +make install + +cd /usr/local/elfutils/src/elfutils* + +export LDFLAGS="-Wl,-rpath=/usr/local/zlib/lib" +./configure "CC=$CC -L/usr/local/zlib/lib -I/usr/local/zlib/include -Wl,-rpath=/usr/local/zlib/lib -lz" "CXX=$CXX -L/usr/local/zlib/lib -I/usr/local/zlib/include -Wl,-rpath=/usr/local/zlib/lib -lz" --with-zlib --disable-debuginfod --disable-libdebuginfod --prefix=/usr/local/elfutils --build=x86_64-linux-gnu --host=aarch64-linux-gnu || /bin/true +make --trace +make install + +ls -l /usr/local/elfutils + +cd "${BUILDDIR}" + +TOPDIR=/usr/local/boost/lib/cmake +DIRS=$(ls -1p "$TOPDIR") +CMAKEDIRS=$(echo "${DIRS}" | grep / | xargs echo | sed 's/\/ /:/g' | sed 's/\///g' | sed 's/:/\:\/usr\/local\/boost\/lib\/cmake\//g' | sed 's/^/\/usr\/local\/boost\/lib\/cmake\//g') + +export CMAKE_PREFIX_PATH=$CMAKEDIRS + +cmake -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DLIBDW_LIBRARIES=/usr/local/libunwind/lib/libdw.a \ + -DLIBDW_INCLUDE_DIRS=/usr/local/libunwind/include \ + -DLIBUNWIND_LIBRARY=/usr/local/libunwind/lib/libunwind-aarch64.a \ + -DLIBUNWIND_INCLUDE_DIR=/usr/local/libunwind/include \ + -DLIBUNWIND_HAS_UNW_BACKTRACE=ON \ + -DZLIB_LIBRARY=/usr/local/zlib/lib/libz.a \ + -DCMAKE_CROSSCOMPILING=ON \ + -DCMAKE_SYSTEM_PROCESSOR=aarch64 \ + -DCMAKE_CXX_COMPILER_TARGET=aarch64-linux-gnu \ + -DCMAKE_C_COMPILER_TARGET=aarch64-linux-gnu \ + -DCMAKE_ASM_COMPILER_TARGET=aarch64-linux-gnu \ + -DCMAKE_BUILD_TYPE=Release \ + .. +cmake --build . --target heaptrack_unwind heaptrack_preload heaptrack_print heaptrack_interpret heaptrack_inject + +mkdir -p "${PREFIX}/bin" "${PREFIX}/lib" "${PREFIX}/libexec" +cp "${BUILDDIR}/bin/heaptrack" "${PREFIX}/bin" +cp "${BUILDDIR}/bin/heaptrack_print" "${PREFIX}/bin" +cp "${BUILDDIR}/lib/heaptrack/libheaptrack_preload.so" "${PREFIX}/lib" +cp "${BUILDDIR}/lib/heaptrack/libheaptrack_inject.so" "${PREFIX}/lib" +cp "${BUILDDIR}/lib/heaptrack/libexec/heaptrack_interpret" "${PREFIX}/libexec" +cp /usr/local/boost/lib/libboost_iostreams.* "${PREFIX}/lib" +cp /usr/local/boost/lib/libboost_program_options.* "${PREFIX}/lib" +cp /usr/local/boost/lib/libboost_filesystem.* "${PREFIX}/lib" + +complete "${PREFIX}" "heaptrack-${VERSION}" "${OUTPUT}" diff --git a/heaptrack/build.sh b/heaptrack/build.sh index 31a178e..d3a59f2 100755 --- a/heaptrack/build.sh +++ b/heaptrack/build.sh @@ -15,8 +15,9 @@ LAST_REVISION="${3:-}" initialise "${REVISION}" "${OUTPUT}" "${LAST_REVISION}" -PREFIX=$(pwd)/prefix +ROOT=$(pwd) DIR=$(pwd)/build +INFRA=$(pwd)/infra mkdir "${DIR}" cd "${DIR}" @@ -24,13 +25,23 @@ cd "${DIR}" if [[ $VERSION == 'trunk' ]]; then git clone --depth 1 ${URL} else - git clone --depth 1 ${URL} -b ${VERSION} + git clone --depth 1 ${URL} -b "${VERSION}" fi; +cd "${ROOT}" +git clone https://github.com/compiler-explorer/infra +cd "${INFRA}" +make ce +mkdir -p /opt/compiler-explorer/staging + BUILDDIR=${DIR}/heaptrack/build mkdir "${BUILDDIR}" cd "${BUILDDIR}" + +PREFIX=$(pwd)/heaptrack +ARCH=$(uname -m) + cmake -DCMAKE_BUILD_TYPE=Release .. cmake --build . --target heaptrack_unwind heaptrack_preload heaptrack_print heaptrack_interpret heaptrack_inject @@ -40,8 +51,8 @@ cp ${BUILDDIR}/bin/heaptrack_print ${PREFIX}/bin cp ${BUILDDIR}/lib/heaptrack/libheaptrack_preload.so ${PREFIX}/lib cp ${BUILDDIR}/lib/heaptrack/libheaptrack_inject.so ${PREFIX}/lib cp ${BUILDDIR}/lib/heaptrack/libexec/heaptrack_interpret ${PREFIX}/libexec -cp /lib/x86_64-linux-gnu/libboost_iostreams.* ${PREFIX}/lib -cp /lib/x86_64-linux-gnu/libboost_program_options.* ${PREFIX}/lib -cp /lib/x86_64-linux-gnu/libboost_filesystem.* ${PREFIX}/lib +cp /lib/${ARCH}-linux-gnu/libboost_iostreams.* ${PREFIX}/lib +cp /lib/${ARCH}-linux-gnu/libboost_program_options.* ${PREFIX}/lib +cp /lib/${ARCH}-linux-gnu/libboost_filesystem.* ${PREFIX}/lib -complete "${PREFIX}" "heaptrack-${VERSION}" "${OUTPUT}" +complete "${PREFIX}" "heaptrack-${ARCH}-${VERSION}" "${OUTPUT}"