Skip to content

Commit

Permalink
ci: Add static build job
Browse files Browse the repository at this point in the history
This commit adds a simple CI job that just tests if bpftrace can build
statically. No additional tests are run -- in the past we have not seen
much benefit in embedded-build tests. It was, however, a massive
headache to maintain. So this time we only build.

Nix was not chosen to do static builds as the `pkgsStatic` ecosystem has
some pretty annoying bugs. Basically pkgsStatic applies overlays to try
and statically build all the packages it typically dynamically links
for. While clever, there are bugs everywhere. So it wasn't worth the
hassle. Alpine linux + docker seemed like a much easier option to
maintain.
  • Loading branch information
danobi committed Nov 16, 2023
1 parent 9e73c86 commit baf41c9
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/include/static.sh
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions docker/Dockerfile.static
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit baf41c9

Please sign in to comment.