Improved handling of non-writable rlib/rmeta files #12674
Labels
A-layout
Area: target output directory layout, naming, and organization
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
S-needs-team-input
Status: Needs input from team on whether/how to proceed.
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: