Description
Problem
Given a Cargo.toml where the profiles are configured to only differ in LTO, I would expect to be able to share dependencies between different profiles (e.g. via sccache), as I wouldn't typically expect LTO to influence dependencies.
Steps
- given the provided cargo.toml in a freshly generated binary project (note only LTO differs) between the profiles
- run
cargo build --verbose
andcargo build --verbose --release
and compare the metadata for byteorder - note they aren't the same
[package]
name = "abc"
version = "0.1.0"
authors = ["Aidan Hobson Sayers <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
byteorder = "*"
[profile.dev]
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
incremental = false
rpath = false
[profile.dev.package."*"]
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
#lto = false # can't specify this for packages
#panic = 'unwind' # can't specify this for packages
incremental = false
#rpath = false # can't specify this for packages
[profile.release]
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
lto = true # NOTE THIS LINE
panic = 'unwind'
incremental = false
rpath = false
Possible Solution(s)
After a quick look - metadata is derived from comparable()
on a Profile
, which looks at the profile lto, rather than the computed lto for that unit. A solution could be to use the computed lto instead.
Alternatively, this issue may just be a wontfix given that we now would expect lto to make dependencies look different (once #8337 is fixed).
This said - even if it is a wontfix, it may be worth using the computed lto anyway as it's strictly speaking more reflective of the logic within cargo than using the profile lto (i.e. if you switch the lto option in your profile but it doesn't actually have an effect on the unit, you don't need to recompile).
Notes
Output of cargo version
:
- cargo 1.44.0 (05d080f 2020-05-06)