Skip to content

Commit b3af6fa

Browse files
committed
ci: libbpf-dev + conditional eBPF build (stub fallback without libbpf)
1 parent 7abd12a commit b3af6fa

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ jobs:
1818
- name: Install toolchain
1919
run: |
2020
sudo apt-get update
21-
sudo apt-get install -y cmake g++ clang linux-libc-dev
21+
sudo apt-get install -y cmake g++ clang libbpf-dev libelf-dev linux-libc-dev
22+
23+
- name: Compile eBPF object
24+
run: |
25+
# l'objet eBPF est compilé par le build CMake (clang -target bpf)
26+
# avec les headers système ; clang sur GH Actions a besoin des
27+
# includes asm de la libc
28+
echo "compilé par CMake (voir configure)"
2229
2330
- name: Configure
2431
run: |

‎CMakeLists.txt‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,30 @@ target_include_directories(memflux_core PUBLIC include)
4545
target_link_libraries(memflux_core PUBLIC Threads::Threads bpf)
4646

4747
# eBPF : l'objet est compilé si clang est disponible (optionnel au runtime)
48+
find_package(PkgConfig QUIET)
4849
find_program(CLANG_BPF clang)
49-
if(CLANG_BPF)
50+
if(PKG_CONFIG_FOUND)
51+
pkg_check_modules(LIBBPF libbpf)
52+
endif()
53+
if(CLANG_BPF AND LIBBPF_FOUND)
5054
add_custom_command(
5155
OUTPUT ${CMAKE_BINARY_DIR}/ebpf_access.bpf.o
5256
COMMAND ${CLANG_BPF} -O2 -g -target bpf -D__TARGET_ARCH_x86
53-
-I/usr/include -c ${CMAKE_SOURCE_DIR}/src/kern/ebpf_access.bpf.c
57+
-I/usr/include/x86_64-linux-gnu -I/usr/include
58+
-c ${CMAKE_SOURCE_DIR}/src/kern/ebpf_access.bpf.c
5459
-o ${CMAKE_BINARY_DIR}/ebpf_access.bpf.o
5560
DEPENDS src/kern/ebpf_access.bpf.c
5661
COMMENT "clang -target bpf: ebpf_access")
5762
add_custom_target(ebpf_obj ALL
5863
DEPENDS ${CMAKE_BINARY_DIR}/ebpf_access.bpf.o)
64+
target_include_directories(memflux_core PUBLIC ${LIBBPF_INCLUDE_DIRS})
65+
target_link_directories(memflux_core PUBLIC ${LIBBPF_LIBRARY_DIRS})
5966
target_compile_definitions(memflux_core PUBLIC
6067
EbpfObjectPath="${CMAKE_BINARY_DIR}/ebpf_access.bpf.o")
6168
else()
62-
target_compile_definitions(memflux_core PUBLIC
63-
EbpfObjectPath="")
69+
# backend eBPF désactivé au runtime (EbpfObjectPath vide)
70+
add_library(ebpf_stub OBJECT src/kern/ebpf_stub.cpp)
71+
target_compile_definitions(memflux_core PUBLIC EbpfObjectPath="")
6472
endif()
6573

6674
# ---------------------------------------------------------------------------

‎src/kern/ebpf.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ struct fault_val { __u64 minor; };
7171
std::map<pid_t, uint64_t> drain_faults(){
7272
std::map<pid_t, uint64_t> out;
7373
if(!g.map) return out;
74-
int fd = bpf_map__fd(g.map);
7574
struct fault_key key = {}, next = {};
7675
struct fault_val val = {};
7776
while(bpf_map__get_next_key(g.map, &key, &next, sizeof(next)) == 0){

‎src/kern/ebpf_stub.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "memflux/ebpf.hpp"
2+
namespace memflux::ebpf {
3+
// stub : eBPF indisponible (libbpf ou clang -target bpf absent au build)
4+
bool available(){ return false; }
5+
bool load(){ return false; }
6+
void unload(){}
7+
bool loaded(){ return false; }
8+
std::map<pid_t, uint64_t> drain_faults(){ return {}; }
9+
} // namespace memflux::ebpf

0 commit comments

Comments
 (0)