33#![ allow( clippy:: shadow_reuse, reason = "let's not be silly" ) ]
44#![ allow( clippy:: unwrap_used, reason = "this is basically a test" ) ]
55
6- use std:: io:: { self , Write as _} ;
7- use std:: path:: PathBuf ;
6+ use core:: convert:: Infallible ;
7+ use std:: {
8+ io:: { self , Write as _} ,
9+ panic,
10+ path:: PathBuf ,
11+ } ;
812
913use anyhow:: Context as _;
1014use cargo_gpu_build:: lockfile:: LockfileMismatchHandler ;
1115use rustc_codegen_spirv_cache:: install:: Install ;
12- use spirv_builder:: { CompileResult , ModuleResult , SpirvBuilder } ;
16+ use spirv_builder:: { CompileResult , ModuleResult , SpirvBuilder , Watch } ;
1317
1418use crate :: { linkage:: Linkage , user_consent:: ask_for_user_consent} ;
1519
@@ -103,7 +107,8 @@ impl Build {
103107 ) ;
104108
105109 if self . build . watch {
106- return self . watch ( ) ;
110+ let never = self . watch ( ) ?;
111+ match never { }
107112 }
108113 self . build ( )
109114 }
@@ -119,21 +124,27 @@ impl Build {
119124 Ok ( ( ) )
120125 }
121126
122- /// Watches shader crate for changes using [`SpirvBuilder`]
123- /// or returns an error depending on presence of `watch` feature.
124- fn watch ( & self ) -> anyhow:: Result < ( ) > {
127+ /// Watches shader crate for changes using [`SpirvBuilder`].
128+ fn watch ( & self ) -> anyhow:: Result < Infallible > {
125129 let this = self . clone ( ) ;
126- self . build
127- . spirv_builder
128- . watch ( move |result, accept| {
129- let parse_result = this. parse_compilation_result ( & result) ;
130- if let Some ( accept) = accept {
131- accept. submit ( parse_result) ;
132- }
133- } ) ?
130+ let Watch {
131+ first_compile,
132+ watch_thread,
133+ ..
134+ } = self . build . spirv_builder . watch ( move |result, accept| {
135+ let parse_result = this. parse_compilation_result ( & result) ;
136+ if let Some ( accept) = accept {
137+ accept. submit ( parse_result) ;
138+ }
139+ } ) ?;
140+
141+ first_compile
134142 . context ( "should always return the first compile result" )
135143 . flatten ( ) ?;
136- anyhow:: bail!( "unexpected end of watch" )
144+ watch_thread. join ( ) . map_err ( |payload| {
145+ log:: error!( "watch thread panicked" ) ;
146+ panic:: resume_unwind ( payload)
147+ } )
137148 }
138149
139150 /// Parses compilation result from [`SpirvBuilder`] and writes it out to a file
0 commit comments