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

Incremental compilation error building rustc (-i --keep-stage 0) #59105

Closed
alexreg opened this issue Mar 11, 2019 · 16 comments · Fixed by #63470
Closed

Incremental compilation error building rustc (-i --keep-stage 0) #59105

alexreg opened this issue Mar 11, 2019 · 16 comments · Fixed by #63470
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. P-medium Medium priority T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexreg
Copy link
Contributor

alexreg commented Mar 11, 2019

I manage to successfully build the latest master revision of rustc, but then when I try to build it incrementally as ./x.py build -i --keep-stage 0, I get the following error. Apparently, this is broken for others as well, as has been for a while.

$ ./x.py build -i --keep-stage 0
Updating only changed submodules
Submodules updated in 0.08 seconds
    Finished dev [unoptimized] target(s) in 0.45s
Warning: Using a potentially old libstd. This may not behave well.
Copying stage0 std from stage0 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Warning: Using a potentially old libtest. This may not behave well.
Copying stage0 test from stage0 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Warning: Using a potentially old librustc. This may not behave well.
Copying stage0 rustc from stage0 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Warning: Using a potentially old codegen backend. This may not behave well.
Assembling stage1 compiler (x86_64-apple-darwin)
Building stage1 std artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
   Compiling cc v1.0.28
   Compiling libc v0.2.46
   Compiling core v0.0.0 (/Users/alex/Software/rust-devel/src/libcore)
   Compiling unwind v0.0.0 (/Users/alex/Software/rust-devel/src/libunwind)
   Compiling build_helper v0.1.0 (/Users/alex/Software/rust-devel/src/build_helper)
   Compiling compiler_builtins v0.1.5
   Compiling cmake v0.1.33
   Compiling backtrace-sys v0.1.27
   Compiling std v0.0.0 (/Users/alex/Software/rust-devel/src/libstd)
   Compiling rustc_asan v0.0.0 (/Users/alex/Software/rust-devel/src/librustc_asan)
   Compiling rustc_tsan v0.0.0 (/Users/alex/Software/rust-devel/src/librustc_tsan)
   Compiling rustc-std-workspace-core v1.0.0 (/Users/alex/Software/rust-devel/src/tools/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/Users/alex/Software/rust-devel/src/liballoc)
   Compiling panic_abort v0.0.0 (/Users/alex/Software/rust-devel/src/libpanic_abort)
   Compiling rustc-demangle v0.1.10
   Compiling panic_unwind v0.0.0 (/Users/alex/Software/rust-devel/src/libpanic_unwind)
    Finished release [optimized] target(s) in 1m 12s
Copying stage1 std from stage1 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Building stage1 test artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
   Compiling getopts v0.2.17
   Compiling proc_macro v0.0.0 (/Users/alex/Software/rust-devel/src/libproc_macro)
   Compiling term v0.0.0 (/Users/alex/Software/rust-devel/src/libterm)
   Compiling test v0.0.0 (/Users/alex/Software/rust-devel/src/libtest)
    Finished release [optimized] target(s) in 21.00s
