Cargo build dependencies in release mode

My project has grown very large and compiles faster in debug mode, so I want to do that. But startup and running is unnacceptably slow because of the runtime checks. Can I runt cargo to make dependencies run in release mode and only the main crate in debug mode? It seems to be all or nothing. What I am doing at the moment is using FFI to link directly to the shared library without compiling but I don't really want to do that.

Steve

Unfortunately you can't. Relevant issue: Add an option to optimize just dependencies · Issue #1359 · rust-lang/cargo · GitHub

Update from 2024: this is possible, and this comment at the end of the github issue referenced above points out that the "profile overrides" feature makes this possible. Its documentation is located at Profiles - The Cargo Book.

1 Like