Skip to content

fix(spirv-builder): error instead of panic when backend dylib is missing - #689

Closed
sorinirimies wants to merge 1 commit into
Rust-GPU:mainfrom
sorinirimies:fix/spirv-builder-dylib-not-found-error
Closed

sorinirimies wants to merge 1 commit into
Rust-GPU:mainfrom
sorinirimies:fix/spirv-builder-dylib-not-found-error

Conversation

@sorinirimies

Copy link
Copy Markdown

Summary

find_rustc_codegen_spirv panicked when the backend dylib wasn't in the library search path. SpirvBuilder::build already returns Result<_, SpirvBuilderError>, so this is now a proper error.

 fn find_rustc_codegen_spirv() -> Result<PathBuf, SpirvBuilderError>
   if cfg!(feature = "rustc_codegen_spirv")
-    ... else panic!("Could not find {filename} in library path")
+    find_rustc_codegen_spirv_in_paths(dylib_path())
+      .ok_or(RustcCodegenSpirvDylibNotFound { filename })

New variant: SpirvBuilderError::RustcCodegenSpirvDylibNotFound { filename: String } — "could not find {filename} in the dynamic library search path".

Evidence

New tests in dylib_lookup:

finds_nothing_in_empty_or_missing_dirs   ok
ignores_unrelated_dylibs                 ok
not_found_error_names_the_dylib          ok

cargo test -p spirv-builder --features watch,clap: 7 passed. Clippy -D warnings clean (default, --no-default-features, watch,clap).

Merge Danger

Door: two-way

Blast Radius: small — SpirvBuilderError is #[non_exhaustive], so the new variant is non-breaking. Callers that relied on the panic now get an Err.

`find_rustc_codegen_spirv` now returns
`SpirvBuilderError::RustcCodegenSpirvDylibNotFound` (the enum is
`#[non_exhaustive]`, so this is non-breaking). Adds dylib lookup tests.
@sorinirimies

Copy link
Copy Markdown
Author

Reproduction

multibuilder run outside the target dir with no dylib search path, so the backend can't be found:

cargo build -p multibuilder && cd /tmp && env -u DYLD_FALLBACK_LIBRARY_PATH <repo>/target/debug/multibuilder

Before (main) — panic inside spirv-builder:

thread 'main' panicked at crates/spirv-builder/src/lib.rs:870:9:
Could not find librustc_codegen_spirv.dylib in library path

After (this PR) — SpirvBuilder::build returns Err; the only panic is the example's own .unwrap():

thread 'main' panicked at examples/multibuilder/src/main.rs:9:34:
called `Result::unwrap()` on an `Err` value: RustcCodegenSpirvDylibNotFound { filename: "librustc_codegen_spirv.dylib" }

@Firestar99 Firestar99 closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants