-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem
When setting some profile configuration globally it applies to all crate types.
For example, if you enable LTO by setting CARGO_PROFILE_RELEASE_LTO=on env variable or defining it inside the global config.toml.
It is meant to be used for executables, but undesirable say for static libs.
Proposed Solution
It could be useful to be able to define profile configurations per crate type.
Notes
The case I faced personally is compiling git with rust support. It uses a staticlib to link against existing C executables. Which means that the code goes through both rustc own LTO and resulting C compiler LTO.
Not mentioning that double LTO is kinda pointless, the end result is actually worse with rustc LTO enabled, for whatever reason. It decreases the size of libgitcore.a itself, but resulting git executable grows in size instead. Reproducible with both GCC & Clang and variety of linkers.
Which probably shouldn't happen at all, as the rust code here doesn't add any functionality, it just substitutes the identical C code (see varint.rs vs varint.c). So without rustc LTO enabled the binary effectively does not change in size as expected.
But that's another question for compiler/linker devs, I guess.