Skip to content

examples/c: rebuild BPF objects on header changes in CMake - #372

Merged
danielocfb merged 1 commit into
libbpf:masterfrom
Dhanya16:fix/cmake-bpf-header-deps
Aug 31, 2026
Merged

examples/c: rebuild BPF objects on header changes in CMake#372
danielocfb merged 1 commit into
libbpf:masterfrom
Dhanya16:fix/cmake-bpf-header-deps

Conversation

@Dhanya16

Copy link
Copy Markdown
Contributor

Problem: bpf_object() supports optional headers in DEPENDS, but examples/c/CMakeLists.txt only passed the .bpf.c source. Touching a shared header (e.g. bootstrap.h) rebuilt userspace via CMake's normal C dependency scanning, but not the BPF object or skeleton.

Change: Pass ${app_stem}.h into bpf_object() when that file exists.

Follow-up to #371 (CMake path noted by @danielocfb ).

Before:

$ stat -c '%y %n' bootstrap.bpf.o
2026-08-31 15:06:42.837222615 +0530 bootstrap.bpf.o
$ touch ../bootstrap.h
$ cmake --build . --target bootstrap 2>&1 | grep -E 'Building BPF|skel|bootstrap\.c'
[ 85%] Building C object CMakeFiles/bootstrap.dir/bootstrap.c.o
$ stat -c '%y %n' bootstrap.bpf.o
2026-08-31 15:06:42.837222615 +0530 bootstrap.bpf.o

After:

$ stat -c '%y %n' bootstrap.bpf.o
2026-08-31 16:03:20.703857431 +0530 bootstrap.bpf.o
$ touch ../bootstrap.h
$ cmake --build . --target bootstrap 2>&1 | grep -E 'Building BPF|skel|bootstrap\.c'
[ 85%] [clang] Building BPF object: bootstrap
[ 90%] [skel]  Building BPF skeleton: bootstrap
[ 95%] Building C object CMakeFiles/bootstrap.dir/bootstrap.c.o
$ stat -c '%y %n' bootstrap.bpf.o
2026-08-31 16:04:14.114486381 +0530 bootstrap.bpf.o

Signed-off-by: Dhanya16 <dhanyabailoor@gmail.com>
@danielocfb

Copy link
Copy Markdown
Collaborator

Not entirely convinced this is the entire story, as I think it relies on a bug in the existing cmake plumbing. But it's probably better than the status quo.

@danielocfb
danielocfb merged commit 2fdb354 into libbpf:master Aug 31, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants