1
+ use cargo_gpu:: InstalledBackend ;
1
2
use cargo_gpu:: spirv_builder:: { MetadataPrintout , SpirvMetadata } ;
2
3
use std:: path:: PathBuf ;
3
4
@@ -6,8 +7,29 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
6
7
7
8
let shader_crate = PathBuf :: from ( concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/.." ) ) ;
8
9
9
- // install the toolchain and build the `rustc_codegen_spirv` codegen backend with it
10
- let backend = cargo_gpu:: Install :: from_shader_crate ( shader_crate. clone ( ) ) . run ( ) ?;
10
+ // Allows overriding the PATH to inject the rust-gpu rust toolchain when building the rest of the project with stable rustc.
11
+ // Used in nix shell. Do not remove without checking with developers using nix.
12
+ if let Ok ( path_override) = std:: env:: var ( "RUST_GPU_PATH_OVERRIDE" ) {
13
+ let current_path = std:: env:: var ( "PATH" ) . unwrap_or_default ( ) ;
14
+ let new_path = format ! ( "{path_override}:{current_path}" ) ;
15
+ // SAFETY: Build script is single-threaded therefore this cannot lead to undefined behavior.
16
+ unsafe {
17
+ std:: env:: set_var ( "PATH" , & new_path) ;
18
+ }
19
+ }
20
+
21
+ let rustc_codegen_spirv_path = std:: env:: var ( "RUSTC_CODEGEN_SPIRV_PATH" ) . unwrap_or_default ( ) ;
22
+ let backend = if rustc_codegen_spirv_path. is_empty ( ) {
23
+ // install the toolchain and build the `rustc_codegen_spirv` codegen backend with it
24
+ cargo_gpu:: Install :: from_shader_crate ( shader_crate. clone ( ) ) . run ( ) ?
25
+ } else {
26
+ // use the `RUSTC_CODEGEN_SPIRV` environment variable to find the codegen backend
27
+ let mut backend = InstalledBackend :: default ( ) ;
28
+ backend. rustc_codegen_spirv_location = PathBuf :: from ( rustc_codegen_spirv_path) ;
29
+ backend. toolchain_channel = "nightly" . to_string ( ) ;
30
+ backend. target_spec_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
31
+ backend
32
+ } ;
11
33
12
34
// build the shader crate
13
35
let mut builder = backend. to_spirv_builder ( shader_crate, "spirv-unknown-naga-wgsl" ) ;
0 commit comments