-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Make cargo preduce dependency binaries to a shared directory for reuse #6437
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
I think the solution we've promoted to achieve this is using sscache as a rustc wrapper: https://doc.rust-lang.org/cargo/guide/build-cache.html (edit: sscache is also mentioned in the associated thread, but only in passing.) |
I think sccache is not able to share build artifacts between two different projects in different paths (which this pr is aimed at?)? |
Hmm, it looks like build artifacts are share among directories even if different
|
@matthiaskrgr Ah, I see, it seems metadata doesn't include the extra arguments passed to compiler. I think there are two potential workaround here.
I think the first workaround may be better, because once it allows to cache artifacts with extra flags, it may produce too many thing in the shared dir never being used again. Just dig into the fingerprint code a little bit, seems extra RUSTFLAGS is the only param that is missing? I am new to Cargo code please let me know if there's anything wrong. -- |
This is a good goale, I look forward to finding a solution in this direction. Thank you for pushing to make this happen. Unfortunately, I don't know this part of the code well enough to comment on the implementation details. I have some questions about the bigger picture, that I think will need to be answered and documented before it can get stabilized.
|
Good questions. I have inlined answers.
It seems a existing concept, and I am new to Cargo, just pickup the term from the code. The
For this one, --out-dir seems only copy the primary artifacts. But this change won't affect the primary artifacts, so it's different. And I have tried with the both param, seems works. Here's the test run.
I believe this won't cause any problem, since what this change did is just override the output location / dep artifacts location. So it won't impact anything related to tempfile. |
Thanks for the PR here! Unfortunately though I think that this sort of functionality will require significant design work before moving forward with simply a PR. This PR is currently incorrect as RUSTFLAGS isn't the only value that affects the output artifact, there's a lot of settings which don't make their way into the file's hashed name (we have a whole module dedicated to doing this). All of these properties need to be compared to ensure the correct build is used. You can emulate what would naturally happen with Cargo today by using |
☔ The latest upstream changes (presumably #6867) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm gonna go ahead and close this as it's been inactive for quite some time now, but it can of course be resubmitted! |
Currently Cargo re-compiles all the dependencies for every package. But in fact, there's many dependency binaries can be shared across crates. In addition, once the target directory is cleaned, cargo will start to build all the dependencies again.
This change makes Cargo able to reuse the library binaries across the packages by setting environment variable
CARGO_SHARED_TARGET_DIR
. When this environment variable is set, the non-primary unit will produce output inCARGO_SHARED_TARGET_DIR
and if the target is already in the directorycargo
won't callrustc
again.The target name is determined by the name of the crate and the metadata of the output which also mixed the version, dependency versions, features and cfgs.
Related discussion: https://internals.rust-lang.org/t/idea-cargo-global-binary-cache/9002