Skip to content

Commit bb3acbf

Browse files
timon-schellingFirestar99
authored andcommitted
nix: use rustc_codegen_spirv.so from nix
1 parent 46e60c5 commit bb3acbf

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

node-graph/graster-nodes/shaders/build.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use cargo_gpu::InstalledBackend;
12
use cargo_gpu::spirv_builder::{MetadataPrintout, SpirvMetadata};
23
use std::path::PathBuf;
34

@@ -6,8 +7,29 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
67

78
let shader_crate = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/.."));
89

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+
};
1133

1234
// build the shader crate
1335
let mut builder = backend.to_spirv_builder(shader_crate, "spirv-unknown-naga-wgsl");
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"allows-weak-linkage": false,
3+
"arch": "spirv",
4+
"crt-objects-fallback": "false",
5+
"crt-static-allows-dylibs": true,
6+
"crt-static-respected": true,
7+
"data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64",
8+
"dll-prefix": "",
9+
"dll-suffix": ".spv.json",
10+
"dynamic-linking": true,
11+
"emit-debug-gdb-scripts": false,
12+
"env": "naga-wgsl",
13+
"linker-flavor": "unix",
14+
"linker-is-gnu": false,
15+
"llvm-target": "spirv-unknown-naga-wgsl",
16+
"main-needs-argc-argv": false,
17+
"metadata": {
18+
"description": null,
19+
"host_tools": null,
20+
"std": null,
21+
"tier": null
22+
},
23+
"panic-strategy": "abort",
24+
"simd-types-indirect": false,
25+
"target-pointer-width": "32"
26+
}

0 commit comments

Comments
 (0)