Link to shared libraries normally or set RPATH, instead of relying on LD_LIBRARY_PATH
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Rust
- Sterne
- 3.4k
- Forks
- 126
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Expected Behaviour
Binaries should run without requring any magical environment variables.
Example & Steps To Reproduce
The examples are not directly runnable (i.e. not using cargo run) due to unnecessary LD_LIBRARY_PATH shenanigans:
$ cargo build -p example-runner-wgpu
$ target/debug/example-runner-wgpu
thread 'main' panicked at crates/spirv-builder/src/lib.rs:745:9:
Could not find librustc_codegen_spirv.so in library path
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
This happens because you're looking for that file by manually parsing the LD_LIBRARY_PATH environment variable. It's my understanding that this lookup is only performed so the location of that file can be passed to a rustc invocation later, so it doesn't even make sense to look this up in LD_LIBRARY_PATH.
Upon manually setting LD_LIBRARY_PATH:
$ LD_LIBRARY_PATH=$PWD/target/debug ./target/debug/example-runner-wgpu
thread 'main' panicked at examples/runners/wgpu/src/graphics.rs:467:49:
called `Result::unwrap()` on an `Err` value: Os(OsError { line: 81, file: "/home/max/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winit-0.30.7/src/platform_impl/linux/wayland/event_loop/mod.rs", error: WaylandError(Connection(NoWaylandLib)) })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Regardless of the mechanism that's used to find librustc_codegen_spirv.so, it should not be necessary that these graphics libraries are discovered through LD_LIBRARY_PATH at all. Via RUSTFLAGS, one can configure the output binary's RPATH:
--- a/default.nix
+++ b/default.nix
@@ -14,7 +14,7 @@ in with pkgs; stdenv.mkDerivation rec {
nativeBuildInputs = [ rustup ];
# Runtime dependencies (for the example runners).
- LD_LIBRARY_PATH = with xorg; lib.makeLibraryPath [
+ env.RUSTFLAGS = "-C link-arg=-Wl,-rpath,${with xorg; lib.makeLibraryPath [
vulkan-loader
# NOTE(eddyb) winit really wants `libxkbcommon` on Wayland for some reason
@@ -22,5 +22,5 @@ in with pkgs; stdenv.mkDerivation rec {
wayland libxkbcommon
libX11 libXcursor libXi libXrandr
- ];
+ ]}";
}
$ cargo build -p example-runner-wgpu
$ patchelf --print-rpath target/debug/example-runner-wgpu | tr : \\n
/nix/store/pkzygdv7p08cma6q6zbarprkmdbgqn6m-vulkan-loader-1.4.313.0/lib
/nix/store/h64w118vqfw706px8ranz6cx07ki06jl-wayland-1.23.1/lib
/nix/store/dxh4x7x96lfadv500bdw3m2b3h4a3vwa-libxkbcommon-1.10.0/lib
/nix/store/26c0x3gh2g5dpczvjxgjzn0mc22zxpjz-libX11-1.8.12/lib
/nix/store/2dv3na4hkiq5l3af3a25wb5a390grr2x-libXcursor-1.2.3/lib
/nix/store/mnyka5w2k0jbfnfzrazhgwrhk6nnldnq-libXi-1.8.2/lib
/nix/store/22da37glz0r7vs536nj9n6h56kh1lr7m-libXrandr-1.5.4/lib
/home/max/Projects/rust-gpu/outputs/out/lib
/nix/store/q4wq65gl3r8fy746v9bbwgx4gzn0r2kl-glibc-2.40-66/lib
/nix/store/l7d6vwajpfvgsd3j4cr25imd1mzb7d1d-gcc-14.3.0-lib/lib
The best option would be to actually link the binaries to the shared libraries like normal. For example, ash supports this through an optional feature. wgpu does not seem to expose it.
System Info
- Rust: rustc 1.89.0-nightly (be19eda0d 2025-06-22)
- OS: NixOS 25.11.20250627.30e2e28
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Mit cargo build -p example-runner-wgpu reproduzieren und die Suche nach gemeinsam genutzten Bibliotheken rund um crates/spirv-builder/src/lib.rs:745 untersuchen; sie mit den Laufzeiteinstellungen in default.nix und dem Fehler in examples/runners/wgpu/src/graphics.rs vergleichen. Als erledigt gilt die Aufgabe, wenn der Example-Runner ohne manuelles Setzen von LD_LIBRARY_PATH startet und dabei normales Linking gemeinsam genutzter Bibliotheken oder ein geeigneter RPATH verwendet wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- nixos, rust
- Bereich
- build-system, computer-graphics
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100