Copying stage1 test from stage1 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Building stage1 compiler artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
   Compiling nodrop v0.1.12
   Compiling cfg-if v0.1.6
   Compiling rand_core v0.3.0
   Compiling memoffset v0.2.1
   Compiling scopeguard v0.3.3
   Compiling lazy_static v1.2.0
   Compiling void v1.0.2
   Compiling stable_deref_trait v1.1.0
   Compiling either v1.5.0
   Compiling unicode-width v0.1.5
   Compiling byteorder v1.2.7
   Compiling bitflags v1.0.4
   Compiling graphviz v0.0.0 (/Users/alex/Software/rust-devel/src/libgraphviz)
   Compiling scoped-tls v1.0.0
   Compiling lazy_static v0.2.11
   Compiling termcolor v1.0.4
   Compiling rustc-demangle v0.1.10
   Compiling datafrog v2.0.1
   Compiling remove_dir_all v0.5.1
   Compiling fmt_macros v0.0.0 (/Users/alex/Software/rust-devel/src/libfmt_macros)
   Compiling rustc_fs_util v0.0.0 (/Users/alex/Software/rust-devel/src/librustc_fs_util)
   Compiling rustc-serialize v0.3.24
   Compiling quick-error v1.2.2
   Compiling scoped-tls v0.1.2
   Compiling cc v1.0.28
   Compiling libc v0.2.46
   Compiling rustc-rayon-core v0.1.2
   Compiling rustc-rayon v0.1.2
   Compiling crossbeam-utils v0.2.2
   Compiling log v0.4.6
   Compiling rustc_target v0.0.0 (/Users/alex/Software/rust-devel/src/librustc_target)
   Compiling crc32fast v1.1.2
   Compiling syntax v0.0.0 (/Users/alex/Software/rust-devel/src/libsyntax)
   Compiling arrayvec v0.4.7
   Compiling owning_ref v0.3.3
   Compiling unreachable v1.0.0
   Compiling rustc v0.0.0 (/Users/alex/Software/rust-devel/src/librustc)
   Compiling log_settings v0.1.2
   Compiling rustc_incremental v0.0.0 (/Users/alex/Software/rust-devel/src/librustc_incremental)
   Compiling rustc_metadata v0.0.0 (/Users/alex/Software/rust-devel/src/librustc_metadata)
   Compiling chalk-macros v0.1.0
   Compiling humantime v1.2.0
   Compiling rustc_driver v0.0.0 (/Users/alex/Software/rust-devel/src/librustc_driver)
   Compiling rand_xorshift v0.1.0
   Compiling rand_isaac v0.1.1
   Compiling rand_hc v0.1.0
   Compiling rand_core v0.2.2
   Compiling miniz-sys v0.1.11
   Compiling rustc-hash v1.0.1
   Compiling smallvec v0.6.7
   Compiling ena v0.11.0
   Compiling rustc_cratesio_shim v0.0.0 (/Users/alex/Software/rust-devel/src/librustc_cratesio_shim)
   Compiling lock_api v0.1.3
   Compiling polonius-engine v0.6.2
   Compiling crossbeam-epoch v0.3.1
   Compiling chalk-engine v0.9.0
   Compiling num_cpus v1.8.0
   Compiling jobserver v0.1.12
   Compiling atty v0.2.11
   Compiling backtrace v0.3.11
   Compiling memmap v0.6.2
   Compiling rand v0.5.5
   Compiling serialize v0.0.0 (/Users/alex/Software/rust-devel/src/libserialize)
   Compiling rand_chacha v0.1.0
   Compiling rand_pcg v0.1.1
   Compiling rand v0.6.1
   Compiling parking_lot_core v0.4.0
   Compiling rustc_apfloat v0.0.0 (/Users/alex/Software/rust-devel/src/librustc_apfloat)
   Compiling env_logger v0.5.13
   Compiling flate2 v1.0.6
   Compiling crossbeam-deque v0.2.0
   Compiling rustc_macros v0.1.0 (/Users/alex/Software/rust-devel/src/librustc_macros)
error[E0460]: found possibly newer version of crate `std` which `synstructure` depends onialize...
 --> src/librustc_macros/src/lib.rs:4:5
  |
4 | use synstructure::decl_derive;
  |     ^^^^^^^^^^^^
  |
  = note: perhaps that crate needs to be recompiled?
  = note: the following crate versions were found:
          crate `std`: /Users/alex/Software/rust-devel/build/x86_64-apple-darwin/stage1/lib/rustlib/x86_64-apple-darwin/lib/libstd-082537f2f194063c.rlib
          crate `std`: /Users/alex/Software/rust-devel/build/x86_64-apple-darwin/stage1/lib/rustlib/x86_64-apple-darwin/lib/libstd-082537f2f194063c.dylib
          crate `synstructure`: /Users/alex/Software/rust-devel/build/x86_64-apple-darwin/stage1-rustc/release/deps/libsynstructure-923fcb34d21ecfbf.rlib

error: aborting due to previous error

