Setting --release as the default profile

How can I set --release as the default profile for my crate, so I can just type cargo build instead of cargo build --release?

(When I build my program with the --debug profile, it fails to build because it is too large to fit in the flash of the board I'm using. This is why I want cargo build to build the release version.)


You can't, but you can make debug profile behave exactly like the release profile.

1 Like

Is there a way to find out exactly what settings the release profile uses? The Cargo Book shows the defaults for the release profile, but I'm pretty sure some of those are different for embedded development. (e. g. I'm pretty sure embedded targets are using panic = 'abort' rather than panic = 'unwind', and I thought somewhere I saw that embedded targets used opt-level = 's', rather than opt-level = 3. But I'd like to know for sure, rather than guessing.)

You can see which options Cargo passes to rustc by adding -v to your Cargo flags. I don't think Cargo's behavior changes by target; for example, it looks like it always passes -C opt-level=3 by default in the release profile.

However, you are correct that rustc uses panic=abort by default for some targets when no panic strategy is explicitly specified.

1 Like