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 crate :: install:: Install ;
6
- use crate :: linkage:: Linkage ;
7
- use crate :: lockfile:: LockfileMismatchHandler ;
5
+ use spirv_builder:: SpirvBuilder ;
6
+ use std:: path:: PathBuf ;
7
+
8
+ #[ cfg( feature = "watch" ) ]
8
9
use anyhow:: Context as _;
9
- use spirv_builder:: { CompileResult , ModuleResult , SpirvBuilder } ;
10
+ #[ cfg( feature = "watch" ) ]
11
+ use spirv_builder:: { CompileResult , ModuleResult } ;
12
+ #[ cfg( feature = "watch" ) ]
10
13
use std:: io:: Write as _;
11
- use std:: path:: PathBuf ;
14
+
15
+ use crate :: install:: Install ;
16
+ use crate :: lockfile:: LockfileMismatchHandler ;
17
+
18
+ #[ cfg( feature = "watch" ) ]
19
+ use crate :: linkage:: Linkage ;
12
20
13
21
/// Args for just a build
14
22
#[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
@@ -19,6 +27,7 @@ pub struct BuildArgs {
19
27
pub output_dir : PathBuf ,
20
28
21
29
/// Watch the shader crate directory and automatically recompile on changes.
30
+ #[ cfg( feature = "watch" ) ]
22
31
#[ cfg_attr( feature = "clap" , clap( long, short, action) ) ]
23
32
pub watch : bool ,
24
33
@@ -37,6 +46,7 @@ impl Default for BuildArgs {
37
46
fn default ( ) -> Self {
38
47
Self {
39
48
output_dir : PathBuf :: from ( "./" ) ,
49
+ #[ cfg( feature = "watch" ) ]
40
50
watch : false ,
41
51
spirv_builder : SpirvBuilder :: default ( ) ,
42
52
manifest_file : String :: from ( "manifest.json" ) ,
@@ -91,6 +101,7 @@ impl Build {
91
101
std:: env:: current_dir( ) ?. display( )
92
102
) ;
93
103
104
+ #[ cfg( feature = "watch" ) ]
94
105
if self . build . watch {
95
106
let this = self . clone ( ) ;
96
107
self . build
@@ -111,10 +122,12 @@ impl Build {
111
122
let result = self . build . spirv_builder . build ( ) ?;
112
123
self . parse_compilation_result ( & result) ?;
113
124
}
125
+
114
126
Ok ( ( ) )
115
127
}
116
128
117
129
/// Parses compilation result from `SpirvBuilder` and writes it out to a file
130
+ #[ cfg( feature = "watch" ) ]
118
131
fn parse_compilation_result ( & self , result : & CompileResult ) -> anyhow:: Result < ( ) > {
119
132
let shaders = match & result. module {
120
133
ModuleResult :: MultiModule ( modules) => {
0 commit comments