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.

 
4
Kudos
 
4
Kudos

Now read this

Behind the scene: Syntax Highlighted Editor

Syntax highlighted editors is not a new concept in the world wide web. Few years ago, there are some famous names that dominating the world: FCKeditor in the early age, TinyEditor, nedit and ton of other WYSIWYG (What you see is what you... Continue →

Subscribe to The Full Snack Developer

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

S9LXLa7CrucYvIzThg7