@@ -44,6 +44,8 @@ pub struct Install {
44
44
pub rebuild_codegen : bool ,
45
45
46
46
/// Assume "yes" to "Install Rust toolchain: [y/n]" prompt.
47
+ ///
48
+ /// Defaults to `false` in cli, `true` in [`Default`]
47
49
#[ clap( long, action) ]
48
50
pub auto_install_rust_toolchain : bool ,
49
51
@@ -77,6 +79,21 @@ pub struct Install {
77
79
pub force_overwrite_lockfiles_v4_to_v3 : bool ,
78
80
}
79
81
82
+ impl Install {
83
+ /// Create a default install for a shader crate of some path
84
+ pub fn from_shader_crate ( shader_crate : PathBuf ) -> Self {
85
+ Self {
86
+ shader_crate,
87
+ spirv_builder_source : None ,
88
+ spirv_builder_version : None ,
89
+ rebuild_codegen : false ,
90
+ auto_install_rust_toolchain : true ,
91
+ clear_target : true ,
92
+ force_overwrite_lockfiles_v4_to_v3 : false ,
93
+ }
94
+ }
95
+ }
96
+
80
97
/// Represents a functional backend installation, whether it was cached or just installed.
81
98
#[ derive( Clone , Debug ) ]
82
99
pub struct InstalledBackend {
@@ -89,6 +106,18 @@ pub struct InstalledBackend {
89
106
}
90
107
91
108
impl InstalledBackend {
109
+ /// Creates a new `SpirvBuilder` configured to use this installed backend.
110
+ pub fn to_spirv_builder (
111
+ & self ,
112
+ path_to_crate : impl AsRef < Path > ,
113
+ target : impl Into < String > ,
114
+ ) -> SpirvBuilder {
115
+ let mut builder = SpirvBuilder :: new ( path_to_crate, target) ;
116
+ self . configure_spirv_builder ( & mut builder)
117
+ . expect ( "unreachable" ) ;
118
+ builder
119
+ }
120
+
92
121
/// Configures the supplied [`SpirvBuilder`]. `SpirvBuilder.target` must be set and must not change after calling this function.
93
122
pub fn configure_spirv_builder ( & self , builder : & mut SpirvBuilder ) -> anyhow:: Result < ( ) > {
94
123
builder. rustc_codegen_spirv_location = Some ( self . rustc_codegen_spirv_location . clone ( ) ) ;
@@ -101,21 +130,6 @@ impl InstalledBackend {
101
130
}
102
131
}
103
132
104
- impl Default for Install {
105
- #[ inline]
106
- fn default ( ) -> Self {
107
- Self {
108
- shader_crate : PathBuf :: from ( "./" ) ,
109
- spirv_builder_source : None ,
110
- spirv_builder_version : None ,
111
- rebuild_codegen : false ,
112
- auto_install_rust_toolchain : false ,
113
- clear_target : true ,
114
- force_overwrite_lockfiles_v4_to_v3 : false ,
115
- }
116
- }
117
- }
118
-
119
133
impl Install {
120
134
/// Create the `rustc_codegen_spirv_dummy` crate that depends on `rustc_codegen_spirv`
121
135
fn write_source_files ( source : & SpirvSource , checkout : & Path ) -> anyhow:: Result < ( ) > {
0 commit comments