Rename the default Cargo binary to be different than the package name

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

In ./target/debug/ we can see the binary name: digital-garden-steps. This is the name of our package and we want the actual binary that users install to be named garden instead.

To do this we can change the auto-discovered src/main.rs binary and change the name using a bin config in the Cargo.toml file.

[[bin]]
name = "garden"
path = "src/main.rs"

Then we see ./target/debug/garden get created when we cargo run or cargo build.

Chris Biscardi: [0:00] After running cargo run, we can see the path as target/debug/digital_garden. That means the name of our binary is digital_garden, which is the same name as the package. If we bring up in Cargo.toml, we can confirm that.

[0:14] We can change the name of the binary by using a bin field. Note that because Cargo packages can have multiple binaries, this is an array. We'll rename the binary to garden and specify the path as being src/main.rs. We could change the path, but it is conventional to have the default binary be src/main, while the default library is src/lib.

[0:39] Now we could see that we run target/debug/garden when we run cargo run. If we look in target/debug, we can see a binary called digital_garden and a binary called garden. This is because digital_garden is left over from the first build, when the binary was still named digital_garden, while garden is the new binary name.

egghead
egghead
~ just now

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today