Skip to content

Commit

Permalink
Stop abusing LD_LIBRARY_PATH
Browse files Browse the repository at this point in the history
LD_LIBRARY_PATH is meant for the dynamic linker to search for shared
libraries at runtime. Previously libbpf-sys abused this variable to
provide pathes for the linker(invoked by rustc) to find libraries at
build time. And this is not documented at all.

This commit proposes to use a dedicated enviroment variable for this
purpose and documents it in README.md
  • Loading branch information
kxxt authored and danielocfb committed Aug 21, 2024
1 parent 9b7afd7 commit d3ba1f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $ cargo build
#### Environment Variables

- `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.

### Distribution

Expand Down
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ fn main() {
);
println!("cargo:include={}/include", out_dir.to_string_lossy());

println!("cargo:rerun-if-env-changed=LD_LIBRARY_PATH");
if let Ok(ld_path) = env::var("LD_LIBRARY_PATH") {
for path in ld_path.split(':') {
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);
}
Expand Down

0 comments on commit d3ba1f3

Please sign in to comment.