Files
fdtd-coremem/crates/spirv_backend_runner/build.rs
2022-07-05 23:01:41 -07:00

62 lines
2.0 KiB
Rust

use std::env;
use std::error::Error;
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn Error>> {
// heavily inspired from EmbarkStudios/rust-gpu/examples/runners/wgpu/build.rs
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_OS");
println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH");
// While OUT_DIR is set for both build.rs and compiling the crate, PROFILE is only set in
// build.rs. So, export it to crate compilation as well.
let profile = env::var("PROFILE").unwrap();
println!("cargo:rustc-env=PROFILE={}", profile);
let mut dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("OUT_DIR: {:?}", dir);
// recover the directory from which this was invoked
while !dir.ends_with("target") {
dir.pop();
}
assert!(dir.pop());
if dir.ends_with("spirv_backend_runner") {
// being run from this dir
assert!(
dir.pop()
&& dir.ends_with("spirv")
&& dir.pop()
&& dir.ends_with("sim")
&& dir.pop()
&& dir.ends_with("src")
&& dir.pop()
);
} // else already at the top-level dir
let target_dir = dir.join("target/spirv_backend_builder");
let manifest_path = dir.join("crates/spirv_backend_builder/Cargo.toml");
println!("target_dir: {:?}", target_dir);
println!("manifest_path: {:?}", manifest_path);
let status = std::process::Command::new("cargo")
.args([
"run",
"--release",
"--manifest-path",
])
.arg(manifest_path)
.arg("--target-dir")
.arg(target_dir)
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.status()?;
if !status.success() {
if let Some(code) = status.code() {
std::process::exit(code);
} else {
std::process::exit(1);
}
}
Ok(())
}