Skip to content

Commit

Permalink
feat: pass extra cflags via LIBBPF_SYS_EXTRA_CFLAGS
Browse files Browse the repository at this point in the history
  • Loading branch information
kxxt authored and danielocfb committed Aug 16, 2024
1 parent 2dbfe03 commit 76cb036
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 76cb036

Please sign in to comment.