While hacking on Rust, how to recompile only what's changed?


#1

tl;dr: this worked for me: make NO_REBUILD=1 NO_BENCH=1 (it recompiled rustdoc in like 4mins)


Suppose I changed something in this file: src/librustdoc/markdown.rs such as, added a println!() to see the value of a variable. I thus need a recompiled rustdoc executable (at least).

How do I tell the rust build system to recompile only what has changed? Instead of everything (which takes like 86 minutes)

NO_REBUILD=1 wouldn’t work because it says "allows docs and tests to be built and run without recompiling Rust. "

What I tried:

$ time make rustc-stage2 NO_BENCH=1
cfg: version 1.9.0-dev (600dc3552 2016-04-04)
cfg: build triple x86_64-unknown-linux-gnu
cfg: host triples x86_64-unknown-linux-gnu
cfg: target triples x86_64-unknown-linux-gnu
cfg: host for x86_64-unknown-linux-gnu is x86_64
cfg: os for x86_64-unknown-linux-gnu is unknown-linux-gnu
cfg: have good valgrind for x86_64-unknown-linux-gnu
cfg: using CC=ccache gcc (CFG_CC)
cfg: disabling valgrind run-pass tests
make: Nothing to be done for 'rustc-stage2'.

real	0m1.438s
user	0m0.473s
sys	0m0.950s

$ time make NO_REBUILD=1 NO_BENCH=1
...
real	3m41.056s
user	6m47.138s
sys	0m7.294s

Wait, what? That did it! rustdoc got recompiled! How teh! :slight_smile:
That was definitely unexpected.

Ok, while that worked on rustdoc supposedly as a side-effect of NO_REBUILD=1 ("allows docs and tests to be built and run without recompiling Rust. "), I figure this will not work if the file that I’ve changed is part of Rust but not of rustdoc?

So the question still stands: how do I recompile only what’s changed?


#2

See https://www.reddit.com/r/rust/comments/2gzt2u/hacking_rustc_small_changes_take_forever/cko0s16 for some suggestions.