I would like to separate some performance intensive code into a .so (I am running Kubuntu Linux) while the main quantity of my code is compiled in debug mode. I want the faster compiles and run time support in my code, but it's unacceptable to run the small amount of intensive code with all the debug checks in it.
Is it possible to do this using Cargo? It seems that Cargo propagates the top level profile to the dependencies, so they are all compiled as release or debug, depending on what is requested of the main crate.
This is possible as of Rust 1.41 via overrides:
[package]
name = "speedy"
version = "0.1.0"
authors = ["An Devloper <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
image = "0.21.1"
# All dependencies (but not this crate itself or any workspace member)
# will be compiled with -Copt-level=2 . This includes build dependencies.
[profile.dev.package."*"]
opt-level = 2
The output with some details elided:
$ cargo build --verbose
Compiling image v0.23.0
Running `rustc [...] --crate-name image [...] -C opt-level=2 -C debuginfo=2 -C debug-assertions=on [...]`
Compiling speedy v0.1.0 (/private/tmp/speedy)
Running `rustc [...] --crate-name speedy [...] -C debuginfo=2 [...]`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With