@@ -12,7 +12,7 @@ use cargo_gpu_build::{
12
12
13
13
use crate :: { linkage:: Linkage , user_consent:: ask_for_user_consent} ;
14
14
15
- /// Args for just a build
15
+ /// Args for just a build.
16
16
#[ derive( Debug , Clone , clap:: Parser , serde:: Deserialize , serde:: Serialize ) ]
17
17
#[ non_exhaustive]
18
18
#[ expect( clippy:: module_name_repetitions, reason = "it is intended" ) ]
@@ -25,12 +25,12 @@ pub struct BuildArgs {
25
25
#[ clap( long, short, action) ]
26
26
pub watch : bool ,
27
27
28
- /// The flattened [`SpirvBuilder`]
28
+ /// The flattened [`SpirvBuilder`].
29
29
#[ clap( flatten) ]
30
30
#[ serde( flatten) ]
31
31
pub spirv_builder : SpirvBuilder ,
32
32
33
- /// Renames the manifest.json file to the given name
33
+ /// Renames the manifest.json file to the given name.
34
34
#[ clap( long, short, default_value = "manifest.json" ) ]
35
35
pub manifest_file : String ,
36
36
}
@@ -47,15 +47,29 @@ impl Default for BuildArgs {
47
47
}
48
48
}
49
49
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
+
50
64
/// `cargo build` subcommands
51
65
#[ derive( Clone , Debug , clap:: Parser , serde:: Deserialize , serde:: Serialize ) ]
52
66
#[ non_exhaustive]
53
67
pub struct Build {
54
- /// CLI args for install the `rust-gpu` compiler and components
68
+ /// CLI args for install the `rust-gpu` compiler and components.
55
69
#[ clap( flatten) ]
56
- pub install : Install ,
70
+ pub install : InstallArgs ,
57
71
58
- /// CLI args for configuring the build of the shader
72
+ /// CLI args for configuring the build of the shader.
59
73
#[ clap( flatten) ]
60
74
pub build : BuildArgs ,
61
75
}
@@ -68,15 +82,15 @@ impl Build {
68
82
/// Returns an error if the build process fails somehow.
69
83
#[ inline]
70
84
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 ( ) ) ;
72
86
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 ) ;
74
88
let crate_builder_params = ShaderCrateBuilderParams :: from ( self . build . spirv_builder . clone ( ) )
75
- . install ( self . install . params . clone ( ) )
89
+ . install ( self . install . backend . params . clone ( ) )
76
90
. halt ( halt) ;
77
91
let crate_builder = ShaderCrateBuilder :: new ( crate_builder_params) ?;
78
92
79
- self . install = crate_builder. installed_backend_args . clone ( ) ;
93
+ self . install . backend = crate_builder. installed_backend_args . clone ( ) ;
80
94
self . build . spirv_builder = crate_builder. builder . clone ( ) ;
81
95
82
96
// Ensure the shader output dir exists
@@ -130,7 +144,7 @@ impl Build {
130
144
}
131
145
}
132
146
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.
134
148
fn parse_compilation_result ( & self , result : & CompileResult ) -> anyhow:: Result < ( ) > {
135
149
let shaders = match & result. module {
136
150
ModuleResult :: MultiModule ( modules) => {
@@ -157,10 +171,10 @@ impl Build {
157
171
log:: debug!(
158
172
"linkage of {} relative to {}" ,
159
173
path. display( ) ,
160
- self . install. shader_crate. display( )
174
+ self . install. backend . shader_crate. display( )
161
175
) ;
162
176
let spv_path = path
163
- . relative_to ( & self . install . shader_crate )
177
+ . relative_to ( & self . install . backend . shader_crate )
164
178
. map_or ( path, |path_relative_to_shader_crate| {
165
179
path_relative_to_shader_crate. to_path ( "" )
166
180
} ) ;
@@ -216,7 +230,7 @@ mod test {
216
230
command : Command :: Build ( build) ,
217
231
} = Cli :: parse_from ( args)
218
232
{
219
- assert_eq ! ( shader_crate_path, build. install. shader_crate) ;
233
+ assert_eq ! ( shader_crate_path, build. install. backend . shader_crate) ;
220
234
assert_eq ! ( output_dir, build. build. output_dir) ;
221
235
222
236
// TODO:
0 commit comments