Skip to content

Commit 8473e1a

Browse files
committed
fix: use system libelf-static on Alpine, vendored-libelf only on Ubuntu
vendored-libelf (libbpf-sys) calls make_elfutils() which runs elfutils' autoconf configure. That configure calls AC_SEARCH_LIBS([argp_parse], [argp]) AC_SEARCH_LIBS([fts_close], [fts]) Both argp and fts are GNU/BSD extensions absent from musl libc, causing a hard configure error on Alpine. argp-standalone fixes the first but fts_close is still missing, making this a whack-a-mole problem. Root cause fix: - Alpine 3.20 ships libelf-static which is already musl-compiled WITHOUT zstd. vendored-libelf is unnecessary there. Use the system .a. - Ubuntu 24.04 ships a glibc libelf.a compiled WITH zstd (unusable for musl targets), so vendored-libelf IS required. Ubuntu glibc provides both argp_parse and fts_close, so configure succeeds. Changes: * Cargo.toml: move vendored-libelf out of libbpf-sys default features; add optional edriver feature 'vendored-libelf' that proxies to libbpf-sys/vendored-libelf. * Makefile: add CARGO_EXTRA_FEATURES variable (default empty); append it to --features= in build/debug/test targets. * CI yaml: - x86_64/Alpine: add libelf-static package; remove argp-standalone and all autotools no longer needed. - aarch64/Ubuntu: set cargo_extra_features=',vendored-libelf'. - Pass CARGO_EXTRA_FEATURES env in Build and Test steps. - Bump cache key to v4.
1 parent dc4e809 commit 8473e1a

3 files changed

Lines changed: 35 additions & 22 deletions

File tree

.github/workflows/ci-edriver.yaml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
# zlib-static installs libz.a to /lib (not /usr/lib) on Alpine 3.20.
3333
lib_path: /lib:/usr/lib
3434
extra_cflags: ""
35+
# Alpine libelf-static is musl-native, no zstd dep: no vendored-libelf.
36+
cargo_extra_features: ""
3537
- arch: aarch64
3638
runner: ubuntu-24.04-arm
3739
target: aarch64-unknown-linux-musl
@@ -41,8 +43,12 @@ jobs:
4143
cc: musl-gcc
4244
lib_path: ""
4345
# musl-gcc uses -nostdinc; re-add system includes so vendored
44-
# elfutils and libbpf can find kernel headers (linux/bpf.h etc.).
46+
# libbpf can find kernel headers (linux/bpf.h etc.).
4547
extra_cflags: "-I/usr/include -I/usr/include/aarch64-linux-gnu"
48+
# Ubuntu libelf is glibc-compiled: must vendored-compile elfutils.
49+
# elfutils configure needs argp+fts which exist on glibc (Ubuntu) but
50+
# not on musl (Alpine), hence this is Ubuntu-only.
51+
cargo_extra_features: ",vendored-libelf"
4652
steps:
4753
# ── Alpine (x86_64) ─────────────────────────────────────────────────
4854
# Install BEFORE actions/checkout so git/bash/curl are available for
@@ -54,12 +60,10 @@ jobs:
5460
bash curl git \
5561
build-base linux-headers \
5662
clang llvm \
57-
elfutils-dev \
63+
elfutils-dev libelf-static \
5864
zlib-dev zlib-static \
5965
protobuf-dev \
60-
pkgconf \
61-
autoconf automake libtool gettext-dev flex bison gawk perl \
62-
argp-standalone
66+
pkgconf
6367
6468
# ── Ubuntu (aarch64) ────────────────────────────────────────────────
6569
- name: Install build dependencies (Ubuntu / aarch64)
@@ -94,8 +98,8 @@ jobs:
9498
path: |
9599
~/.cargo/registry
96100
~/.cargo/git
97-
key: ${{ matrix.arch }}-cargo-edriver-v3-${{ hashFiles('plugins/edriver/Cargo.lock') }}
98-
restore-keys: ${{ matrix.arch }}-cargo-edriver-v3-
101+
key: ${{ matrix.arch }}-cargo-edriver-v4-${{ hashFiles('plugins/edriver/Cargo.lock') }}
102+
restore-keys: ${{ matrix.arch }}-cargo-edriver-v4-
99103

100104
- name: Verify toolchain
101105
run: |
@@ -108,19 +112,19 @@ jobs:
108112
cd plugins/edriver && make build
109113
env:
110114
PLATFORM: ${{ matrix.arch }}
111-
# vendored-libelf built with --without-zstd → no libzstd needed.
112-
# vendored-zlib compiled from source → no system libz.a needed.
113-
# lib_path is a fallback search path (libz.a on Alpine is in /lib).
115+
# x86_64 Alpine: system libelf-static is musl-native (no zstd).
116+
# lib_path covers /lib where Alpine's zlib-static installs libz.a.
114117
LIBBPF_SYS_LIBRARY_PATH: ${{ matrix.lib_path }}
115-
# Kernel headers for vendored C compilation inside musl-gcc -nostdinc.
118+
# aarch64 Ubuntu: musl-gcc -nostdinc needs kernel headers explicitly.
116119
LIBBPF_SYS_EXTRA_CFLAGS: ${{ matrix.extra_cflags }}
117120
# Override .cargo/config.toml [env] which defaults to "musl-gcc".
118121
CC_x86_64_unknown_linux_musl: ${{ matrix.cc }}
119122
CC_aarch64_unknown_linux_musl: ${{ matrix.cc }}
120123
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: ${{ matrix.cc }}
121124
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: ${{ matrix.cc }}
122-
# No -lzstd link arg needed: vendored elfutils is --without-zstd.
123125
RUSTFLAGS: "-C target-feature=+crt-static"
126+
# Activates vendored-libelf only on Ubuntu aarch64 (see matrix).
127+
CARGO_EXTRA_FEATURES: ${{ matrix.cargo_extra_features }}
124128

