@@ -44,6 +44,8 @@ pub struct Install {
4444 pub rebuild_codegen : bool ,
4545
4646 /// Assume "yes" to "Install Rust toolchain: [y/n]" prompt.
47+ ///
48+ /// Defaults to `false` in cli, `true` in [`Default`]
4749 #[ clap( long, action) ]
4850 pub auto_install_rust_toolchain : bool ,
4951
@@ -77,6 +79,21 @@ pub struct Install {
7779 pub force_overwrite_lockfiles_v4_to_v3 : bool ,
7880}
7981
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+
8097/// Represents a functional backend installation, whether it was cached or just installed.
8198#[ derive( Clone , Debug ) ]
8299pub struct InstalledBackend {
@@ -89,6 +106,18 @@ pub struct InstalledBackend {
89106}
90107
91108impl 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+
92121 /// Configures the supplied [`SpirvBuilder`]. `SpirvBuilder.target` must be set and must not change after calling this function.
93122 pub fn configure_spirv_builder ( & self , builder : & mut SpirvBuilder ) -> anyhow:: Result < ( ) > {
94123 builder. rustc_codegen_spirv_location = Some ( self . rustc_codegen_spirv_location . clone ( ) ) ;
@@ -101,21 +130,6 @@ impl InstalledBackend {
101130 }
102131}
103132
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-
119133impl Install {
120134 /// Create the `rustc_codegen_spirv_dummy` crate that depends on `rustc_codegen_spirv`
121135 fn write_source_files ( source : & SpirvSource , checkout : & Path ) -> anyhow:: Result < ( ) > {
0 commit comments