rust-lang / rust-lang/rust

Compile a crate from its source archive directly

Open
#128,884 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Problem

Today, crates provided by e.g. crates.io are downloaded in a (somewhat loosely defined?) archive format, with a .crate extension. Example: https://static.crates.io/crates/clap/clap-3.0.6.crate

clap-3.0.6.crate: gzip compressed data, was "clap-3.0.6.crate", max compression, original size modulo 2^32 1110528

This gets stored as a local cache and is also extracted in a nearby folder, which then gets fed to cargo / rustc for compilation.

I (and surely others) am developing a $RUSTC_WRAPPER that has to deal with these archives and thus have to replicate the handling of said .crates. Given these open issues, and for optimization reasons, I would like for cargo (or rustc) to be able to take in these archives directly, without prior extraction:

Proposed Solution

I am not familiar with the inner workings of either cargo nor rustc so this is a high level take.

Basically, I'm asking that today's call to rustc be seamlessly interchangeable from:

rustc --crate-name clap ...... $HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clap-3.0.6/src/lib.rs ....

to

rustc --crate-name clap ...... $HOME/.cargo/registry/cache/index.crates.io-6f17d22bba15001f/clap-3.0.6.crate ...

thus moving the crate archive handling code to within the boundary of (I guess) rustc.

This in turn

  • encapsulates the archive format
  • allows me (and others) to just pass archives down from crates.io straight to rustc
Notes

I realize this issue may need to move to rustc. But hey let's have a small discussion first :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the current cargo-to-rustc flow described in the issue, including how .crate archives are cached, extracted, and passed to rustc. Compare the existing cargo and rustc entry points, then determine where direct archive handling belongs. Done means rustc or cargo can compile a .crate archive without prior extraction while preserving the current compilation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.