diff --git a/.github/include/static.sh b/.github/include/static.sh new file mode 100755 index 000000000000..4893440aa5b3 --- /dev/null +++ b/.github/include/static.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# +# This script is the entrypoint for the static build. +# +# To make CI errors easier to reproduce locally, please limit +# this script to using only git, docker, and coreutils. + +set -eux + +IMAGE=bpftrace-static +cd $(git rev-parse --show-toplevel) + +# Build the base image +docker build -t "$IMAGE" -f docker/Dockerfile.static docker/ + +# Perform bpftrace static build +docker run -v $(pwd):$(pwd) -w $(pwd) -i "$IMAGE" <<'EOF' +set -eux +BUILD_DIR=build-static +cmake -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_TESTING=OFF -DSTATIC_LINKING=ON +make -C "$BUILD_DIR" -j$(nproc) + +# Basic smoke test +./"$BUILD_DIR"/src/bpftrace --help + +# Validate that it's a mostly static binary except for libc +EXPECTED="/lib/ld-musl-x86_64.so.1\nlibc.musl-x86_64.so.1" +GOT=$(ldd "$BUILD_DIR"/src/bpftrace | awk '{print $1}') +if ! diff <(echo -e "$EXPECTED") <(echo "$GOT"); then + set +x + >&2 echo "bpftrace incorrectly linked" + exit 1 +fi +EOF diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 000000000000..9e1f7d160cfa --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,16 @@ +name: Static + +on: [push, pull_request] + +# Cancel previous run if a new one is started +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build static bpftrace + run: ./.github/include/static.sh diff --git a/docker/Dockerfile.static b/docker/Dockerfile.static new file mode 100644 index 000000000000..609de1eace8b --- /dev/null +++ b/docker/Dockerfile.static @@ -0,0 +1,44 @@ +# This Dockerfile is used to test STATIC_LINKING=ON builds in the CI + +FROM alpine:3.18 + +RUN apk add --update \ + asciidoctor \ + argp-standalone \ + bash \ + bcc-dev \ + bcc-static \ + bison \ + bzip2-static \ + build-base \ + cereal \ + clang-dev \ + clang-static \ + cmake \ + elfutils-dev \ + flex-dev \ + git \ + gtest-dev \ + libbpf-dev \ + libelf-static \ + libpcap-dev \ + libc6-compat \ + linux-headers \ + llvm16-dev \ + llvm16-static \ + musl-obstack-dev \ + openssl-dev \ + pahole \ + procps \ + python3 \ + wget \ + xxd \ + xz-static \ + zlib-dev \ + zlib-static \ + zstd-dev \ + zstd-static + +# It looks like llvm16 prefers to dynamically link against zstd. Extremely +# unclear why. Work around it by modifying LLVMExports.cmake. +RUN sed -i 's/libzstd_shared/libzstd_static/g' /usr/lib/llvm16/lib/cmake/llvm/LLVMExports.cmake