2
2
#![ allow( clippy:: unwrap_used, reason = "this is basically a test" ) ]
3
3
//! `cargo gpu build`, analogous to `cargo build`
4
4
5
- use spirv_builder:: SpirvBuilder ;
6
- use std:: path:: PathBuf ;
7
-
8
- #[ cfg( feature = "watch" ) ]
9
5
use anyhow:: Context as _;
10
- #[ cfg( feature = "watch" ) ]
11
- use spirv_builder:: { CompileResult , ModuleResult } ;
12
- #[ cfg( feature = "watch" ) ]
6
+ use spirv_builder:: { CompileResult , ModuleResult , SpirvBuilder } ;
13
7
use std:: io:: Write as _;
8
+ use std:: path:: PathBuf ;
14
9
15
10
use crate :: install:: Install ;
16
- use crate :: lockfile:: LockfileMismatchHandler ;
17
-
18
- #[ cfg( feature = "watch" ) ]
19
11
use crate :: linkage:: Linkage ;
12
+ use crate :: lockfile:: LockfileMismatchHandler ;
20
13
21
14
/// Args for just a build
22
15
#[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
@@ -101,6 +94,22 @@ impl Build {
101
94
std:: env:: current_dir( ) ?. display( )
102
95
) ;
103
96
97
+ self . build_or_watch ( )
98
+ }
99
+
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
+ } ;
112
+
104
113
#[ cfg( feature = "watch" ) ]
105
114
if self . build . watch {
106
115
let this = self . clone ( ) ;
@@ -115,19 +124,16 @@ impl Build {
115
124
. context ( "unreachable" ) ??;
116
125
std:: thread:: park ( ) ;
117
126
} else {
118
- crate :: user_output!(
119
- "Compiling shaders at {}...\n " ,
120
- self . install. shader_crate. display( )
121
- ) ;
122
- let result = self . build . spirv_builder . build ( ) ?;
123
- self . parse_compilation_result ( & result) ?;
127
+ build ( ) ?;
124
128
}
125
129
130
+ #[ cfg( not( feature = "watch" ) ) ]
131
+ build ( ) ?;
132
+
126
133
Ok ( ( ) )
127
134
}
128
135
129
136
/// Parses compilation result from `SpirvBuilder` and writes it out to a file
130
- #[ cfg( feature = "watch" ) ]
131
137
fn parse_compilation_result ( & self , result : & CompileResult ) -> anyhow:: Result < ( ) > {
132
138
let shaders = match & result. module {
133
139
ModuleResult :: MultiModule ( modules) => {
0 commit comments