Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
luser opened this issue Mar 7, 2017 · 3 comments
Closed

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

luser opened this issue Mar 7, 2017 · 3 comments

Comments

@luser
Copy link
Contributor

luser commented Mar 7, 2017

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.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Mar 7, 2017
This commit alters the compiler to exit quickly if the only output being emitted
is `dep-info`, which doesn't need a lot of other information to generate.

Closes rust-lang#40328
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 9, 2017
rustc: Exit quickly on only `--emit dep-info`

This commit alters the compiler to exit quickly if the only output being emitted
is `dep-info`, which doesn't need a lot of other information to generate.

Closes rust-lang#40328
alexcrichton added a commit to alexcrichton/rust that referenced this issue Mar 10, 2017
rustc: Exit quickly on only `--emit dep-info`

This commit alters the compiler to exit quickly if the only output being emitted
is `dep-info`, which doesn't need a lot of other information to generate.

Closes rust-lang#40328
alexcrichton pushed a commit to arielb1/rust that referenced this issue Mar 10, 2017
rustc: Exit quickly on only `--emit dep-info`

This commit alters the compiler to exit quickly if the only output being emitted
is `dep-info`, which doesn't need a lot of other information to generate.

Closes rust-lang#40328
alexcrichton added a commit to alexcrichton/rust that referenced this issue Mar 10, 2017
This commit alters the compiler to exit quickly if the only output being emitted
is `dep-info`, which doesn't need a lot of other information to generate.

Closes rust-lang#40328
alexcrichton added a commit to alexcrichton/rust that referenced this issue Mar 10, 2017
rustc: Exit quickly on only `--emit dep-info`

This commit alters the compiler to exit quickly if the only output being emitted
is `dep-info`, which doesn't need a lot of other information to generate.

Closes rust-lang#40328
alexcrichton added a commit to alexcrichton/rust that referenced this issue Mar 11, 2017
rustc: Exit quickly on only `--emit dep-info`

This commit alters the compiler to exit quickly if the only output being emitted
is `dep-info`, which doesn't need a lot of other information to generate.

Closes rust-lang#40328
@luser
Copy link
Contributor Author

luser commented Mar 14, 2017

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

@mimoo
Copy link

mimoo commented Apr 30, 2020

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 :(

@eddyb
Copy link
Member

eddyb commented May 1, 2020

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants