[Pre-RFC] Cargo-useable format for prebuilt libraries

New to the forum, apologies in advance if I step on any toes.

I was reading about Hadean's attempts to manage Cargo dependencies with the Nix package manager, and how difficult and hackish it became due to Cargo's inability to use precompiled libraries. I've read up on the reasons that this hasn't been implemented, and it got me thinking: what if we had a library format, that included all of the metadata about that library's compilation? It could include the rlib, the package version, the target triple + all extra compilation features, and the version of rustc used to compile it. That way, to check whether the library was compatible, cargo could simply check the rustc and package versions against the ones it was using -- if it matched, using the precompiled file, and if not, falling back to compiling from source. This same format could also potentially be used to package C libraries -- just specify that you're using the C abi instead of a rustc version, and you're good to go.

You could integrate Cargo into an external build system with this -- you would specify a prebuilt library cache which Cargo could use, and allow the option of falling back to source (emitting an error telling you to update your cache). If the format included a hash of the Cargo.toml, Cargo could even check against crates.io to ensure the integrity of the library, saving a lot of compilation and download time while still getting the benefits of native compilation. We could make Cargo a lot more flexible this way.

Not an expert on low-level details like this, so there may be some reason why this wouldn't work, but it would be really cool if it did.

12 Likes