For more information about this error, try `rustc --explain E0460`.
error: Could not compile `rustc_macros`.
warning: build failed, waiting for other jobs to finish...
error: build failed
command did not execute successfully: "/Users/alex/Software/rust-devel/build/x86_64-apple-darwin/stage0/bin/cargo" "build" "--target" "x86_64-apple-darwin" "-j" "12" "--release" "--features" "" "--manifest-path" "/Users/alex/Software/rust-devel/src/rustc/Cargo.toml" "--message-format" "json"
expected success, got: exit code: 101
failed to run: /Users/alex/Software/rust-devel/build/bootstrap/debug/bootstrap build -i --keep-stage 0
Build completed unsuccessfully in 0:01:59
@jonas-schievink jonas-schievink added A-incr-comp Area: Incremental compilation T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-bug Category: This is a bug. labels Mar 11, 2019
@estebank
Copy link
Contributor

Stopgap: ./x.py clean helps you get to a good state.

@alexreg
Copy link
Contributor Author

alexreg commented Mar 11, 2019

@estebank Yeah I know, but then I have to compile from scratch, and it takes forever. :-(

@ehuss
Copy link
Contributor

ehuss commented Mar 15, 2019

I think I see one way this happens. I think the issue is that clear_if_dirty only knows about one output directory, but it does not consider the host directory (for stage1) where proc-macros and build scripts are located.

Here is one way to repro this:

  1. ./x.py build
  2. Make a change to libstd that will modify the SVH. I added a module, but there's probably an easier way.
  3. Force a proc macro to get rebuilt: touch src/librustc_macros/src/lib.rs
  4. ./x.py build

The last step should fail in stage1 to build rustc_macros because one of its dependencies (synstructure) was compiled with an older libstd, but synstructure itself was not rebuilt.

I think the solution is to clear the host directory, although care should be taken so it is not cleared multiple times if there are multiple targets. I'm not super familiar with rustbuild, but maybe @Mark-Simulacrum or @collin5 know more about this.

One way to get this particular example back on track is to rm -rf build/*/stage1-rustc/release.

Some similar issues: #49979, #50481

EDIT: Other things like codegen have to be cleaned out too, like rm -rf build/*/stage1-codegen/release.

@alexreg
Copy link
Contributor Author

alexreg commented Mar 21, 2019

@estebank Do you know who works on incremental compilation in the compiler team? This seems like a pretty high-priority bug, so maybe we should tag them. :-)

@estebank
Copy link
Contributor

I believe @alexcrichton, @nikomatsakis, @Zoxc, @michaelwoerister and @MarkSimulacrum have been involved with incremental compilation at one point or another.

@Mark-Simulacrum
Copy link
Member

Based on the error message, this likely has nothing to do with the compiler -- it's most likely purely a problem inside rustbuild (i.e., rustbuild is broken).

@ehuss
Copy link
Contributor

ehuss commented Mar 21, 2019

Yea, this is only related to rustbuild. The issue is that cargo does not track libstd as a dependency, so rustbuild needs to be careful to force rebuilding of crates when libstd changes. It does that currently (via clear_if_dirty), but it is missing the directory for proc-macros and build scripts.

@alexreg
Copy link
Contributor Author

alexreg commented Mar 21, 2019

Ah okay. So it should be quite a straightforward fix for someone who knows how rustbuild works, eh?

@Mark-Simulacrum
Copy link
Member

Actually quite difficult, but yes, in theory it's a fairly easy fix.

@pnkfelix pnkfelix changed the title Incremental compilation error building rustc Incremental compilation error building rustc (-i --keep-stage 0) Mar 26, 2019
@Centril Centril added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 1, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Apr 4, 2019

triage: leaving I-nominated for discussion of prioritization at T-compiler meeting itself.

(My personal inclination is to assign this P-medium priority, and if no one takes it on at the meeting or shortly thereafter, I may self-assign.)

@pnkfelix
Copy link
Member

pnkfelix commented Apr 4, 2019

discussed at T-compiler meeting. Assigning P-medium priority, since this is essentially an internal tooling issue that we would like to fix, but does not take precedence over customer P-high matters.

@pnkfelix pnkfelix added P-medium Medium priority and removed I-nominated labels Apr 4, 2019
@alexreg
Copy link
Contributor Author

alexreg commented Apr 4, 2019

