Rust-GPU / Rust-GPU/rust-gpu

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

Abierto
#351 3 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug
Lenguaje dominante
Rust
Estrellas
3.4k
Forks
126
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproducir con cargo build -p example-runner-wgpu e inspeccionar la búsqueda de bibliotecas compartidas alrededor de crates/spirv-builder/src/lib.rs:745; compararla con la configuración de ejecución en default.nix y el fallo en examples/runners/wgpu/src/graphics.rs. Se considera terminado cuando el example runner se inicia sin establecer manualmente LD_LIBRARY_PATH, usando el enlace normal de bibliotecas compartidas o un RPATH adecuado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
nixos, rust
Área
build-system, computer-graphics
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.