Skip to content

Commit 6622543

Browse files
committed
compile_codegen: validate rustc_codegen_spirv_location on build
1 parent 92f1c0d commit 6622543

File tree

1 file changed

+9
-11
lines changed
  • crates/spirv-builder/src

1 file changed

+9
-11
lines changed

crates/spirv-builder/src/lib.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ pub enum SpirvBuilderError {
107107
"Without feature `compile_codegen`, you need to set the path of the codegen dylib using `rustc_codegen_spirv_location(...)`"
108108
)]
109109
MissingCodegenBackendDylib,
110+
#[error("`rustc_codegen_spirv_location` path '{0}' is not a file")]
111+
CodegenBackendDylibDoesNotExist(PathBuf),
110112
#[error("build failed")]
111113
BuildFailed,
112114
#[error("multi-module build cannot be used with print_metadata = MetadataPrintout::Full")]
@@ -556,17 +558,8 @@ impl SpirvBuilder {
556558
}
557559

558560
#[must_use]
559-
pub fn rustc_codegen_spirv_location(
560-
mut self,
561-
path_to_dylib: impl AsRef<std::path::Path>,
562-
) -> Self {
563-
let path_to_dylib = path_to_dylib.as_ref().to_path_buf();
564-
assert!(
565-
path_to_dylib.is_file(),
566-
"Provided path to dylib '{}' is not a file",
567-
path_to_dylib.display()
568-
);
569-
self.rustc_codegen_spirv_location = Some(path_to_dylib);
561+
pub fn rustc_codegen_spirv_location(mut self, path_to_dylib: impl AsRef<Path>) -> Self {
562+
self.rustc_codegen_spirv_location = Some(path_to_dylib.as_ref().to_path_buf());
570563
self
571564
}
572565

@@ -732,6 +725,11 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
732725
let rustc_codegen_spirv = Ok(builder.rustc_codegen_spirv_location.clone())
733726
.transpose()
734727
.unwrap_or_else(find_rustc_codegen_spirv)?;
728+
if !rustc_codegen_spirv.is_file() {
729+
return Err(SpirvBuilderError::CodegenBackendDylibDoesNotExist(
730+
rustc_codegen_spirv,
731+
));
732+
}
735733

736734
let mut rustflags = vec![
737735
format!("-Zcodegen-backend={}", rustc_codegen_spirv.display()),

0 commit comments

Comments
 (0)