Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ $ cargo build

- `LIBBPF_SYS_EXTRA_CFLAGS` can be used to pass extra cflags when vendoring libbpf, libz or libelf.
- `LIBBPF_SYS_LIBRARY_PATH`: colon separated paths for the linker to find native libs.
- `LIBBPF_SYS_LIBRARY_PATH_<TARGET_TRIPLE>`: similar to `LIBBPF_SYS_LIBRARY_PATH`, but used to set per-target library path, to help cross-compilation environments. If `LIBBPF_SYS_LIBRARY_PATH_<TARGET_TRIPLE>` and `LIBBPF_SYS_LIBRARY_PATH` are defined, the paths from both will be used, and the "target" paths will have precedence.

### Distribution

Expand Down
29 changes: 24 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,30 @@ fn main() {
);
println!("cargo:include={}/include", out_dir.to_string_lossy());

println!("cargo:rerun-if-env-changed=LIBBPF_SYS_LIBRARY_PATH");
if let Ok(lib_path) = env::var("LIBBPF_SYS_LIBRARY_PATH") {
for path in lib_path.split(':') {
if !path.is_empty() {
println!("cargo:rustc-link-search=native={}", path);
let global_lib_path = "LIBBPF_SYS_LIBRARY_PATH";
let target_lib_path = format!("{}_{}", global_lib_path, env::var("TARGET").unwrap());
let target_lib_path_underscored = format!(
"{}_{}",
global_lib_path,
env::var("TARGET").unwrap().replace('-', "_")
);

println!("cargo:rerun-if-env-changed={}", global_lib_path);
println!("cargo:rerun-if-env-changed={}", target_lib_path);
println!("cargo:rerun-if-env-changed={}", target_lib_path_underscored);

let lib_paths = vec![
env::var(target_lib_path),
env::var(target_lib_path_underscored),
env::var(global_lib_path),
];

for lib_path in lib_paths {
if let Ok(lib_path) = lib_path {
for path in lib_path.split(':') {
if !path.is_empty() {
println!("cargo:rustc-link-search=native={}", path);
}
}
}
}
Expand Down