Skip to content

Conversation

edmonds
Copy link
Contributor

@edmonds edmonds commented Feb 13, 2025

When xdp-tools builds the embedded copy of libbpf, it invokes the libbpf build system to installs it headers, and then constructs a path to those embedded libbpf headers based on the assumption that libbpf installed its headers into its default PREFIX (which appears to be /usr):

LIBBPF_INCLUDE_DIR='$(LIB_DIR)/libbpf/src/root/usr/include'

However, if PREFIX is passed to the xdp-tools build system, this variable gets passed down to the invocation of the libbpf build system as well, and libbpf installs its headers into a different directory that doesn't match xdp-tools' LIBBPF_INCLUDE_DIR variable, and the build fails like this:

$ make PREFIX=/usr/local
[…]
libbpf support: Submodule 'libbpf' (https://github.com/libbpf/libbpf.git) registered for path 'lib/libbpf'
Cloning into '/home/edmonds/src/xdp-tools/lib/libbpf'...
Submodule path 'lib/libbpf': checked out 'fdf402b384cc42ce29bb9e27011633be3cbafe1e'
submodule v1.4.0
[…]
lib

  libbpf
    CC       libbpf/src/libbpf.a
    INSTALL  libbpf/src/libbpf.a

  libxdp
    CC       staticobjs/libxdp.o
libxdp.c:31:10: fatal error: bpf/libbpf.h: No such file or directory
   31 | #include <bpf/libbpf.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.

This commit explicitly passes PREFIX=/usr to the libbpf build system when installing the embedded libbpf headers so that xdp-tools' LIBBPF_INCLUDE_DIR variable still matches the path to those headers.

@tohojo
Copy link
Member

tohojo commented Feb 24, 2025

Thanks for the patch!

If we're setting this explicitly, I'm wondering whether we shouldn't just drop /usr from the prefix (i.e., just set PREFIX=, and then adjust the include dir accordingly? Mostly from an aesthetic PoV. WDYT, any reason we can't do that?

@edmonds
Copy link
Contributor Author

edmonds commented Feb 24, 2025

I haven't tested it but I would imagine it would work fine.

@tohojo
Copy link
Member

tohojo commented Feb 25, 2025

Alright, please update the PR to do that, then :)

When xdp-tools builds the embedded copy of libbpf, it invokes the libbpf
build system to installs it headers, and then constructs a path to
those embedded libbpf headers [0] based on the assumption that libbpf
installed its headers into its default PREFIX value of /usr.

However, if PREFIX is passed to the xdp-tools build system, this
variable gets passed down to the invocation of the libbpf build system
as well, and libbpf installs its headers into a different directory
that doesn't match xdp-tools' LIBBPF_INCLUDE_DIR variable, and the build
fails like this:

    $ make PREFIX=/usr/local
    […]
    libbpf support: Submodule 'libbpf' (https://github.com/libbpf/libbpf.git) registered for path 'lib/libbpf'
    Cloning into '/home/edmonds/src/xdp-tools/lib/libbpf'...
    Submodule path 'lib/libbpf': checked out 'fdf402b384cc42ce29bb9e27011633be3cbafe1e'
    submodule v1.4.0
    […]
    lib

      libbpf
        CC       libbpf/src/libbpf.a
        INSTALL  libbpf/src/libbpf.a

      libxdp
        CC       staticobjs/libxdp.o
    libxdp.c:31:10: fatal error: bpf/libbpf.h: No such file or directory
       31 | #include <bpf/libbpf.h>
          |          ^~~~~~~~~~~~~~
    compilation terminated.

This commit explicitly passes PREFIX=/ to the libbpf build system
when installing the embedded libbpf headers, and also updates the
LIBBPF_INCLUDE_DIR variable in the xdp-tools build system to match the
resulting include path, so that the embedded libbpf headers are
installed into a fixed location.

[0]: https://github.com/xdp-project/xdp-tools/blob/7b3bbe2f6f16d658bb09a7b7e5958f4a49825ee6/configure#L382

Signed-off-by: Robert Edmonds <[email protected]>
@edmonds edmonds changed the title lib/Makefile: Explicitly set PREFIX when installing embedded libbpf headers Explicitly set PREFIX=/ when installing embedded libbpf headers Feb 25, 2025
@edmonds
Copy link
Contributor Author

edmonds commented Feb 25, 2025

Alright, please update the PR to do that, then :)

Done.

@tohojo tohojo merged commit 981123b into xdp-project:main Feb 26, 2025
29 checks passed
@edmonds edmonds deleted the fix-embedded-libbpf-build-with-prefix branch February 26, 2025 17:50
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