22#![ allow( clippy:: unwrap_used, reason = "this is basically a test" ) ]
33//! `cargo gpu build`, analogous to `cargo build`
44
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" ) ]
89use anyhow:: Context as _;
9- use spirv_builder:: { CompileResult , ModuleResult , SpirvBuilder } ;
10+ #[ cfg( feature = "watch" ) ]
11+ use spirv_builder:: { CompileResult , ModuleResult } ;
12+ #[ cfg( feature = "watch" ) ]
1013use 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 ;
1220
1321/// Args for just a build
1422#[ derive( Debug , Clone , serde:: Deserialize , serde:: Serialize ) ]
@@ -19,6 +27,7 @@ pub struct BuildArgs {
1927 pub output_dir : PathBuf ,
2028
2129 /// Watch the shader crate directory and automatically recompile on changes.
30+ #[ cfg( feature = "watch" ) ]
2231 #[ cfg_attr( feature = "clap" , clap( long, short, action) ) ]
2332 pub watch : bool ,
2433
@@ -37,6 +46,7 @@ impl Default for BuildArgs {
3746 fn default ( ) -> Self {
3847 Self {
3948 output_dir : PathBuf :: from ( "./" ) ,
49+ #[ cfg( feature = "watch" ) ]
4050 watch : false ,
4151 spirv_builder : SpirvBuilder :: default ( ) ,
4252 manifest_file : String :: from ( "manifest.json" ) ,
@@ -91,6 +101,7 @@ impl Build {
91101 std:: env:: current_dir( ) ?. display( )
92102 ) ;
93103
104+ #[ cfg( feature = "watch" ) ]
94105 if self . build . watch {
95106 let this = self . clone ( ) ;
96107 self . build
@@ -111,10 +122,12 @@ impl Build {
111122 let result = self . build . spirv_builder . build ( ) ?;
112123 self . parse_compilation_result ( & result) ?;
113124 }
125+
114126 Ok ( ( ) )
115127 }
116128
117129 /// Parses compilation result from `SpirvBuilder` and writes it out to a file
130+ #[ cfg( feature = "watch" ) ]
118131 fn parse_compilation_result ( & self , result : & CompileResult ) -> anyhow:: Result < ( ) > {
119132 let shaders = match & result. module {
120133 ModuleResult :: MultiModule ( modules) => {
0 commit comments