Nowadays, dependency compilation still takes a huge part of crate compilation. I've done a few tests on my machine by building a binary crate with a dependency on specific crate but not using it at all. Taking some examples:
actix-web - 84s wgpu - 46s
This idea workarounds this by allowing people to request to use the pre-built shared version of libraries to achieve very fast build time, if similar usages has happened before.
Introduce an optional boolean attribute into
Cargo.toml for each dependencies called
precompiled which defaults to
When it is set to true, the behavior of building this dependency is this:
If target != host maybe just emit an error.
If it's already prebuilt do nothing. Otherwise prebuilt it in this way:
a.Temporarily see its crate type as
dylib, and build it with target-dir pointing to a temporary directory, copying the resulting artifacts to
Copy the artifacts from prebuilt directory back to target-dir as prebuilt-dependencies. Read its metadata and perform linking with the artifacts as usual properly.