Multi bin project?

I'm working on a small project that needs to do HTTP GET queries to fetch some data. When developing I'd like to have a locally running HTTP serving predefined static files to avoid hitting the network.

I thought about having two [[bin]] sections in my Cargo.toml; one for the main app, one for the companion HTTP server. Those two binaries would have two different sets of dependencies but it seems that it's not possible at the moment.

I could use a separate HTTP server to serve the files but I would prefer to have everything at one place packaged with Cargo.

How do you usually manage such kind of setup?

2 Likes

Either by using Cargo's built-in src/bin stuff, or workspaces. I don't do [[bin]] sections unless I absolutely have to.

For a project that's not a library on crates.io, I don't worry about the dependency stuff; if you're not using extern crate it's gonna get compiled out anyway, and it's only a one-time build, and you do need them all for both.

2 Likes

Oh cool, I somehow missed that rust files in src/bin do not need to be declared in the Cargo.toml but are immediately available.

Thanks!

2 Likes

What are you referring to?

This I guess.

3 Likes

Exactly.