Environment Variables

Cargo sets a number of environment variables which your code can detect. To get the value of any of these variables in a Rust program, do this:

let version = env!("CARGO_PKG_VERSION")

version will now contain the value of CARGO_PKG_VERSION.

Here are a list of the variables Cargo sets, organized by when it sets them:

Environment variables Cargo reads

Environment variables Cargo sets for build scripts

Environment variables Cargo sets for crates