-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improved handling of non-writable rlib/rmeta files #140164
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
Comments
This seems reasonable, but cargo should mostly not be responsible for this, because rustc is the one writing these files. So this issue is the domain of rustc.
We've talked about having a user-wide cache of built libraries. It's a challenge, since every possible configuration or input of a library needs to be taken into account, but it is something we'd love to do if possible. rust-lang/cargo#5931 |
You can see our documentation for what causes a rebuild (fingerprint) vs what causes a unique file ( That does not fully get into intent. One I can think of is having a low-effort GC. Source changes could rapidly expand the size of our cache if we tracked them in our hash. By only tracking them in our fingerprint, we clean up the previous versions automatically. Granted, this isn't ideal when back and forth between commits. We're just now starting to get a more feature rich GC for other parts of Cargo (#14287) and we have more work to do before we can consider a GC for intermediate artifacts and whether that can change how we generate our hash. |
You can share a |
Maybe related: rust-lang/compiler-team#790 |
Problem
I use Crane to build my projects in a Nix environment. This pretty much ends up being vanilla cargo, but with one difference. Crane builds dependencies in one Nix build, storing the resulting
target
dir, and then moves it into place for the subsequent build. The advantage is that when subsequent builds run, they do not have to rebuild dependencies. This is convenient in a CI environment, as it provides for transparent caching.Crane uses two mechanisms to handle this linking procedure. In the old one, it copies everything. This is fast compared to recompiling, but slow compared to a normal cargo workflow, as the data is voluminous. It additionally bloats the output size.
The other mechanism is symlinking, where it adds symlinks for each rlib/rmeta file into the Cargo target directory. These symlinks are read-only.
This mostly works, but fails when Cargo decides that a given library needs to rebuilt. Here, something like:
might be printed by rustc. I believe this is because Cargo is telling rustc to emit to the symlink file, which is then resolved to the read-only path. Rebuilds are typically not required, but can happen due to a buggy build.rs (e.g. a build.rs which emits a non-existent file as a reason to rebuild).
Proposed Solution
I could see three potential solutions here.
There are additional crane-side solutions that could be applied (one simple one might be creating the cargo target dir as an overlayfs, for example). I'd note that I don't believe this problem is exclusively crane related. I've filed a similar tracking issue on Crane itself as ipetkov/crane#385.
Notes
It's very possible that I've misunderstood the separation of responsibilities between rustc and cargo - if so, my apologies. It's also very possible that I'm considering this issue too myopically - that there is some larger improvement that would solve my workflow - I tried to be minimalistic here because piecewise minimalist solutions to problems are usually faster to resolve if project maintainers are amenable to them.
Lastly, it's possible that this is considered a reasonable wontfix - I'm surfacing here because I quite like the Crane behaviour and would love it to be less error-prone.
The text was updated successfully, but these errors were encountered: