Skip to content

Commit 4a8bc20

Browse files
committed
Inject necessary RUNPATH klint can work without LD_LIBRARY_PATH
1 parent 8048f4a commit 4a8bc20

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ cargo install --path .
2020

2121
Note that klint currently is pinned to a Rust version so it is likely that running `cargo install --git` will not work as it will not use the `rust-toolchain` file in the repository.
2222

23-
To run this tool, use rustup which will prepare the necessary environment variables:
24-
```
25-
rustup run nightly klint
26-
```
23+
To run this tool for Linux kernel build, use `make RUSTC=<path to klint>` to use klint in place of a Rust compiler.
2724

2825
klint is developed against latest nightly rustc; if you would like to use it with a stable Rust version, check the tagged releases.
2926

‎build.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
fn probe_sysroot() -> String {
2+
std::process::Command::new("rustc")
3+
.arg("--print")
4+
.arg("sysroot")
5+
.output()
6+
.ok()
7+
.and_then(|out| String::from_utf8(out.stdout).ok())
8+
.map(|x| x.trim().to_owned())
9+
.expect("failed to probe rust sysroot")
10+
}
11+
12+
fn main() {
13+
// No need to rerun for other changes.
14+
println!("cargo::rerun-if-changed=build.rs");
15+
16+
// Probe rustc sysroot. Although this is automatically added when using Cargo, the compiled
17+
// binary would be missing the necessary RPATH so it cannot run without using Cargo.
18+
let sysroot = probe_sysroot();
19+
println!("cargo::rustc-link-arg=-Wl,-rpath={sysroot}/lib");
20+
}

0 commit comments

Comments
 (0)