@pnkfelix Sounds reasonable enough. It's probably P-high by rustc developer standards, but when you consider the scale has to include end-users too, P-medium makes more sense.

@tesuji
Copy link
Contributor

tesuji commented Apr 4, 2019

Currently I'm not able to build the Rust project. Even running git clean -xfd in the project root
the run ./x.py check (with latest commits from GitHub).

I received this error:

Checking test artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Checking rustc_term v0.0.1
    Checking getopts v0.2.17
    Checking proc_macro v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/libproc_macro)
    Checking libtest v0.0.1
error[E0460]: found possibly newer version of crate `std` which `getopts` depends onest
  --> /home/lzutao/.cargo/registry/src/github.com-1ecc6299db9ec823/libtest-0.0.1/lib.rs:34:5
   |
34 | use getopts;
   |     ^^^^^^^
   |
   = note: perhaps that crate needs to be recompiled?
   = note: the following crate versions were found:
           crate `std`: /home/lzutao/github.com/lzutao/rust-fork/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-d26c9396879f81c2.rmeta
           crate `getopts`: /home/lzutao/github.com/lzutao/rust-fork/rust/build/x86_64-unknown-linux-gnu/stage0-test/x86_64-unknown-linux-gnu/release/deps/libgetopts-267ef145c76bc717.rmeta

error: aborting due to previous error

EDIT: It might be related that I'm setting RUSTC_WRAPPER=sccache.

Full stdout when running `./x.py check`
% ./x.py check
Updating only changed submodules
Submodules updated in 0.04 seconds
downloading https://static.rust-lang.org/dist/2019-03-20/rust-std-beta-x86_64-unknown-linux-gnu.tar.gz
##################################################################################################### 100.0%
extracting /home/lzutao/github.com/lzutao/rust-fork/rust/build/cache/2019-03-20/rust-std-beta-x86_64-unknown-linux-gnu.tar.gz
downloading https://static.rust-lang.org/dist/2019-03-20/rustc-beta-x86_64-unknown-linux-gnu.tar.gz
##################################################################################################### 100.0%
extracting /home/lzutao/github.com/lzutao/rust-fork/rust/build/cache/2019-03-20/rustc-beta-x86_64-unknown-linux-gnu.tar.gz
downloading https://static.rust-lang.org/dist/2019-03-20/cargo-beta-x86_64-unknown-linux-gnu.tar.gz
##################################################################################################### 100.0%
extracting /home/lzutao/github.com/lzutao/rust-fork/rust/build/cache/2019-03-20/cargo-beta-x86_64-unknown-linux-gnu.tar.gz
   Compiling proc-macro2 v0.4.24
   Compiling unicode-xid v0.1.0
   Compiling ryu v0.2.7
   Compiling libc v0.2.51
   Compiling serde v1.0.82
   Compiling itoa v0.4.3
   Compiling fixedbitset v0.1.9
   Compiling cc v1.0.28
   Compiling cfg-if v0.1.6
   Compiling ordermap v0.3.5
   Compiling build_helper v0.1.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/build_helper)
   Compiling lazy_static v0.2.11
   Compiling getopts v0.2.17
   Compiling cmake v0.1.33
   Compiling petgraph v0.4.13
   Compiling quote v0.6.10
   Compiling num_cpus v1.8.0
   Compiling filetime v0.2.4
   Compiling time v0.1.40
   Compiling serde_json v1.0.33
   Compiling toml v0.4.10
   Compiling syn v0.15.22
   Compiling serde_derive v1.0.81
   Compiling bootstrap v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/bootstrap)
    Finished dev [unoptimized] target(s) in 1m 28s
Checking rustdoc artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Checking std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling cc v1.0.28
    Checking core v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/libcore)
   Compiling libc v0.2.51
   Compiling unwind v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/libunwind)
   Compiling build_helper v0.1.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/build_helper)
   Compiling compiler_builtins v0.1.8
   Compiling cmake v0.1.33
   Compiling backtrace-sys v0.1.27
   Compiling std v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/libstd)
    Checking rustc-std-workspace-core v1.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/tools/rustc-std-workspace-core)
   Compiling rustc_asan v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/librustc_asan)
   Compiling rustc_lsan v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/librustc_lsan)
   Compiling rustc_tsan v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/librustc_tsan)
   Compiling rustc_msan v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/librustc_msan)
    Checking alloc v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/liballoc)
    Checking rustc-demangle v0.1.10
    Checking panic_abort v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/libpanic_abort)
    Checking panic_unwind v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/libpanic_unwind)
    Finished release [optimized] target(s) in 32.12s
