-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve large workspace build speeds by automatically using a separate CARGO_TARGET_DIR per workspace crate (opt-in) #8596
Comments
Building different crates in a workspace like that shouldn't trigger a rebuild. Each variant of each dependency is stored in the Is this a public project that I can look at? Or do you think you can reduce it to a reproduction? |
Ah! So I just tried my example that I laid out in my issue comment and it doesn't trigger a re-build. So apologies, that means that I'm not actually sure what is leading to me re-building more than I'd expect. I do use Alright - I'll close this and whenever I run into what's really going on I'll open a new issue. Thanks! |
Changing LTO shouldn't cause a rebuild, except on a few platforms (macOS, Windows MSVC, and wasm32) where it will trigger re-linking the final executable. I think dylib and cdylib targets will also need to be rebuilt. Custom named profiles (#6988) can help with those cases if necessary. |
I also have different build scripts across different workspace crates so maybe they’re contributing. I don’t know - but I’ll pay attention to exactly when I see unexpected build times and see if I can open a more focused issue (or likely just fix something that I’m doing incorrectly). Thanks for the link - had never heard of that proposal - will read up! |
Hey, could my unexpected re-building have anything to do with the fact that I use Or is me using
Hmm, I use macOS
I also have a couple of I'm noticing that the re-building crates seem to be somewhat related to my cdylib (dependencies of my cdylib, or dependencies of its dependencies etc) so when I get around to trying #6988 I hope to be in good shape. Thanks! |
Describe the problem you are trying to solve
The problem that I'd like to solve is having crates within a large workspace re-built when their source code hasn't changed, simply because you built another crate within your workspace (which I'm assuming tainted the cache in some sort of way but I'm not entirely familiar with the caching strategies).
To illustrate:
You have a large cargo workspace
Crates within your workspace depend on other crates within your workspace. In some cases multiple crates depend on the same crate within the workspace.
For example, Crate A and B both make use of crate C. Crate A uses certain feature flags, crate B uses certain feature flags.
cargo build crate-a && cargo build crate-b && cargo build crate-a && cargo build crate-b
. I'd expect the second build of each crate to be skipped because nothing has changed, but in this example the second build of each crate might take a few seconds or more.Describe the solution you'd like
The gist of the solution that I'd like is a very easy way to make every crate in the workspace use a separate
CARGO_TARGET_DIR
when built.This would mean trading disk space for compile times (opt-in).
Right now I manually specify a
CARGO_TARGET_DIR
for some of my worst cases of "Aww .. things are getting re-built if nothing changed..." scenarios. Such as when building a few different distribution binaries in a CI job.But I haven't manually added
CARGO_TARGET_DIR
to other build scenarios yet - mainly because it's a (fairly minor) hassle to have to sprinkle the env var in everywhere that I build.I'd prefer to say something such as
And from then on anytime cargo builds a crate it automatically uses
target/MY_CRATE_NAME
.This would be very impactful for me when running my test suite where one of the commands is
cargo test --all
in a workspace that haas a couple dozen crates.Of course I could take the time to write out all of my crate tests (or write a script that enumerates them) as
CARGO_TARGET_DIR=... cargo test -p crate
.And I'll eventually probably do that - but I think that having
Cargo
offer an easy way to handle this instead of leaving it to user-land makes more sense since you end up saving quite a bit of compile time (if you're willing to trade away disk space) when you're working in a large workspace hopping around between different crates.Notes
This is a quick sketch of one potential solution to one small aspect of the "reduce build times" problem.
I'd imagine that a more robust solution might look differently than this initial proposal.
Feel free to point out flaws and bad ideas!
The text was updated successfully, but these errors were encountered: