Rust-GPU / Rust-GPU/rust-gpu

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

オープン
#351 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
Rust
スター
3.4k
フォーク
126
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

cargo build -p example-runner-wgpu で再現し、crates/spirv-builder/src/lib.rs:745 周辺の共有ライブラリ検索を調査する。default.nix のランタイム設定および examples/runners/wgpu/src/graphics.rs での失敗と比較する。LD_LIBRARY_PATH を手動で設定せず、通常の共有ライブラリリンクまたは適切な RPATH を使用して example runner が起動すれば完了とする。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
nixos, rust
領域
build-system, computer-graphics
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。