125129
- name: Test
126130
run: |
@@ -135,3 +139,4 @@ jobs:
135139
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: ${{ matrix.cc }}
136140
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: ${{ matrix.cc }}
137141
RUSTFLAGS: "-C target-feature=+crt-static"
142+
CARGO_EXTRA_FEATURES: ${{ matrix.cargo_extra_features }}

plugins/edriver/Cargo.toml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ description = "Rust version of hades edriver"
77

88
[features]
99
debug = ["sdk/debug"]
10-
# The `static` feature chains to libbpf-rs/static → libbpf-sys/static, which
11-
# links the system libelf.a. On Ubuntu 24.04+ that libelf.a is compiled with
12-
# USE_ZSTD and references ZSTD_* symbols. libbpf-sys does NOT emit
13-
# `cargo:rustc-link-lib=zstd`, so we must add `-lzstd` manually in
14-
# .cargo/config.toml ([build].rustflags for host build-scripts, and
15-
# [target.*-musl].rustflags for the final binary).
1610
static = ["libbpf-rs/static"]
11+
# Enable vendored elfutils compilation via libbpf-sys.
12+
# Only needed on glibc hosts (Ubuntu) where the system libelf.a is compiled
13+
# with USE_ZSTD. On Alpine/musl the system libelf-static is already
14+
# musl-native and zstd-free, so this is unnecessary (and won't build on musl
15+
# because elfutils configure requires glibc-only argp/fts).
16+
vendored-libelf = ["libbpf-sys/vendored-libelf"]
1717

1818
[dependencies]
1919
anyhow = "1.0"
@@ -31,7 +31,11 @@ libbpf-rs = { version = "0.26.2", features = ["static"] }
3131
# compiled with glibc headers (_FORTIFY_SOURCE=2), which generates
3232
# __snprintf_chk / __vsnprintf_chk calls that musl doesn't provide.
3333
# Compiling zlib from source with musl-gcc uses musl headers and avoids these.
34-
libbpf-sys = { version = "1.7", features = ["vendored-zlib", "vendored-libelf"] }
34+
# vendored-zlib: compile zlib from source so the .a is musl-compatible on
35+
# both Alpine and Ubuntu. vendored-libelf is NOT listed here; it is gated
36+
# behind the optional `vendored-libelf` feature above and activated only on
37+
# glibc CI (ubuntu:24.04 aarch64) via CARGO_EXTRA_FEATURES in the Makefile.
38+
libbpf-sys = { version = "1.7", features = ["vendored-zlib"] }
3539
bitflags = "2.11.1"
3640
moka = { version = "0.12", features = ["sync"] }
3741
sdk = { path = "../../SDK/rust" }

plugins/edriver/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
22
CMD_CLANG ?= clang
3+
# Extra cargo features appended to every --features= flag.
4+
# Set to ",vendored-libelf" on glibc hosts (ubuntu aarch64 CI) where the
5+
# system libelf.a is glibc-compiled and vendored compilation is required.
6+
CARGO_EXTRA_FEATURES ?=
37

48
LIB_PATH := ../libs
59
LIBBPF_CFLAGS = "-fPIC"
@@ -28,14 +32,14 @@ build: \
2832
headers/libbpf/libbpf.a
2933

3034
cargo fmt
31-
cargo build --release --bin edriver --target $(PLATFORM)-unknown-linux-$(LIBC) --features=static
35+
cargo build --release --bin edriver --target $(PLATFORM)-unknown-linux-$(LIBC) --features=static$(CARGO_EXTRA_FEATURES)
3236

3337
debug: \
3438
headers/libbpf/libbpf.a
3539

3640
cargo fmt
37-
cargo build --release --bin edriver --target $(PLATFORM)-unknown-linux-$(LIBC) --features=static,debug
41+
cargo build --release --bin edriver --target $(PLATFORM)-unknown-linux-$(LIBC) --features=static,debug$(CARGO_EXTRA_FEATURES)
3842

3943
test:
4044
cargo fmt
41-
cargo test --target $(PLATFORM)-unknown-linux-$(LIBC) --features=static,debug -- --include-ignored --show-output
45+
cargo test --target $(PLATFORM)-unknown-linux-$(LIBC) --features=static,debug$(CARGO_EXTRA_FEATURES) -- --include-ignored --show-output

0 commit comments

Comments
 (0)