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

Add support for caching Rust crate compilation #42

Closed
luser opened this issue Dec 8, 2016 · 7 comments
Closed

Add support for caching Rust crate compilation #42

luser opened this issue Dec 8, 2016 · 7 comments
Assignees

Comments

@luser
Copy link
Contributor

luser commented Dec 8, 2016

I outlined a plan for this in a cargo issue.

The big items here are:

  • make sccache able to detect rustc as a compiler
  • Write a hash function for rustc compiler invocations that uses the things listed in that plan as input. We'll need to refactor the cache lookup code slightly since it currently expects to run a preprocessor and hash that output. We will probably want to make the "generate a hash key" bit generic per-compiler, and then provide a default implementation that does what we currently do for C++ compilers, and a separate implementation for rustc.
@luser
Copy link
Contributor Author

luser commented Mar 3, 2017

I've got a pretty good start on this: https://github.com/luser/sccache/commits/rust-support

@luser
Copy link
Contributor Author

luser commented Mar 7, 2017

I pushed some more changes to the rust-support branch and everything seems to be working for caching Rust compilation!

You can try it out by building sccache from that branch, then you can either write a wrapper script that invokes sccache rustc $* or you can hard-link the sccache binary to a file named rustc, and then run RUSTC=/path/to/rustc cargo build, where /path/to/rustc is your wrapper script or hard-link.

@luser
Copy link
Contributor Author

luser commented Mar 7, 2017

I did some testing this morning, and I was not impressed with the speed of an sccache-wrapped build. I put in some more timing in the server logs and found that the bulk of the time is spent running rustc --emit=dep-info. For some of the crates being built as part of my test app, it took almost as long to run that as to actually run the full compilation. For example, on my Linux machine the rand crate takes ~1.1s to run --emit=dep-info, and ~1.9s to run a full compile.

@eddyb, after looking at the -Z time-passes output, said that he thinks rustc is doing too much work for --emit=dep-info, and we could fix that.

@luser
Copy link
Contributor Author

luser commented Mar 14, 2017

With nightly rustc containing @alexcrichton's fix to exit quickly for --emit=dep-info, sccache is actually a speedup for rust compilation!

luser@eye7:/build/read-process-memory$ cargo clean; time PATH=~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/:$PATH RUSTC=/tmp/bin/rustc cargo build
   Compiling libc v0.2.16
   Compiling getopts v0.2.14
   Compiling log v0.3.6
   Compiling rand v0.3.14
   Compiling pulldown-cmark v0.0.3
   Compiling tempdir v0.3.5
   Compiling skeptic v0.5.0
   Compiling read-process-memory v0.1.2-pre (file:///build/read-process-memory)
    Finished dev [unoptimized + debuginfo] target(s) in 7.36 secs

real	0m7.447s
user	0m0.060s
sys	0m0.044s

luser@eye7:/build/read-process-memory$ cargo clean; time PATH=~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/:$PATH RUSTC=/tmp/bin/rustc cargo build
   Compiling getopts v0.2.14
   Compiling log v0.3.6
   Compiling libc v0.2.16
   Compiling pulldown-cmark v0.0.3
   Compiling rand v0.3.14
   Compiling tempdir v0.3.5
   Compiling skeptic v0.5.0
   Compiling read-process-memory v0.1.2-pre (file:///build/read-process-memory)
    Finished dev [unoptimized + debuginfo] target(s) in 1.92 secs

real	0m2.060s
user	0m0.056s
sys	0m0.040s

@Dushistov
Copy link
Contributor

@luser I tried rust-support on my project, and cargo failed to compile target_build_utils dependency:

$ git clone https://github.com/nagisa/target_build_utils.rs
...
$ RUSTC=$HOME/bin/sccache/rustc cargo build
...
error: Could not compile `target_build_utils`.
$ cargo clean && cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 11.47 secs

RUSTC=$HOME/bin/sccache/rustc cargo build give only such hint:

Caused by:
  process didn't exit successfully: `/home/evgeniy/bin/sccache/rustc --crate-name target_build_utils src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg feature="serde_json" --cfg feature="default" -C metadata=f6a4acc1af3932d7 -C extra-filename=-f6a4acc1af3932d7 --out-dir /tmp/target_build_utils.rs/target/debug/deps -L dependency=/tmp/target_build_utils.rs/target/debug/deps --extern serde_json=/tmp/target_build_utils.rs/target/debug/deps/libserde_json-523da6ef63875c40.rlib --extern phf=/tmp/target_build_utils.rs/target/debug/deps/libphf-e3e74ffb62952a96.rlib` (exit code: 254)

@luser
Copy link
Contributor Author

luser commented Mar 27, 2017

@Dushistov thanks for the info! I'll try that out locally and see if I can reproduce.

@luser
Copy link
Contributor Author

luser commented Mar 27, 2017

This was fixed by merging 8605d60 et. al.

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

2 participants