"cargo build" for redbpf fails with "the name <NAME> is defined multiple times"
Hi!
I have successfully build docker image from https://github.com/foniod/build-images:
docker build --no-cache -t ebpf-20.04 -f Dockerfile.20.04 .
Then I run docker image:
docker run -it --name ebpf-20.04 ebpf-20.04
And tried to build the release:
root@e53d1ecf1999:/build# git clone --branch v2.0.1 https://github.com/foniod/redbpf
root@e53d1ecf1999:/build# cd redbpf/
root@e53d1ecf1999:/build/redbpf# git submodule sync
root@e53d1ecf1999:/build/redbpf# git submodule update --init
root@e53d1ecf1999:/build/redbpf# cargo build
Build failed with:
...
Compiling example-probes v0.1.0 (/build/redbpf/examples/example-probes)
error[E0428]: the name `BPF_ANY` is defined multiple times
--> /build/redbpf/target/debug/build/redbpf-probes-40cfac10474760be/out/gen_bindings.rs:201062:5
|
135864 | pub const BPF_ANY: ::cty::c_uint = 0;
| ------------------------------------- previous definition of the value `BPF_ANY` here
...
201062 | pub const BPF_ANY: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `BPF_ANY` redefined here
|
= note: `BPF_ANY` must be defined only once in the value namespace of this module
...
And a few dozen similar errors, see full build log in attach: cargo-build.log
The following combinations ended with a similar error:
- Dockerfile.20.04 + master
- Dockerfile.20.04 + 2.0.1
- Dockerfile.20.04 + 2.0.0
- Dockerfile.18.04 + 2.0.1
- Dockerfile.18.04 + 2.0.0
Host kernel:
$ uname -a
Linux desktop 5.10.0-4-amd64 #1 SMP Debian 5.10.19-1 (2021-03-02) x86_64 GNU/Linux
Hello @Des333
Thank you for filing this issue.
TL;DR
You can avoid this issue by passing a KERENL_VERSION environment variable.
In ubuntu 20.04
$ KERNEL_VERSION=5.4.0-81-generic cargo build
In ubuntu 18.04
$ KERNEL_VERSION=4.19.5-041905-generic cargo build
Cause
While building redbpf-probe, its build script tries to find the Linux kernel
headers of the currently running Linux kernel version. To find the headers,
it calls uname system call and gets information about the kernel. But in
the docker container the uname system call returns the information about a host
kernel and the build script of redbpf-probes can not correctly locate the
kernel headers in /lib/modules directory.
In this case, users can fix this problem by setting KERNEL_VERSION
environment variable.
Conclusion
I think that redbpf-probes should emit different error messages to give users
more transparent hint.. I'll consider a better method for this case.
Thank you