Rust-GPU / Rust-GPU/rust-gpu

Link to shared libraries normally or set RPATH, instead of relying on LD_LIBRARY_PATH

Aperta
#351 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
Rust
Stelle
3.4k
Fork
125
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riprodurre con cargo build -p example-runner-wgpu e ispezionare la ricerca delle librerie condivise intorno a crates/spirv-builder/src/lib.rs:745; confrontarla con le impostazioni di runtime in default.nix e con l’errore in examples/runners/wgpu/src/graphics.rs. Il lavoro è concluso quando l’example runner si avvia senza impostare manualmente LD_LIBRARY_PATH, usando il normale linking delle librerie condivise o un RPATH appropriato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
nixos, rust
Ambito
build-system, computer-graphics
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.