diff --git a/README.md b/README.md index 05cfa79..5fee596 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ $ git clone --recurse-submodules https://github.com/libbpf/libbpf-sys.git && cd $ cargo build ``` +#### Environment Variables + +- `LIBBPF_SYS_EXTRA_CFLAGS` can be used to pass extra cflags when vendoring libbpf, libz or libelf. + ### Distribution 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. diff --git a/build.rs b/build.rs index 7fb9f0f..1169add 100644 --- a/build.rs +++ b/build.rs @@ -10,7 +10,6 @@ use std::process; use nix::fcntl; - fn emit_rerun_directives_for_contents(dir: &Path) { for result in read_dir(dir).unwrap() { let file = result.unwrap(); @@ -156,7 +155,13 @@ fn main() { let compiler = cc::Build::new().try_get_compiler().expect( "a C compiler is required to compile libbpf-sys using the vendored copy of libbpf", ); - let cflags = compiler.cflags_env(); + let mut cflags = compiler.cflags_env(); + println!("cargo:rerun-if-env-changed=LIBBPF_SYS_EXTRA_CFLAGS"); + let extra_cflags = env::var_os("LIBBPF_SYS_EXTRA_CFLAGS").unwrap_or_default(); + if !extra_cflags.is_empty() { + cflags.push(" "); + cflags.push(extra_cflags); + } (Some(compiler), cflags) } else { (None, ffi::OsString::new())