Checking test artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Checking rustc_term v0.0.1
    Checking getopts v0.2.17
    Checking proc_macro v0.0.0 (/home/lzutao/github.com/lzutao/rust-fork/rust/src/libproc_macro)
    Checking libtest v0.0.1
error[E0460]: found possibly newer version of crate `std` which `getopts` depends onest
  --> /home/lzutao/.cargo/registry/src/github.com-1ecc6299db9ec823/libtest-0.0.1/lib.rs:34:5
   |
34 | use getopts;
   |     ^^^^^^^
   |
   = note: perhaps that crate needs to be recompiled?
   = note: the following crate versions were found:
           crate `std`: /home/lzutao/github.com/lzutao/rust-fork/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-d26c9396879f81c2.rmeta
           crate `getopts`: /home/lzutao/github.com/lzutao/rust-fork/rust/build/x86_64-unknown-linux-gnu/stage0-test/x86_64-unknown-linux-gnu/release/deps/libgetopts-267ef145c76bc717.rmeta

error: aborting due to previous error

For more information about this error, try `rustc --explain E0460`.
error: Could not compile `libtest`.

To learn more, run the command again with --verbose.
command did not execute successfully: "/home/lzutao/github.com/lzutao/rust-fork/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-j" "1" "--release" "--manifest-path" "/home/lzutao/github.com/lzutao/rust-fork/rust/src/libtest/Cargo.toml" "--message-format" "json"
expected success, got: exit code: 101
failed to run: /home/lzutao/github.com/lzutao/rust-fork/rust/build/bootstrap/debug/bootstrap check
Build completed unsuccessfully in 0:02:23

</details>

@rljacobson
Copy link

I get this error with --keep-stage 1. However, --keep-stage 0 worked. The output of the build command follows.

$ ./x.py build --keep-stage 1 --stage 2
Updating only changed submodules
Submodules updated in 0.09 seconds
    Finished dev [unoptimized] target(s) in 3.52s
Building stage0 std artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
    Finished release [optimized] target(s) in 0.29s
Copying stage0 std from stage0 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Building stage0 test artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
    Finished release [optimized] target(s) in 0.14s
Copying stage0 test from stage0 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Building stage0 compiler artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
    Finished release [optimized] target(s) in 0.45s
Copying stage0 rustc from stage0 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Building stage0 codegen artifacts (x86_64-apple-darwin -> x86_64-apple-darwin, llvm)
    Finished release [optimized] target(s) in 0.20s
Assembling stage1 compiler (x86_64-apple-darwin)
Warning: Using a potentially old libstd. This may not behave well.
Copying stage1 std from stage1 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Warning: Using a potentially old libtest. This may not behave well.
Copying stage1 test from stage1 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
thread 'main' panicked at 'fs::read(stamp) failed with No such file or directory (os error 2)', src/bootstrap/lib.rs:1159:24
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
failed to run: /Users/rjacobson/rust/build/bootstrap/debug/bootstrap build --keep-stage 1 --stage 2
Build completed unsuccessfully in 0:00:09

My first build was done from a new cloned repo on an empty directory. The first build command was:

$ ./x.py build -i --stage 1 src/lib

@alexreg
Copy link
Contributor Author

alexreg commented Jun 8, 2019

@pnkfelix Any progress on this lately? Did you want to self-assign?

bors added a commit to rust-lang/cargo that referenced this issue Jul 26, 2019
Fix some issues with absolute paths in dep-info files.

There were some issues with how #7030 was handling translating paths in dep-info files. The main consequence is that when coupled with rust-lang/rust#61727 (which has not yet merged), the fingerprint would fail and be considered dirty when it should be fresh.

