@@ -94,46 +94,52 @@ impl Build {
94
94
std:: env:: current_dir( ) ?. display( )
95
95
) ;
96
96
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 ( )
98
106
}
99
107
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
+ }
112
118
119
+ /// Watches shader crate for changes using [`SpirvBuilder`]
120
+ /// or panics depending on presence of `watch` feature.
121
+ fn watch ( & self ) -> anyhow:: Result < ( ) > {
113
122
#[ cfg( feature = "watch" ) ]
114
- if self . build . watch {
123
+ {
115
124
let this = self . clone ( ) ;
116
125
self . build
117
126
. spirv_builder
118
127
. watch ( move |result, accept| {
119
- let result1 = this. parse_compilation_result ( & result) ;
128
+ let parse_result = this. parse_compilation_result ( & result) ;
120
129
if let Some ( accept) = accept {
121
- accept. submit ( result1 ) ;
130
+ accept. submit ( parse_result ) ;
122
131
}
123
132
} ) ?
124
133
. context ( "unreachable" ) ??;
125
134
std:: thread:: park ( ) ;
126
- } else {
127
- build ( ) ?;
135
+ Ok ( ( ) )
128
136
}
129
137
130
138
#[ cfg( not( feature = "watch" ) ) ]
131
- build ( ) ?;
132
-
133
- Ok ( ( ) )
139
+ unreachable ! ( "cannot watch without the `watch` feature" )
134
140
}
135
141
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
137
143
fn parse_compilation_result ( & self , result : & CompileResult ) -> anyhow:: Result < ( ) > {
138
144
let shaders = match & result. module {
139
145
ModuleResult :: MultiModule ( modules) => {
0 commit comments