Files
fdtd-coremem/crates/spirv_backend_runner/build.rs
colin 5b99d30cda restructure this multi-crate project to use Cargo's "workspace" feature
this solves an issue in the Nix build, where managing multiple
Cargo.lock files is otherwise tricky. it causes (or fails to fix?) an adjacent issue where
the spirv builder doesn't seem to have everything it needs vendored.
2022-07-05 17:34:21 -07:00

61 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)
.stderr(std::process::Stdio::inherit())
.stdout(std::process::Stdio::inherit())
.status()?;
if !status.success() {
if let Some(code) = status.code() {
std::process::exit(code);
} else {
std::process::exit(1);
}
}
Ok(())
}