xref: /aosp_15_r20/external/libbpf/ci/managers/debian.sh (revision f7c14bbac8cf49633f2740db462ea43457973ec4)
1*f7c14bbaSAndroid Build Coastguard Worker#!/bin/bash
2*f7c14bbaSAndroid Build Coastguard Worker
3*f7c14bbaSAndroid Build Coastguard WorkerPHASES=(${@:-SETUP RUN RUN_ASAN CLEANUP})
4*f7c14bbaSAndroid Build Coastguard WorkerDEBIAN_RELEASE="${DEBIAN_RELEASE:-testing}"
5*f7c14bbaSAndroid Build Coastguard WorkerCONT_NAME="${CONT_NAME:-libbpf-debian-$DEBIAN_RELEASE}"
6*f7c14bbaSAndroid Build Coastguard WorkerENV_VARS="${ENV_VARS:-}"
7*f7c14bbaSAndroid Build Coastguard WorkerDOCKER_RUN="${DOCKER_RUN:-docker run}"
8*f7c14bbaSAndroid Build Coastguard WorkerREPO_ROOT="${REPO_ROOT:-$PWD}"
9*f7c14bbaSAndroid Build Coastguard WorkerADDITIONAL_DEPS=(pkgconf)
10*f7c14bbaSAndroid Build Coastguard WorkerEXTRA_CFLAGS=""
11*f7c14bbaSAndroid Build Coastguard WorkerEXTRA_LDFLAGS=""
12*f7c14bbaSAndroid Build Coastguard Worker
13*f7c14bbaSAndroid Build Coastguard Workerfunction info() {
14*f7c14bbaSAndroid Build Coastguard Worker    echo -e "\033[33;1m$1\033[0m"
15*f7c14bbaSAndroid Build Coastguard Worker}
16*f7c14bbaSAndroid Build Coastguard Worker
17*f7c14bbaSAndroid Build Coastguard Workerfunction error() {
18*f7c14bbaSAndroid Build Coastguard Worker    echo -e "\033[31;1m$1\033[0m"
19*f7c14bbaSAndroid Build Coastguard Worker}
20*f7c14bbaSAndroid Build Coastguard Worker
21*f7c14bbaSAndroid Build Coastguard Workerfunction docker_exec() {
22*f7c14bbaSAndroid Build Coastguard Worker    docker exec $ENV_VARS $CONT_NAME "$@"
23*f7c14bbaSAndroid Build Coastguard Worker}
24*f7c14bbaSAndroid Build Coastguard Worker
25*f7c14bbaSAndroid Build Coastguard Workerset -eu
26*f7c14bbaSAndroid Build Coastguard Worker
27*f7c14bbaSAndroid Build Coastguard Workersource "$(dirname $0)/travis_wait.bash"
28*f7c14bbaSAndroid Build Coastguard Worker
29*f7c14bbaSAndroid Build Coastguard Workerfor phase in "${PHASES[@]}"; do
30*f7c14bbaSAndroid Build Coastguard Worker    case $phase in
31*f7c14bbaSAndroid Build Coastguard Worker        SETUP)
32*f7c14bbaSAndroid Build Coastguard Worker            info "Setup phase"
33*f7c14bbaSAndroid Build Coastguard Worker            info "Using Debian $DEBIAN_RELEASE"
34*f7c14bbaSAndroid Build Coastguard Worker
35*f7c14bbaSAndroid Build Coastguard Worker            docker --version
36*f7c14bbaSAndroid Build Coastguard Worker
37*f7c14bbaSAndroid Build Coastguard Worker            docker pull debian:$DEBIAN_RELEASE
38*f7c14bbaSAndroid Build Coastguard Worker            info "Starting container $CONT_NAME"
39*f7c14bbaSAndroid Build Coastguard Worker            $DOCKER_RUN -v $REPO_ROOT:/build:rw \
40*f7c14bbaSAndroid Build Coastguard Worker                        -w /build --privileged=true --name $CONT_NAME \
41*f7c14bbaSAndroid Build Coastguard Worker                        -dit --net=host debian:$DEBIAN_RELEASE /bin/bash
42*f7c14bbaSAndroid Build Coastguard Worker            echo -e "::group::Build Env Setup"
43*f7c14bbaSAndroid Build Coastguard Worker            docker_exec bash -c "echo deb-src http://deb.debian.org/debian $DEBIAN_RELEASE main >>/etc/apt/sources.list"
44*f7c14bbaSAndroid Build Coastguard Worker            docker_exec apt-get -y update
45*f7c14bbaSAndroid Build Coastguard Worker            docker_exec apt-get -y install aptitude
46*f7c14bbaSAndroid Build Coastguard Worker            docker_exec aptitude -y install make libz-dev libelf-dev
47*f7c14bbaSAndroid Build Coastguard Worker            docker_exec aptitude -y install "${ADDITIONAL_DEPS[@]}"
48*f7c14bbaSAndroid Build Coastguard Worker            echo -e "::endgroup::"
49*f7c14bbaSAndroid Build Coastguard Worker            ;;
50*f7c14bbaSAndroid Build Coastguard Worker        RUN|RUN_CLANG|RUN_CLANG14|RUN_CLANG15|RUN_CLANG16|RUN_GCC10|RUN_GCC11|RUN_GCC12|RUN_ASAN|RUN_CLANG_ASAN|RUN_GCC10_ASAN)
51*f7c14bbaSAndroid Build Coastguard Worker            CC="cc"
52*f7c14bbaSAndroid Build Coastguard Worker            if [[ "$phase" =~ "RUN_CLANG(\d+)(_ASAN)?" ]]; then
53*f7c14bbaSAndroid Build Coastguard Worker                ENV_VARS="-e CC=clang-${BASH_REMATCH[1]} -e CXX=clang++-${BASH_REMATCH[1]}"
54*f7c14bbaSAndroid Build Coastguard Worker                CC="clang-${BASH_REMATCH[1]}"
55*f7c14bbaSAndroid Build Coastguard Worker            elif [[ "$phase" = *"CLANG"* ]]; then
56*f7c14bbaSAndroid Build Coastguard Worker                ENV_VARS="-e CC=clang -e CXX=clang++"
57*f7c14bbaSAndroid Build Coastguard Worker                CC="clang"
58*f7c14bbaSAndroid Build Coastguard Worker            elif [[ "$phase" =~ "RUN_GCC(\d+)(_ASAN)?" ]]; then
59*f7c14bbaSAndroid Build Coastguard Worker                ENV_VARS="-e CC=gcc-${BASH_REMATCH[1]} -e CXX=g++-${BASH_REMATCH[1]}"
60*f7c14bbaSAndroid Build Coastguard Worker                CC="gcc-${BASH_REMATCH[1]}"
61*f7c14bbaSAndroid Build Coastguard Worker            fi
62*f7c14bbaSAndroid Build Coastguard Worker            if [[ "$phase" = *"ASAN"* ]]; then
63*f7c14bbaSAndroid Build Coastguard Worker                EXTRA_CFLAGS="${EXTRA_CFLAGS} -fsanitize=address,undefined"
64*f7c14bbaSAndroid Build Coastguard Worker                EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -fsanitize=address,undefined"
65*f7c14bbaSAndroid Build Coastguard Worker            fi
66*f7c14bbaSAndroid Build Coastguard Worker            if [[ "$CC" != "cc" ]]; then
67*f7c14bbaSAndroid Build Coastguard Worker                docker_exec aptitude -y install "$CC"
68*f7c14bbaSAndroid Build Coastguard Worker            else
69*f7c14bbaSAndroid Build Coastguard Worker                docker_exec aptitude -y install gcc
70*f7c14bbaSAndroid Build Coastguard Worker            fi
71*f7c14bbaSAndroid Build Coastguard Worker            docker_exec mkdir build install
72*f7c14bbaSAndroid Build Coastguard Worker            docker_exec ${CC} --version
73*f7c14bbaSAndroid Build Coastguard Worker            info "build"
74*f7c14bbaSAndroid Build Coastguard Worker            docker_exec make -j$((4*$(nproc))) EXTRA_CFLAGS="${EXTRA_CFLAGS}" EXTRA_LDFLAGS="${EXTRA_LDFLAGS}" -C ./src -B OBJDIR=../build
75*f7c14bbaSAndroid Build Coastguard Worker            info "ldd build/libbpf.so:"
76*f7c14bbaSAndroid Build Coastguard Worker            docker_exec ldd build/libbpf.so
77*f7c14bbaSAndroid Build Coastguard Worker            if ! docker_exec ldd build/libbpf.so | grep -q libelf; then
78*f7c14bbaSAndroid Build Coastguard Worker                error "No reference to libelf.so in libbpf.so!"
79*f7c14bbaSAndroid Build Coastguard Worker                exit 1
80*f7c14bbaSAndroid Build Coastguard Worker            fi
81*f7c14bbaSAndroid Build Coastguard Worker            info "install"
82*f7c14bbaSAndroid Build Coastguard Worker            docker_exec make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install
83*f7c14bbaSAndroid Build Coastguard Worker            info "link binary"
84*f7c14bbaSAndroid Build Coastguard Worker            docker_exec bash -c "EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\" EXTRA_LDFLAGS=\"${EXTRA_LDFLAGS}\" ./ci/managers/test_compile.sh"
85*f7c14bbaSAndroid Build Coastguard Worker            ;;
86*f7c14bbaSAndroid Build Coastguard Worker        CLEANUP)
87*f7c14bbaSAndroid Build Coastguard Worker            info "Cleanup phase"
88*f7c14bbaSAndroid Build Coastguard Worker            docker stop $CONT_NAME
89*f7c14bbaSAndroid Build Coastguard Worker            docker rm -f $CONT_NAME
90*f7c14bbaSAndroid Build Coastguard Worker            ;;
91*f7c14bbaSAndroid Build Coastguard Worker        *)
92*f7c14bbaSAndroid Build Coastguard Worker            echo >&2 "Unknown phase '$phase'"
93*f7c14bbaSAndroid Build Coastguard Worker            exit 1
94*f7c14bbaSAndroid Build Coastguard Worker    esac
95*f7c14bbaSAndroid Build Coastguard Workerdone
96