It was joining [`target_root`](https://github.com/rust-lang/cargo/blame/1140c527c4c3b3e2533b9771d67f88509ef7fc16/src/cargo/core/compiler/fingerprint.rs#L1352-L1360) which had 3 different values, but stripping [only one](https://github.com/rust-lang/cargo/blame/1140c527c4c3b3e2533b9771d67f88509ef7fc16/src/cargo/core/compiler/mod.rs#L323). This means for different scenarios (like using `--target`), it was creating incorrect paths in some cases. For example a target having a proc-macro dependency which would be in the host directory.

The solution here is to always use CARGO_TARGET_DIR as the base that all relative paths are checked against. This should handle all host/target differences.

The tests are marked with `#[ignore]` because 61727 has not yet merged.

This includes a second commit (which I can open as a separate PR if needed) which is an alternate solution to #7034. It adds dep-info tracking for registry dependencies. However, it tries to limit which kinds of paths it tracks. It will not track package-relative paths (like source files). It also adds an mtime cache to significantly reduce the number of stat calls (because every dependency was stating every file in sysroot).

Finally, I've run some tests using this PR with 61727 in rust-lang/rust. I can confirm that a second build is fresh (it doesn't erroneously rebuild). I can also confirm that the problem in rust-lang/rust#59105 has *finally* been fixed!

My confidence in all this is pretty low, but I've been unable to think of any specific ways to make it fail. If anyone has ideas on how to better test this, let me know. Also, feel free to ask questions since I've been thinking about this a lot for the past few weeks, and there is quite a bit of subtle stuff going on.
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Aug 14, 2019
…xcrichton

Utilize -Zbinary-dep-depinfo in rustbuild

