git_submodule_versions!() { /* proc-macro */ }
Expand description

Get the git version of all submodules below the cargo project.

This macro expands to [(&str, &str), N] where N is the total number of submodules below the root of the project (evaluated recursively)

Each entry in the array is a tuple of the submodule path and the version information.

The following (named) arguments can be given:

  • args: The arguments to call git describe with. Default: args = ["--always", "--dirty=-modified"]

  • prefix, suffix: The git version for each submodule will be prefixed/suffixed by these strings.

  • fallback: If all else fails, this string will be given instead of reporting an error. This will yield the same type as if the macro was a success, but format will be [("relative/path/to/submodule", {fallback})]


const MODULE_VERSIONS: [(&str, &str); N] = git_submodule_versions!();
for (path, version) in MODULE_VERSIONS {
    println!("{path}: {version}");
const MODULE_VERSIONS: [(&str, &str); N] = git_submodule_versions!(args = ["--abbrev=40", "--always"]);
const MODULE_VERSIONS: [(&str, &str); N] = git_submodule_versions!(prefix = "git:", fallback = "unknown");