-
Notifications
You must be signed in to change notification settings - Fork 67
Description
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