Multiple binaries in a Rust project

If you have a project that needs to compile into multiple binaries or libraries, you can config it in Cargo.toml like this:

...

[[lib]]
name = "<your-lib-name>"
src = "<path-to-source>"

[[bin]]
name = "<your-binary-name>"
src = "<path-to-source>"

...

For example, I am working on a 6502 emulator, and I need to build some tool along with my emulator, so this is my Cargo.toml:

...

[[bin]]
name = "romgen"
src = "src/romgen.rs"

[[bin]]
name = "emulator"
src = "src/main.rs"

Please note that after config the Cargo.toml to build multiple binaries, you need to specify the binary name everytime you run the project with cargo run:

cargo run --bin <binary-name>

But it’s annoying, it would be great if we could have a default binary that will execute every time we use cargo run. There is also an issue created for this.

 
7
Kudos
 
7
Kudos

Now read this

Recursive type problem in Rust

After spending much time reading about Rust, I decided to give it a try. It was a very simple implementation of Binary Tree Traversal algorithm. Surprisingly, by doing it, I learned a lot of Rust’s basic concepts! Rust tell us what’s... Continue →

Subscribe to The Full Snack Developer

Don’t worry; we hate spam with a passion.
You can unsubscribe with one click.

S9LXLa7CrucYvIzThg7