How to publish an optimized binary using cargo publish?

Viewed 604

I am trying to publish my first crate to crates.io.

When I build my project locally, I can pass the --release flag to get an optimized binary but when I do cargo publish --dry-run it seems to be building an unoptimized binary as this was the second-to-last line of the output:

Finished dev [unoptimized + debuginfo] target(s) in 24.79s

If possible, I would like to build and publish an optimized binary to crates.io.

1 Answers

You publish source code to crates.io. When a user runs cargo install <my-crate>, it downloads the source and compiles it with --release. You don't have to do anything.

Related