Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions node-graph/nodes/raster/shaders/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {

println!("cargo:rerun-if-env-changed=RUSTC_CODEGEN_SPIRV_PATH");
let rustc_codegen_spirv_path = std::env::var("RUSTC_CODEGEN_SPIRV_PATH").unwrap_or_default();

let cargo_build_target = std::env::var_os("CARGO_BUILD_TARGET");
unsafe {
// Unset `CARGO_BUILD_TARGET` to prevent `rustc_codegen_spirv` from picking it up and trying to build for the wrong target.
std::env::remove_var("CARGO_BUILD_TARGET");
Comment on lines +32 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The unsafe blocks for std::env::remove_var (lines 32-34) and std::env::set_var (lines 50-52) are used to manipulate environment variables. While unsafe is required on Windows for these operations due to potential thread-safety concerns, it's good practice to provide a clear // SAFETY: comment explaining why it's safe in this context, similar to the one on lines 21-23. This ensures that the justification for using unsafe is explicit and consistent throughout the file.

}

let backend = if rustc_codegen_spirv_path.is_empty() {
// install the toolchain and build the `rustc_codegen_spirv` codegen backend with it
cargo_gpu::Install::from_shader_crate(shader_crate.clone()).run()?
Expand All @@ -39,6 +46,13 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
backend
};

if let Some(value) = cargo_build_target {
unsafe {
// Set `CARGO_BUILD_TARGET` for the rest of the build
std::env::set_var("CARGO_BUILD_TARGET", value);
}
}

// build the shader crate
let mut builder = backend.to_spirv_builder(shader_crate, "spirv-unknown-naga-wgsl");
builder.print_metadata = MetadataPrintout::DependencyOnly;
Expand Down