rust-lang/rust

Wasteful duplication between incremental build dirs and normal artifacts.

eddyb opened this issue · 0 comments

eddyb commented

Incremental compilation reuses object files by storing a copy of them in the incremental cache directory, which is then copied into the rlib.

This results to build dirs which are twice as big as they need to be (which then gets multiplied by the number of stale artifacts that aren't removed by any tool AFAICT).

There are several ways we could resolve this, but they can be split into two categories:

  • incremental cache holds the object files
    • Cargo could have a mode in which it instructs rustc to emit object files but only in the incremental cache and then downstream rustc to use that incremental cache
      • this would allow non-Cargo tooling to keep working, but we'd have to support rlibs as the same time as the new system and we might unknowingly break them if Cargo doesn't use them
    • the rlib doesn't have to be a real archive, we could have a different format that references the files in the incremental cache, or even make the rlib a directory full of hardlinks, or a hardlink itself etc.
  • rlib artifact holds the object files
    • not clear what's possible at all for other crate types, for now they'd keep the duplication
    • we probably want to hardlink/symlink it from the incremental cache and hash each object file so we can check it's still the same and only reuse it then
      • we might already be doing that hashing anyway, in case the incremental dir is corrupted
    • requires no change in tooling AFAICT, including custom non-Cargo setups

cc @rust-lang/compiler