Skip to content

rustc --emit=dep-info does too much work #40328

Closed

Description

@luser

I'm working on caching Rust compilation in sccache, and I got it working but it's not as fast as I had hoped. As part of the design that @alexcrichton, @glandium and I hashed out, I'm running rustc --emit=dep-info to get a list of source files as input to the hash used as the cache key. It turns out that running that takes almost as long as actually compiling the crate for some crates. For example, on my machine compiling the rand crate takes ~1.9s, and running just rustc --emit=dep-info for the same crate takes ~1.1s.

@eddyb looked at the -Z time-passes output and determined that rustc is doing too much work in this case. The fix looks simple, thankfully, so I'm going to try to fix it.

Activity

  1. added a commit that references this issue on Mar 9, 2017
    b8bb1de
  2. added 6 commits that reference this issue on Mar 10, 2017
    4f701fd
    cb71358
    5c8aa74
    88aa2ac
    2b1d1bb
  3. luser commented on Mar 14, 2017

    @luser
    ContributorAuthor

    That's significantly better!

    $ rustc +stable --version
    rustc 1.15.1 (021bd294c 2017-02-08)
    
    $ time rustc --crate-name rand /home/luser/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.3.14/src/lib.rs --crate-type lib -g -C metadata=a266d0434ee969c4 -C extra-filename=-a266d0434ee969c4 -L dependency=/build/read-process-memory/target/debug/deps --extern libc=/build/read-process-memory/target/debug/deps/liblibc-8c7226756bef4c8b.rlib --cap-lints allow --emit dep-info -o /tmp/deps.d
    
    real	0m1.396s
    user	0m1.268s
    sys	0m0.024s
    
    $ rustc +nightly --version
    rustc 1.17.0-nightly (fd182c401 2017-03-13)
    
    $ time rustc +nightly --crate-name rand /home/luser/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.3.14/src/lib.rs --crate-type lib -C debuginfo=2 -C metadata=7436655aefac27bf -C extra-filename=-7436655aefac27bf -L dependency=/build/read-process-memory/target/debug/deps --extern libc=/build/read-process-memory/target/debug/deps/liblibc-89a24418d48d484a.rlib --cap-lints allow --emit dep-info -o /tmp/deps.d
    
    real	0m0.111s
    user	0m0.100s
    sys	0m0.004s
    
  4. mimoo commented on Apr 30, 2020

    @mimoo

    I'm running into the same type of issue, I want to run RUSTFLAGS="--emit=dep-info" cargo check to obtain .d files and understand what files will be used for the compilation. But I do not want to compile anything. This does not seem to work unfortunately :(

  5. eddyb commented on May 1, 2020

    @eddyb
    Contributor

    @mimoo --emit doesn't override previous --emits AFAIK, it's additive. So your RUSTFLAGS does nothing because cargo check already passes --emit=dep-info,metadata.

    You need to use Cargo as a library, or (as I've seen recommended by other people) use cargo_metadata, in order to find all the crates, and then you can attempt to run rustc yourself with --emit=dep-info, but that's not guaranteed to work.

    Looking at the PR that closed this issue, --emit=dep-info stops compilation after expansion, which means it needs to be able to load macros from dependency crates (and e.g. include!(...) can add to the .d output AFAIK).

    So you probably need the full cargo check anyway, unless you want some approximation (that --emit=dep-info won't give you).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions