@@ -12,7 +12,7 @@ use cargo_gpu_build::{
1212
1313use crate :: { linkage:: Linkage , user_consent:: ask_for_user_consent} ;
1414
15- /// Args for just a build
15+ /// Args for just a build.
1616#[ derive( Debug , Clone , clap:: Parser , serde:: Deserialize , serde:: Serialize ) ]
1717#[ non_exhaustive]
1818#[ expect( clippy:: module_name_repetitions, reason = "it is intended" ) ]
@@ -25,12 +25,12 @@ pub struct BuildArgs {
2525 #[ clap( long, short, action) ]
2626 pub watch : bool ,
2727
28- /// The flattened [`SpirvBuilder`]
28+ /// The flattened [`SpirvBuilder`].
2929 #[ clap( flatten) ]
3030 #[ serde( flatten) ]
3131 pub spirv_builder : SpirvBuilder ,
3232
33- /// Renames the manifest.json file to the given name
33+ /// Renames the manifest.json file to the given name.
3434 #[ clap( long, short, default_value = "manifest.json" ) ]
3535 pub manifest_file : String ,
3636}
@@ -47,15 +47,29 @@ impl Default for BuildArgs {
4747 }
4848}
4949
50+ /// Args for just an install.
51+ #[ derive( Clone , Debug , clap:: Parser , serde:: Deserialize , serde:: Serialize ) ]
52+ #[ non_exhaustive]
53+ pub struct InstallArgs {
54+ /// The flattened [`Install`].
55+ #[ clap( flatten) ]
56+ #[ serde( flatten) ]
57+ pub backend : Install ,
58+
59+ /// Assume "yes" to "Install Rust toolchain: [y/n]" prompt.
60+ #[ clap( long, action) ]
61+ pub auto_install_rust_toolchain : bool ,
62+ }
63+
5064/// `cargo build` subcommands
5165#[ derive( Clone , Debug , clap:: Parser , serde:: Deserialize , serde:: Serialize ) ]
5266#[ non_exhaustive]
5367pub struct Build {
54- /// CLI args for install the `rust-gpu` compiler and components
68+ /// CLI args for install the `rust-gpu` compiler and components.
5569 #[ clap( flatten) ]
56- pub install : Install ,
70+ pub install : InstallArgs ,
5771
58- /// CLI args for configuring the build of the shader
72+ /// CLI args for configuring the build of the shader.
5973 #[ clap( flatten) ]
6074 pub build : BuildArgs ,
6175}
@@ -68,15 +82,15 @@ impl Build {
6882 /// Returns an error if the build process fails somehow.
6983 #[ inline]
7084 pub fn run ( & mut self ) -> anyhow:: Result < ( ) > {
71- self . build . spirv_builder . path_to_crate = Some ( self . install . shader_crate . clone ( ) ) ;
85+ self . build . spirv_builder . path_to_crate = Some ( self . install . backend . shader_crate . clone ( ) ) ;
7286
73- let halt = ask_for_user_consent ( self . install . params . auto_install_rust_toolchain ) ;
87+ let halt = ask_for_user_consent ( self . install . auto_install_rust_toolchain ) ;
7488 let crate_builder_params = ShaderCrateBuilderParams :: from ( self . build . spirv_builder . clone ( ) )
75- . install ( self . install . params . clone ( ) )
89+ . install ( self . install . backend . params . clone ( ) )
7690 . halt ( halt) ;
7791 let crate_builder = ShaderCrateBuilder :: new ( crate_builder_params) ?;
7892
79- self . install = crate_builder. installed_backend_args . clone ( ) ;
93+ self . install . backend = crate_builder. installed_backend_args . clone ( ) ;
8094 self . build . spirv_builder = crate_builder. builder . clone ( ) ;
8195
8296 // Ensure the shader output dir exists
@@ -130,7 +144,7 @@ impl Build {
130144 }
131145 }
132146
133- /// Parses compilation result from [`SpirvBuilder`] and writes it out to a file
147+ /// Parses compilation result from [`SpirvBuilder`] and writes it out to a file.
134148 fn parse_compilation_result ( & self , result : & CompileResult ) -> anyhow:: Result < ( ) > {
135149 let shaders = match & result. module {
136150 ModuleResult :: MultiModule ( modules) => {
@@ -157,10 +171,10 @@ impl Build {
157171 log:: debug!(
158172 "linkage of {} relative to {}" ,
159173 path. display( ) ,
160- self . install. shader_crate. display( )
174+ self . install. backend . shader_crate. display( )
161175 ) ;
162176 let spv_path = path
163- . relative_to ( & self . install . shader_crate )
177+ . relative_to ( & self . install . backend . shader_crate )
164178 . map_or ( path, |path_relative_to_shader_crate| {
165179 path_relative_to_shader_crate. to_path ( "" )
166180 } ) ;
@@ -216,7 +230,7 @@ mod test {
216230 command : Command :: Build ( build) ,
217231 } = Cli :: parse_from ( args)
218232 {
219- assert_eq ! ( shader_crate_path, build. install. shader_crate) ;
233+ assert_eq ! ( shader_crate_path, build. install. backend . shader_crate) ;
220234 assert_eq ! ( output_dir, build. build. output_dir) ;
221235
222236 // TODO:
0 commit comments