Skip to main content

stamp_commit

Function stamp_commit 

Source
pub fn stamp_commit()
Expand description

Stamps the crate whose build script calls it with its commit, a dirty flag and a hash of its sources.

Sets HENAD_BUILD_COMMIT, HENAD_BUILD_COMMIT_DATE, HENAD_BUILD_DIRTY and HENAD_BUILD_SOURCE_HASH, and has Cargo rerun the script when any of them can change. henad::build_info! reads all four variables.

The commit comes from the package’s .cargo_vcs_info.json, as in a registry download, or else from git when git tracks the crate’s Cargo.toml. Otherwise the commit stays empty and the dirty flag unknown. The source hash is computed in every case, and tells two builds apart where no commit can: an uncommitted edit, or a project not under git. The dirty flag is unknown instead of clean when git does not track the lockfile, because no commit then records it.

A commit reruns the script once the crate sits in a git repository, even before git tracks the crate. A crate built before git init keeps an empty commit until a file under src or the manifest changes, or cargo clean -p <package> runs.

Note that the dirty flag and the source hash cover the files under src, the manifest and, outside a package, the nearest Cargo.lock. Dotfiles, editor backups and the .orig and .rej files that a merge or a patch leaves behind are excluded. A file a model reads at compile time, through include_bytes! or include_str!, belongs under src for the stamp to see it. A symlink to a directory is not followed. A shader that ShaderBuild compiles from a linked directory, or imports from outside src, changes neither the dirty flag nor the source hash. No stamp records data that a model reads from a path at run time.