Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make novendor feature the default #521

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libbpf-cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ path = "src/lib.rs"
[features]
# When turned on, link against system-installed libbpf instead of building
# and linking against vendored libbpf sources
novendor = ["libbpf-sys/novendor"]
static = ["libbpf-sys/static"]

[dependencies]
anyhow = "1.0.1"
Expand Down
6 changes: 3 additions & 3 deletions libbpf-cargo/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn extract_version(output: &str) -> Result<&str> {
/// Extract vendored libbpf header files to a temporary directory.
///
/// Directory and enclosed contents will be removed when return object is dropped.
#[cfg(not(feature = "novendor"))]
#[cfg(feature = "static")]
fn extract_libbpf_headers_to_disk(target_dir: &Path) -> Result<Option<PathBuf>> {
use std::fs::OpenOptions;
use std::io::Write;
Expand All @@ -68,8 +68,8 @@ fn extract_libbpf_headers_to_disk(target_dir: &Path) -> Result<Option<PathBuf>>
Ok(Some(parent_dir))
}

#[cfg(feature = "novendor")]
fn extract_libbpf_headers_to_disk(target_dir: &Path) -> Result<Option<PathBuf>> {
#[cfg(not(feature = "static"))]
fn extract_libbpf_headers_to_disk(_target_dir: &Path) -> Result<Option<PathBuf>> {
return Ok(None);
}

Expand Down
6 changes: 3 additions & 3 deletions libbpf-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ keywords = ["bpf", "ebpf", "libbpf"]
maintenance = { status = "actively-developed" }

[features]
# When turned on, link against system-installed libbpf instead of building
# and linking against vendored libbpf sources
novendor = ["libbpf-sys/novendor"]
# When turned on, compile and link all libbpf library dependencies statically
# this will vendor the C-libraries libelf, libz, and libbpf
# When turned off, dynamically link all libbpf library dependencies
static = ["libbpf-sys/static"]

[dependencies]
Expand Down
23 changes: 23 additions & 0 deletions libbpf-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@
//! libbpf-rs at your BPF object file
//! 1. Continue regular rust workflow (ie `cargo build`, `cargo run`, etc)
//!
//! ## Static Compilation
//!
//! By default, programs using libbpf-rs will dynamically link against
//! non-vendored (system/distrubution provided) shared libraries. These
//! non-vendored libraries will include libbpf.so, libz.so, and libelf.so
//! (please see crate libbpf-sys for more info).
//!
//! To use vendored versions of libbpf, libz and libelf please enable
//! the "static" feature. With usage of "static", vendored copies of
//! libbpf, libz, and libelf will be compiled and statically linked to your program.
//!
//! Due to the C-library libbpf being tightly coupled to the linux kernel's
//! headers, musl targets will not work with the "static" feature.
//! Please see: https://wiki.musl-libc.org/faq.html section
//! "Why am i getting error: redefinition of..." for more information.
//!
//! To have a fully statically compiled binary, you may be able statically link
//! with the gnu compiler. To do this, enable the "static" feature
//! and compile your program with the following command:
//!
//! $ RUSTFLAGS='-C target-feature+crt-static' \
//! cargo build --target x86_64-unknown-linux-gnu
//!
//! ## Design
//!
//! libbpf-rs models various "phases":
Expand Down
Loading