20

Working through Rust's Getting Started page on macOS, I ran the following command for Cargo to generate a project:

cargo new hello_world --bin

When I inspected the Cargo.toml file, it contained my real name as well as my email address.

From where is Cargo getting my name and email? How can I configure the name and email address Cargo uses?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
ross
  • 526
  • 5
  • 19

1 Answers1

20

Cargo uses your git configuration, among other environment variables.

To override it, you should be able to set the CARGO_EMAIL and CARGO_NAME environment variables when running cargo. E.g:

CARGO_NAME=not-ross cargo new --bin project_name

For example:

simon /c/rust
$ CARGO_NAME=Not-Simon CARGO_EMAIL=not_simon@not_simon.com cargo new --bin override-author
     Created binary (application) `override-author` project

simon /c/rust
$ cd !$

simon /c/rust/override-author (master)
$ cat Cargo.toml
[package]
name = "override-author"
version = "0.1.0"
authors = ["Not-Simon <not_simon@not_simon.com>"]

[dependencies]

Using CARGO_NAME and CARGO_EMAIL lets cargo figure out the author name and email at a higher "scope". Looking at the code in more detail, it will check git first but you can override it with the --vcs flag which will still use CARGO_NAME and CARGO_EMAIL if provided.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138