Skip to content

Commit 13e976a

Browse files
committed
fixup watch from SpirvBuilder changes
1 parent 3265a6e commit 13e976a

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exclude = [
1313
resolver = "2"
1414

1515
[workspace.dependencies]
16-
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu.git", rev = "0c7f509f7da93d0bd12d51230d15a07d0152c593", default-features = false }
16+
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu.git", rev = "f35e492ae03df66ce989927dba2858656a9cf49a", default-features = false }
1717
anyhow = "1.0.94"
1818
clap = { version = "4.5.37", features = ["derive"] }
1919
crossterm = "0.28.1"

crates/cargo-gpu/src/build.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,31 @@ impl Build {
6464
std::env::current_dir()?.display()
6565
);
6666

67-
if !self.build_args.watch {
67+
if self.build_args.watch {
68+
let this = self.clone();
69+
self.build_args
70+
.spirv_builder
71+
.watch(move |result, accept| {
72+
let result1 = this.parse_compilation_result(&result);
73+
if let Some(accept) = accept {
74+
accept.submit(result1);
75+
}
76+
})?
77+
.context("unreachable")??;
78+
std::thread::park();
79+
} else {
6880
crate::user_output!(
6981
"Compiling shaders at {}...\n",
7082
self.install.spirv_install.shader_crate.display()
7183
);
7284
let result = self.build_args.spirv_builder.build()?;
73-
self.parse_compilation_result(result)?;
74-
Ok(())
75-
} else {
76-
let this = self.clone();
77-
self.build_args.spirv_builder.watch(move |result| {
78-
this.parse_compilation_result(result)
79-
.expect("watch operation failed")
80-
})?;
81-
std::thread::park();
82-
Ok(())
85+
self.parse_compilation_result(&result)?;
8386
}
87+
Ok(())
8488
}
8589

86-
fn parse_compilation_result(&self, result: CompileResult) -> anyhow::Result<()> {
90+
/// Parses compilation result from `SpirvBuilder` and writes it out to a file
91+
fn parse_compilation_result(&self, result: &CompileResult) -> anyhow::Result<()> {
8792
let shaders = match &result.module {
8893
ModuleResult::MultiModule(modules) => {
8994
anyhow::ensure!(!modules.is_empty(), "No shader modules were compiled");

0 commit comments

Comments
 (0)