How to compile some dependencies with release

Viewed 1530

I'd like to build my rust app with "dev" profile, but some of the dependencies with "release" profile (because otherwise they are really slow). How can I selectively specify profiles for my crate dependencies?

1 Answers

Cargo is able to override profile for a specific package.

From the reference :

Profile settings can be overridden for specific packages and build-time crates. To override the settings for a specific package, use the package table to change the settings for the named package:

# The `foo` package will use the -Copt-level=3 flag.
[profile.dev.package.foo]
opt-level = 3

While compiling with dev profile, this will override optimize level for foo package.


  • If you want to optimize few dependency with a default value from dev profile and more from a release profile:
#override target package to build with dev default(opt-level) 
[profile.dev.package.bar]
opt-level = 0 

#override all other dependencies to build with release default(opt-level) 
[profile.dev.package."*"]
opt-level = 3

  • If you want to optimize all of your dependencies except your application(also workspace members)
[profile.dev.package."*"]
opt-level = 3

See also :

Related