gpufft 0.1.3

Unified GPU-accelerated FFT for Rust: Vulkan via VkFFT, CUDA via cuFFT.
//! Build script for the `gpufft` crate.
//!
//! Compiles the Vulkan compute shaders under `shaders/` to SPIR-V via
//! `glslangValidator` when the `vulkan` feature is enabled, and writes
//! the binaries into `OUT_DIR` so they can be `include_bytes!`'d by the
//! Vulkan backend.

use std::env;
use std::path::PathBuf;
use std::process::Command;

fn main() {
    println!("cargo:rerun-if-changed=build.rs");

    // Re-export the VkFFT bundle's OUT_DIR from gpufft-vulkan-sys so that
    // direct consumers of this crate (which typically do not depend on the
    // -sys crate directly) can bake an rpath into their bin targets. Cargo
    // only propagates `cargo:<key>=<val>` metadata to crates that directly
    // depend on the emitter; this crate stands in for that one-hop link.
    println!("cargo:rerun-if-env-changed=DEP_GPUFFT_VKFFT_BUNDLE_DIR");
    if let Ok(dir) = env::var("DEP_GPUFFT_VKFFT_BUNDLE_DIR") {
        println!("cargo:bundle_dir={dir}");
    }

    // Only compile shaders when the Vulkan backend is enabled; other
    // feature combinations do not need them.
    if env::var_os("CARGO_FEATURE_VULKAN").is_none() {
        return;
    }

    println!("cargo:rerun-if-changed=shaders/stride_copy.comp");

    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    let out_path = out_dir.join("stride_copy.spv");

    let status = Command::new("glslangValidator")
        .args(["-V", "--target-env", "vulkan1.2"])
        .arg("shaders/stride_copy.comp")
        .arg("-o")
        .arg(&out_path)
        .status()
        .expect(
            "failed to run glslangValidator. Install `glslang-devel` \
             (Fedora) or `glslang-dev` (Debian/Ubuntu), or install the \
             LunarG Vulkan SDK.",
        );
    assert!(
        status.success(),
        "glslangValidator failed to compile stride_copy.comp"
    );
}