Skip to content

Commit 7847b46

Browse files
committed
Implement env var hack to work around potentially suboptimal cargo behaviour
1 parent 1e07afc commit 7847b46

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
name = "rust-gpu-builder"
33
version = "0.4.0"
44
edition = "2021"
5-
build = false
65

76
[dependencies]
87
rust-gpu-builder-shared = { git = "https://github.com/bevy-rust-gpu/rust-gpu-builder-shared" }

build.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use std::{env, error::Error};
2+
3+
fn main() -> Result<(), Box<dyn Error>> {
4+
println!("cargo:rerun-if-changed=build.rs");
5+
println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_OS");
6+
println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH");
7+
// While OUT_DIR is set for both build.rs and compiling the crate, PROFILE is only set in
8+
// build.rs. So, export it to crate compilation as well.
9+
let profile = env::var("PROFILE").unwrap();
10+
println!("cargo:rustc-env=PROFILE={profile}");
11+
Ok(())
12+
}

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ impl ShaderBuilder {
104104

105105
/// Builds a shader with the provided set of options.
106106
pub fn build_shader(&self) -> Result<CompileResult, SpirvBuilderError> {
107+
// As per `spirv-builder`, apply env vars set in build.rs
108+
// to work around potentially suboptimal cargo behaviour
109+
std::env::set_var("OUT_DIR", env!("OUT_DIR"));
110+
std::env::set_var("PROFILE", env!("PROFILE"));
111+
107112
let mut builder = SpirvBuilder::new(&self.path_to_crate, &self.target)
108113
.deny_warnings(self.deny_warnings)
109114
.release(self.release)

0 commit comments

Comments
 (0)