Skip to content

Add novendor build flag to use system installed libbpf#18

Merged
alexforster merged 1 commit into
libbpf:masterfrom
danobi:pkgconfig
May 10, 2021
Merged

Add novendor build flag to use system installed libbpf#18
alexforster merged 1 commit into
libbpf:masterfrom
danobi:pkgconfig

Conversation

@danobi
Copy link
Copy Markdown
Member

@danobi danobi commented May 10, 2021

This commit adds support to build libbpf-sys using the system installed
libbpf instead of building and linking against the vendored sources.

This is necessary to get libbpf-sys packaged into (most) distro's
package repositories. For example, Fedora has this requirement:
https://fedoraproject.org/wiki/Bundled_Libraries

This closes #10 .

@danobi
Copy link
Copy Markdown
Member Author

danobi commented May 10, 2021

Test plan

With this docker container:

FROM fedora:34

RUN dnf update
RUN dnf install -y curl gcc pkgconf-pkg-config
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
RUN dnf install -y libbpf-devel

ENTRYPOINT ["/bin/bash"]

Running:

$ podman build -t fedora -f Dockerfile
$ podman run -v $(pwd):/libbpf-sys -it fedora
[root@6f479fd4ee9a /]# cd libbpf-sys
[root@6f479fd4ee9a libbpf-sys]# cargo test --features novendor
<...>
running 1 test
test tests::test ... ok
<...>
[root@6f479fd4ee9a libbpf-sys]# ldd ./target/debug/deps/tests-f9beebfff4efee33
<...>
        libbpf.so.0 => /lib64/libbpf.so.0 (0x00007fed68ef6000)
<...>
        libelf.so.1 => /lib64/libelf.so.1 (0x00007fed68b83000)
        libz.so.1 => /lib64/libz.so.1 (0x00007fed68b69000)

Comment thread build.rs Outdated

if cfg!(feature = "novendor") {
let libbpf = pkg_config::Config::new()
.atleast_version("0.3.0")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerned this will get out of sync with the crate version – I'll certainly forget to bump it! Can we instead do something like–

    .atleast_version(&format!("{}.{}.{}", env!("CARGO_PKG_VERSION_MAJOR"), env!("CARGO_PKG_VERSION_MINOR"), env!("CARGO_PKG_VERSION_PATCH")))

Since I guarantee that the major/minor/rev numbers will match the libbpf version exactly, I think this should Just Work™.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

This commit adds support to build libbpf-sys using the system installed
libbpf instead of building and linking against the vendored sources.

This is necessary to get libbpf-sys packaged into (most) distro's
package repositories. For example, Fedora has this requirement:
https://fedoraproject.org/wiki/Bundled_Libraries
@alexforster alexforster self-assigned this May 10, 2021
@alexforster
Copy link
Copy Markdown
Member

Looks good. Once Travis runs I'll merge and cut a release.

@alexforster alexforster merged commit 63a762f into libbpf:master May 10, 2021
@alexforster alexforster added the enhancement New feature or request label Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libbpf vendoring

2 participants