foniod / redbpf

Rust library for building and running BPF/eBPF modules
Apache License 2.0
1.71k stars 136 forks source link

Check the exit code of `make` executed to build redbpf static library #185

Closed rhdxmr closed 3 years ago

rhdxmr commented 3 years ago

bpf-sys does not check the exit code of make command so that an worse error occurs and users get in trouble to figure out a root cause.

make fails if libelf header files (libelf-dev or elfutils-libelf-devel package) do not exist. However without the checking of exit code, the build script of bpf-sys succeeds and another error occurs while compiling bpf-sys:

error: could not find native static library bpf, perhaps an -L flag is missing? error: could not compile bpf-sys due to previous error

With this error message, it is not easy to understand the root cause and users can not come up with what they should do next.

So it is better to check the exit code of make and panic unless it succeeds. This behavior produces more comprehensive error messages:

make: Entering directory '/home/esrse/opensource/redbpf/bpf-sys/libbpf/src' MKDIR staticobjs CC bpf.o CC btf.o make: Leaving directory '/home/esrse/opensource/redbpf/bpf-sys/libbpf/src'

--- stderr btf.c:18:10: fatal error: gelf.h: No such file or directory 18 | #include | ^~~~ compilation terminated. make: *** [Makefile:113: /home/esrse/opensource/redbpf/target/debug/build/bpf-sys-adb9a2ddcc715ce3/out/libbpf/staticobjs/btf.o] Error 1 thread 'main' panicked at 'failed to build libbpf static library', bpf-sys/build.rs:56:9

Signed-off-by: Junyeong Jeong rhdxmr@gmail.com


This PR alleviates #177 problem case.

rhdxmr commented 3 years ago

@rsdy Thanks for your approval. I am merging this. I hope this change is helpful to our potential users.