#bpf #ebpf #xdp

sys libbpf-sys

Rust bindings to libbpf from the Linux kernel

23 unstable releases (6 breaking)

0.6.1-1 Jan 6, 2022
0.6.0-1 Dec 3, 2021
0.5.0-2 Nov 1, 2021
0.4.0-2 Jul 9, 2021
0.0.0 Nov 7, 2017

#36 in Unix APIs

Download history 2907/week @ 2021-09-26 2075/week @ 2021-10-03 2722/week @ 2021-10-10 2905/week @ 2021-10-17 1820/week @ 2021-10-24 1926/week @ 2021-10-31 2006/week @ 2021-11-07 1342/week @ 2021-11-14 1462/week @ 2021-11-21 1957/week @ 2021-11-28 2010/week @ 2021-12-05 2578/week @ 2021-12-12 1855/week @ 2021-12-19 870/week @ 2021-12-26 2124/week @ 2022-01-02 2407/week @ 2022-01-09

7,387 downloads per month
Used in 12 crates (9 directly)


28K SLoC

C 22K SLoC // 0.1% comments Rust 5.5K SLoC // 0.0% comments Shell 1.5K SLoC // 0.1% comments BASH 45 SLoC // 0.1% comments Python 22 SLoC // 0.3% comments

libbpf-sys Travis CI build status badge crates.io version number badge

Rust bindings to libbpf from the Linux kernel

Maintainer: Alex Forster <alex@alexforster.com>
License: BSD-2-Clause

libbpf-sys is the packaged result of using bindgen to automatically generate Rust FFI bindings to libbpf from the Linux kernel.

Warning: this crate does not provide a high-level or "safe" API wrapper around libbpf. If you are looking for an easier way to use libbpf, check out these other crates that implement higher-level APIs using libbpf-sys...

The community is encouraged to build higher-level crates using libbpf-sys. Please let me know if you do!


As part of the cargo build process, an included copy of libbpf is compiled and statically linked into the resulting binary. This means that, in order to build a project that depends on this crate, your system must provide a working C compiler toolchain (GCC and Clang should both work). Additionally, your system must provide development headers for zlib and libelf, and they must be discoverable via pkgconfig.


When you add this crate as a dependency to your project, your resulting binaries will dynamically link with libz and libelf. This means that the systems where you run your binaries must have these libraries installed.


Because the API of this crate is automatically generated from libbpf sources, it uses a versioning scheme based on the version of libbpf that it provides.

The "Major.Minor.Patch" semver numbers correspond exactly to the libbpf version that each release provides. For example, the 0.0.8-1 release of this crate provides the API for the libbpf v0.0.8 release.

In order to allow for human error, all releases have a "pre-release" version number appended to them. For example, both the 0.0.6-1 and 0.0.6-2 releases of this crate contain bindings to libbpf v0.0.6, but the later release contains bugfixes and/or enhancements to the crate itself.

Note: because this crate uses a "pre-release" version number, it is impossible to use wildcard-style version syntax in your Cargo.toml file. You must specify the exact version of libbpf-sys, and you must not assume that any other version will be API or ABI compatible.

Licensing and Dependencies

This crate is released under the BSD 2-Clause license, and is careful to avoid infecting users with viral licenses.

It currently depends on the following third-party libraries:

Website License Linkage
libbpf github.com/libbpf/libbpf LGPL-2.1-only OR BSD-2-Clause Static
libelf sourceware.org/elfutils LGPL-2.1-or-later OR LGPL-3.0-or-later Dynamic
zlib zlib.net Zlib Dynamic