@@ -94,46 +94,52 @@ impl Build {
9494 std:: env:: current_dir( ) ?. display( )
9595 ) ;
9696
97- self . build_or_watch ( )
97+ #[ cfg( feature = "watch" ) ]
98+ let watching = self . build . watch ;
99+ #[ cfg( not( feature = "watch" ) ) ]
100+ let watching = false ;
101+ if watching {
102+ return self . watch ( ) ;
103+ }
104+
105+ self . build ( )
98106 }
99107
100- /// Builds shader crate locally or watches it for changes
101- /// depending on presence of `watch` feature and `BuildArgs::watch` flag.
102- fn build_or_watch ( & self ) -> anyhow:: Result < ( ) > {
103- let build = || -> anyhow:: Result < ( ) > {
104- crate :: user_output!(
105- "Compiling shaders at {}...\n " ,
106- self . install. shader_crate. display( )
107- ) ;
108- let result = self . build . spirv_builder . build ( ) ?;
109- self . parse_compilation_result ( & result) ?;
110- Ok ( ( ) )
111- } ;
108+ /// Builds shader crate locally using [`SpirvBuilder`].
109+ fn build ( & self ) -> anyhow:: Result < ( ) > {
110+ crate :: user_output!(
111+ "Compiling shaders at {}...\n " ,
112+ self . install. shader_crate. display( )
113+ ) ;
114+ let result = self . build . spirv_builder . build ( ) ?;
115+ self . parse_compilation_result ( & result) ?;
116+ Ok ( ( ) )
117+ }
112118
119+ /// Watches shader crate for changes using [`SpirvBuilder`]
120+ /// or panics depending on presence of `watch` feature.
121+ fn watch ( & self ) -> anyhow:: Result < ( ) > {
113122 #[ cfg( feature = "watch" ) ]
114- if self . build . watch {
123+ {
115124 let this = self . clone ( ) ;
116125 self . build
117126 . spirv_builder
118127 . watch ( move |result, accept| {
119- let result1 = this. parse_compilation_result ( & result) ;
128+ let parse_result = this. parse_compilation_result ( & result) ;
120129 if let Some ( accept) = accept {
121- accept. submit ( result1 ) ;
130+ accept. submit ( parse_result ) ;
122131 }
123132 } ) ?
124133 . context ( "unreachable" ) ??;
125134 std:: thread:: park ( ) ;
126- } else {
127- build ( ) ?;
135+ Ok ( ( ) )
128136 }
129137
130138 #[ cfg( not( feature = "watch" ) ) ]
131- build ( ) ?;
132-
133- Ok ( ( ) )
139+ unreachable ! ( "cannot watch without the `watch` feature" )
134140 }
135141
136- /// Parses compilation result from `SpirvBuilder` and writes it out to a file
142+ /// Parses compilation result from [ `SpirvBuilder`] and writes it out to a file
137143 fn parse_compilation_result ( & self , result : & CompileResult ) -> anyhow:: Result < ( ) > {
138144 let shaders = match & result. module {
139145 ModuleResult :: MultiModule ( modules) => {
0 commit comments