Skip to content

Commit

Permalink
attempt to crosscompile heaptrack (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
partouf authored Sep 26, 2024
1 parent e9b2c32 commit 21ef064
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 14 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Build
on:
push:
workflow_dispatch:
jobs:
build:
jobs:
build-x86_64:
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -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 }}
20 changes: 14 additions & 6 deletions Dockerfile.heaptrack
Original file line number Diff line number Diff line change
@@ -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
Expand Down
134 changes: 134 additions & 0 deletions heaptrack/build-cross.sh
Original file line number Diff line number Diff line change
@@ -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}"
23 changes: 17 additions & 6 deletions heaptrack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,33 @@ LAST_REVISION="${3:-}"

initialise "${REVISION}" "${OUTPUT}" "${LAST_REVISION}"

PREFIX=$(pwd)/prefix
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}
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

Expand All @@ -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}"

0 comments on commit 21ef064

Please sign in to comment.