diff --git a/crates/cargo-gpu/Cargo.toml b/crates/cargo-gpu/Cargo.toml index b05cd68..6000715 100644 --- a/crates/cargo-gpu/Cargo.toml +++ b/crates/cargo-gpu/Cargo.toml @@ -6,6 +6,7 @@ description = "Generates shader .spv files from rust-gpu shader crates" repository = "https://github.com/Rust-GPU/cargo-gpu" readme = "../../README.md" keywords = ["gpu", "compiler"] +build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/crates/cargo-gpu/build.rs b/crates/cargo-gpu/build.rs new file mode 100644 index 0000000..31a3357 --- /dev/null +++ b/crates/cargo-gpu/build.rs @@ -0,0 +1,12 @@ +//! cargo-gpu build script. + +fn main() { + let git_hash = std::process::Command::new("git") + .args(["rev-parse", "HEAD"]) + .output() + .map_or_else( + |_| "unknown".to_owned(), + |output| String::from_utf8(output.stdout).unwrap_or_else(|_| "unknown".to_owned()), + ); + println!("cargo:rustc-env=GIT_HASH={git_hash}"); +} diff --git a/crates/cargo-gpu/src/show.rs b/crates/cargo-gpu/src/show.rs index 814c057..3fb8c72 100644 --- a/crates/cargo-gpu/src/show.rs +++ b/crates/cargo-gpu/src/show.rs @@ -17,6 +17,8 @@ pub enum Info { CacheDirectory, /// The source location of spirv-std SpirvSource(SpirvSourceDep), + /// The git commitsh of this cli tool. + Commitsh, } /// `cargo gpu show` @@ -48,6 +50,9 @@ impl Show { println!("{rust_gpu_source}\n"); } } + Info::Commitsh => { + println!("{}", std::env!("GIT_HASH")); + } } Ok(())