I make frequently used functions to my own local library and use it.
The library is referenced by itself here and there, so it's too difficult to separate it totally.
But using it is too slow to compile or "cargo check" because it references too many popular libraries and it seems like cargo tries to compile all of it.
How about add some options to cargo that compiles only "used" library,
How would cargo figure out which library/module/function is used without compiling the dependent crate, which in turn requires compiling the dependency crate?
There is an ongoing long-term effort of refactoring rustc compiler to using queries instead of batch processing, which makes it compute only properties of the code that are used, instead of everything in the crate. However, this is only for a single crate and doesn't work across crates.
I think there also was a vague plan to compile crates to MIR representation instead of optimized machine code, which could in theory make compilation of dependencies quicker, and delay heavy optimization work until later. I don't know if that ever got beyond talk that it'd be a nice to have.
But for avoiding compiling unused code in dependencies there's a chicken-egg problem. It's not possible to correctly compile the parent crate without having type information for its children. Rust has glob imports, macros, and generics that can mix code of multiple crates in ways that are difficult or impossible to reason about without actually compiling all of the code involved.
Cargo should only need to check/build your dependencies the first time you check/build in any given workspace, until you update your Rust version or do
cargo clean. If you're getting a clean rebuild more often then that, something's messed up with your configuration.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.