The last commit moves us over to using binary-dep-depinfo while the first two permit us to bootstrap from what will become future beta, to be released in the next week (it's the `cfg(bootstrap)` processing).

We no longer utilize stamp-file mtimes at all inside rustbuild, and a future PR may be able to entirely eliminate them by eagerly copying to the appropriate sysroot. The only mtime-based dependency tracking left is for documentation because we lie to Cargo about the rustdoc binary, so Cargo does not track changes to the real binary, and codegen-backends because binary-dep-depinfo does not emit that information into the depfiles.

Both of these are fixable in the longer term but this existing patch gives us the following benefits:
 * We no longer delete Cargo target directories manually within a stage. Cross-stage, changes to codegen backends will still clear out target directories. This means that incremental state persists across individual steps (e.g., rebuilding libstd does not clear out librustc incremental state). Fixes rust-lang#54712.
 * Dependency tracking across steps within a given stage is now fully precise. We will not clear out all codegen backend dependencies due to changes in librustc_driver, for example, only deleting the final librustc_codegen_llvm crate. Fixes rust-lang#54008, fixes rust-lang#50481.
 * We properly track codegen backends as a dependency (equivalent to rustc) across changes. Fixes rust-lang#53284, and fixes rust-lang#52719.
 * Cross-stage dependency tracking of crates is also much more accurate and reliable. Most likely fixes rust-lang#49979 (but no reproduction steps in that issue). Fixes rust-lang#59105.

cc rust-lang#63012
Centril added a commit to Centril/rust that referenced this issue Aug 15, 2019
…xcrichton

Utilize -Zbinary-dep-depinfo in rustbuild

The last commit moves us over to using binary-dep-depinfo while the first two permit us to bootstrap from what will become future beta, to be released in the next week (it's the `cfg(bootstrap)` processing).

We no longer utilize stamp-file mtimes at all inside rustbuild, and a future PR may be able to entirely eliminate them by eagerly copying to the appropriate sysroot. The only mtime-based dependency tracking left is for documentation because we lie to Cargo about the rustdoc binary, so Cargo does not track changes to the real binary, and codegen-backends because binary-dep-depinfo does not emit that information into the depfiles.

Both of these are fixable in the longer term but this existing patch gives us the following benefits:
 * We no longer delete Cargo target directories manually within a stage. Cross-stage, changes to codegen backends will still clear out target directories. This means that incremental state persists across individual steps (e.g., rebuilding libstd does not clear out librustc incremental state). Fixes rust-lang#54712.
 * Dependency tracking across steps within a given stage is now fully precise. We will not clear out all codegen backend dependencies due to changes in librustc_driver, for example, only deleting the final librustc_codegen_llvm crate. Fixes rust-lang#54008, fixes rust-lang#50481.
 * We properly track codegen backends as a dependency (equivalent to rustc) across changes. Fixes rust-lang#53284, and fixes rust-lang#52719.
 * Cross-stage dependency tracking of crates is also much more accurate and reliable. Most likely fixes rust-lang#49979 (but no reproduction steps in that issue). Fixes rust-lang#59105.

cc rust-lang#63012
Centril added a commit to Centril/rust that referenced this issue Aug 15, 2019
…xcrichton

Utilize -Zbinary-dep-depinfo in rustbuild

The last commit moves us over to using binary-dep-depinfo while the first two permit us to bootstrap from what will become future beta, to be released in the next week (it's the `cfg(bootstrap)` processing).

We no longer utilize stamp-file mtimes at all inside rustbuild, and a future PR may be able to entirely eliminate them by eagerly copying to the appropriate sysroot. The only mtime-based dependency tracking left is for documentation because we lie to Cargo about the rustdoc binary, so Cargo does not track changes to the real binary, and codegen-backends because binary-dep-depinfo does not emit that information into the depfiles.

Both of these are fixable in the longer term but this existing patch gives us the following benefits:
 * We no longer delete Cargo target directories manually within a stage. Cross-stage, changes to codegen backends will still clear out target directories. This means that incremental state persists across individual steps (e.g., rebuilding libstd does not clear out librustc incremental state). Fixes rust-lang#54712.
 * Dependency tracking across steps within a given stage is now fully precise. We will not clear out all codegen backend dependencies due to changes in librustc_driver, for example, only deleting the final librustc_codegen_llvm crate. Fixes rust-lang#54008, fixes rust-lang#50481.
 * We properly track codegen backends as a dependency (equivalent to rustc) across changes. Fixes rust-lang#53284, and fixes rust-lang#52719.
 * Cross-stage dependency tracking of crates is also much more accurate and reliable. Most likely fixes rust-lang#49979 (but no reproduction steps in that issue). Fixes rust-lang#59105.

cc rust-lang#63012
Centril added a commit to Centril/rust that referenced this issue Aug 15, 2019
…xcrichton

Utilize -Zbinary-dep-depinfo in rustbuild

The last commit moves us over to using binary-dep-depinfo while the first two permit us to bootstrap from what will become future beta, to be released in the next week (it's the `cfg(bootstrap)` processing).

We no longer utilize stamp-file mtimes at all inside rustbuild, and a future PR may be able to entirely eliminate them by eagerly copying to the appropriate sysroot. The only mtime-based dependency tracking left is for documentation because we lie to Cargo about the rustdoc binary, so Cargo does not track changes to the real binary, and codegen-backends because binary-dep-depinfo does not emit that information into the depfiles.

Both of these are fixable in the longer term but this existing patch gives us the following benefits:
 * We no longer delete Cargo target directories manually within a stage. Cross-stage, changes to codegen backends will still clear out target directories. This means that incremental state persists across individual steps (e.g., rebuilding libstd does not clear out librustc incremental state). Fixes rust-lang#54712.
 * Dependency tracking across steps within a given stage is now fully precise. We will not clear out all codegen backend dependencies due to changes in librustc_driver, for example, only deleting the final librustc_codegen_llvm crate. Fixes rust-lang#54008, fixes rust-lang#50481.
 * We properly track codegen backends as a dependency (equivalent to rustc) across changes. Fixes rust-lang#53284, and fixes rust-lang#52719.
 * Cross-stage dependency tracking of crates is also much more accurate and reliable. Most likely fixes rust-lang#49979 (but no reproduction steps in that issue). Fixes rust-lang#59105.

cc rust-lang#63012
Centril added a commit to Centril/rust that referenced this issue Aug 15, 2019
…xcrichton

Utilize -Zbinary-dep-depinfo in rustbuild

The last commit moves us over to using binary-dep-depinfo while the first two permit us to bootstrap from what will become future beta, to be released in the next week (it's the `cfg(bootstrap)` processing).

We no longer utilize stamp-file mtimes at all inside rustbuild, and a future PR may be able to entirely eliminate them by eagerly copying to the appropriate sysroot. The only mtime-based dependency tracking left is for documentation because we lie to Cargo about the rustdoc binary, so Cargo does not track changes to the real binary, and codegen-backends because binary-dep-depinfo does not emit that information into the depfiles.

Both of these are fixable in the longer term but this existing patch gives us the following benefits:
 * We no longer delete Cargo target directories manually within a stage. Cross-stage, changes to codegen backends will still clear out target directories. This means that incremental state persists across individual steps (e.g., rebuilding libstd does not clear out librustc incremental state). Fixes rust-lang#54712.
 * Dependency tracking across steps within a given stage is now fully precise. We will not clear out all codegen backend dependencies due to changes in librustc_driver, for example, only deleting the final librustc_codegen_llvm crate. Fixes rust-lang#54008, fixes rust-lang#50481.
 * We properly track codegen backends as a dependency (equivalent to rustc) across changes. Fixes rust-lang#53284, and fixes rust-lang#52719.
 * Cross-stage dependency tracking of crates is also much more accurate and reliable. Most likely fixes rust-lang#49979 (but no reproduction steps in that issue). Fixes rust-lang#59105.

cc rust-lang#63012
Centril added a commit to Centril/rust that referenced this issue Aug 15, 2019
…xcrichton

Utilize -Zbinary-dep-depinfo in rustbuild

The last commit moves us over to using binary-dep-depinfo while the first two permit us to bootstrap from what will become future beta, to be released in the next week (it's the `cfg(bootstrap)` processing).

We no longer utilize stamp-file mtimes at all inside rustbuild, and a future PR may be able to entirely eliminate them by eagerly copying to the appropriate sysroot. The only mtime-based dependency tracking left is for documentation because we lie to Cargo about the rustdoc binary, so Cargo does not track changes to the real binary, and codegen-backends because binary-dep-depinfo does not emit that information into the depfiles.

Both of these are fixable in the longer term but this existing patch gives us the following benefits:
 * We no longer delete Cargo target directories manually within a stage. Cross-stage, changes to codegen backends will still clear out target directories. This means that incremental state persists across individual steps (e.g., rebuilding libstd does not clear out librustc incremental state). Fixes rust-lang#54712.
 * Dependency tracking across steps within a given stage is now fully precise. We will not clear out all codegen backend dependencies due to changes in librustc_driver, for example, only deleting the final librustc_codegen_llvm crate. Fixes rust-lang#54008, fixes rust-lang#50481.
 * We properly track codegen backends as a dependency (equivalent to rustc) across changes. Fixes rust-lang#53284, and fixes rust-lang#52719.
 * Cross-stage dependency tracking of crates is also much more accurate and reliable. Most likely fixes rust-lang#49979 (but no reproduction steps in that issue). Fixes rust-lang#59105.

cc rust-lang#63012
@bors bors closed this as completed in 9a32ad0 Aug 16, 2019
@tshepang
Copy link
Member

tshepang commented Jul 31, 2020

Just bumped onto this with ./x.py doc, even after ./x.py clean:

error[E0460]: found possibly newer version of crate `std` which `synstructure` depends on                                                    
 --> src/librustc_macros/src/lib.rs:4:5                                                                                                      
  |                                                                                                                                          
4 | use synstructure::decl_derive;                                                                                                           
  |     ^^^^^^^^^^^^                                                                                                                         
  |                                                                                                                                                                                                                                                                                       
  = note: perhaps that crate needs to be recompiled?                                                                                                                                                                                                                                      
  = note: the following crate versions were found:                                                                                                                                                                                                                                        
          crate `std`: /home/tshepang/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-95e90a1be2e66993.rlib                                                                                                                            
          crate `std`: /home/tshepang/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-95e90a1be2e66993.so                                                                            
          crate `synstructure`: /home/tshepang/rust/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps/libsynstructure-7a0d29a374b01f60.rmeta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. P-medium Medium priority T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants