Publish two binaries from same code?

Hi all,

Sorry if this is a silly question.

I have a project (this one) which produces two binaries, a client and server. They currently build from one Cargo.toml and share some code in the form of a lib.rs.

I would like to publish both the client and server to crates.io so that a single cargo install my-thing will install both binaries.

Do I just add a

[[bin]]
name = "my-cool-binary"
path = "src/my-cool-binary.rs"

for each of the binaries?

1 Like

You don't need to make any changes; just publish your project as-is. cargo install always installs all binaries from a package. (Well, you might want to change the binary names from client and server to something less generic. :slight_smile:)

If you want to test the cargo install behavior before publishing, you can use cargo install --path . in a local clone of the project, or cargo install --git https://github.com/mark-i-m/jobserver.

1 Like

Thanks for the response! That's much simpler than I expected :rocket:

One followup: currently, the binaries are named client.rs and server.rs. Would I add the [[bin]] sections if I want them to be named something else? Or would it just be easier to just rename the files?

Both approaches are valid. Personally, I like to use the source filenames to control the binary names, just so I don't have to remember what files map to which names.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.