I'm probably doing something wrong. The docs say that with incremental compilation you should be able to recompile rustc in about 30 seconds. For me it takes around 10 minutes.
I've done the following (as described in the docs):
codegen-units to 0 in config.toml./x.py build -i --stage 1librustc./x.py build -i --stage 1 --keep-stage 1 src/librustcStep 4 takes at least 10 minutes, often more. This is ran on a MacBook Pro (3.1 GHz Intel Core i7 with 4 cores) with macOS Mojoave 10.14.5.
I'm using a local nightly version of rustc and cargo that are both up to date. But I've also tried with the default configuration and I still get the same result.
Are these compilation times normal or am I doing something wrong? Thanks for the help!
cc @Zoxc
I experience this as well on macOS Mojave 10.14.5.
I also have optimize set to true and debug assertions off.
A full bootstrap usually takes over an hour and an incremental build with keep-stage 1 and only a small change (e.g. a whitespace change) in librustc takes over 20 minutes.
30 seconds does seem quite optimistic for a incremental compiler build (assuming any changes). This is probably just some wrong documentation. cc @mark-i-m
Well, 3 minutes would make me happy too. Do you guys get different results on Linux?
Guide doesn't specify the CPU :smile:
$ echo " " >> src/librustc/lib.rs
$ ./x.py build -i --stage 1 --keep-stage 1 src/librustc
[...]
Build completed successfully in 0:02:31
$ echo " " >> src/librustc_codegen_ssa/lib.rs
$ ./x.py build -i --stage 1 --keep-stage 1 src/librustc_codegen_ssa/lib.rs
[...]
Build completed successfully in 0:00:51
$ echo " " >> src/librustc_driver/lib.rs
$ ./x.py build -i --stage 1 --keep-stage 1 src/librustc_driver
[...]
Build completed successfully in 0:00:39 # Almost there
Config
--- config.toml.example 2019-07-04 15:20:12.472184560 +0200
+++ config.toml 2019-07-24 18:34:31.037396329 +0200
@@ -291,11 +291,11 @@
# Number of codegen units to use for each compiler invocation. A value of 0
# means "the number of cores on this machine", and 1+ is passed through to the
# compiler.
-#codegen-units = 1
+codegen-units = 0
# Sets the number of codegen units to build the standard library with,
# regardless of what the codegen-unit setting for the rest of the compiler is.
-#codegen-units-std = 1
+codegen-units-std = 0
# Whether or not debug assertions are enabled for the compiler and standard
# library.
@@ -327,7 +327,7 @@
#backtrace = true
# Whether to always use incremental compilation when building rustc
-#incremental = false
+incremental = true
# Build a multi-threaded rustc
#parallel-compiler = false
2700X on Linux
Modifying different crate or using more powerful CPU (like 3900X which is still considered as mainstream CPU) would beat 30s time.
I've just noticed that stage0 is executed again even with the --keep-stage 1 option.
$ ./x.py build -i --stage 1 --keep-stage 1 src/librustc
Updating only changed submodules
Submodules updated in 0.06 seconds
Finished dev [unoptimized] target(s) in 0.13s
Building stage0 std artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
Finished release [optimized] target(s) in 0.18s
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.13s
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)
Compiling rustc v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc)
Compiling rustc_metadata v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_metadata)
Compiling rustc_mir v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_mir)
Compiling rustc_incremental v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_incremental)
Compiling rustc_allocator v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_allocator)
Compiling rustc_typeck v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_typeck)
Compiling rustc_traits v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_traits)
Compiling rustc_lint v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_lint)
Compiling rustc_ast_borrowck v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_ast_borrowck)
Compiling rustc_codegen_utils v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_codegen_utils)
Compiling rustc_plugin v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_plugin)
Compiling rustc_resolve v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_resolve)
Compiling rustc_privacy v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_privacy)
Compiling rustc_codegen_ssa v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_codegen_ssa)
Compiling rustc_save_analysis v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_save_analysis)
Compiling rustc_passes v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_passes)
Compiling rustc_interface v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_interface)
Compiling rustc_driver v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_driver)
Compiling rustc-main v0.0.0 (/Users/ilijatovilo/Developer/rust/src/rustc)
Finished release [optimized] target(s) in 9m 42s
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)
Compiling rand_core v0.3.0
Compiling remove_dir_all v0.5.1
Compiling cfg-if v0.1.8
Compiling rustc-demangle v0.1.15
Compiling cc v1.0.35
Compiling libc v0.2.54
Compiling rustc_codegen_llvm v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_codegen_llvm)
Compiling rustc_llvm v0.0.0 (/Users/ilijatovilo/Developer/rust/src/librustc_llvm)
Compiling rand_pcg v0.1.1
Compiling rand_chacha v0.1.0
Compiling rand v0.6.1
Compiling rand_isaac v0.1.1
Compiling rand_hc v0.1.0
Compiling rand_xorshift v0.1.0
Compiling memmap v0.6.2
Compiling num_cpus v1.8.0
Compiling tempfile v3.0.5
Finished release [optimized] target(s) in 1m 38s
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)
Warning: Using a potentially old librustc. This may not behave well.
Copying stage1 rustc from stage1 (x86_64-apple-darwin -> x86_64-apple-darwin / x86_64-apple-darwin)
Build completed successfully in 0:11:24
And that's exactly where the majority of the time is spent.
EDIT
Maybe not? I don't see stage1 building, I'm seriously confused by this output.
I've just noticed that stage0 is executed again even with the
--keep-stage 1option.$ ./x.py build -i --stage 1 --keep-stage 1 src/librustcOutput
And that's exactly where the majority of the time is spent.
EDIT
Maybe not? I don't see stage1 building, I'm seriously confused by this output.
I believe that's the intended behavior. From the rustc guide:
A "stage N artifact" is an artifact that is produced by the stage N compiler.
The stage 0 artifacts being built in the output are being built _by_ the stage 0 compiler. The keep-stage 1 flag means that the std lib compiled by the previous stage 1 rustc is copied over for the current build, not that you start at stage 1. The stage 1 compiler is assembled using the stage 0 artifacts (as indicated by the line further down your output). Hope that makes sense.
Sorry for the delayed reply. I haven't tried this in a while, TBH. I'm glad to take a PR on the guide if it needs updating.
Most helpful comment
30 seconds does seem quite optimistic for a incremental compiler build (assuming any changes). This is probably just some wrong documentation. cc @mark-i-m