Skip to content

Commit a5617df

Browse files
committed
Auto merge of #5716 - kennytm:unstable-compile-progress, r=alexcrichton
Reintroduce the compile progress bar as an unstable feature (-Z compile-progress) This allows us to test the feature on-demand to see if there's any other bugs besides #5695. Also, fixed the flickering #5697 (this was caused by build script emitting Stdout/Stderr events).
2 parents 15e6361 + 9612be6 commit a5617df

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

src/bin/cargo/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Available unstable (nightly-only) flags:
2222
-Z offline -- Offline mode that does not perform network requests
2323
-Z unstable-options -- Allow the usage of unstable options such as --registry
2424
-Z config-profile -- Read profiles from .cargo/config files
25+
-Z compile-progress -- Display a progress bar while compiling
2526
2627
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
2728
);

src/cargo/core/compiler/job_queue.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,13 @@ impl<'a> JobQueue<'a> {
190190
// bar we'll need to probably capture the stderr of rustc and
191191
// capture compiler error messages, but that also means
192192
// reproducing rustc's styling of error messages which is
193-
// currently a pretty big task. This is issue #5695. Note that
194-
// when reenabling it'd also probably be good to fix #5697 while
195-
// we're at it.
193+
// currently a pretty big task. This is issue #5695.
196194
let mut error = None;
197195
let mut progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
198-
progress.disable();
196+
let mut progress_maybe_changed = true; // avoid flickering due to build script
197+
if !cx.bcx.config.cli_unstable().compile_progress {
198+
progress.disable();
199+
}
199200
let total = self.queue.len();
200201
loop {
201202
// Dequeue as much work as we can, learning about everything
@@ -240,14 +241,23 @@ impl<'a> JobQueue<'a> {
240241
// to the jobserver itself.
241242
tokens.truncate(self.active.len() - 1);
242243

243-
let count = total - self.queue.len();
244-
let active_names = self.active.iter().map(|key| match key.mode {
245-
CompileMode::Doc { .. } => format!("{}(doc)", key.pkg.name()),
246-
_ => key.pkg.name().to_string(),
247-
}).collect::<Vec<_>>();
248-
drop(progress.tick_now(count, total, &format!(": {}", active_names.join(", "))));
244+
if progress_maybe_changed {
245+
let count = total - self.queue.len();
246+
let active_names = self.active.iter().map(|key| match key.mode {
247+
CompileMode::Doc { .. } => format!("{}(doc)", key.pkg.name()),
248+
_ => key.pkg.name().to_string(),
249+
}).collect::<Vec<_>>();
250+
drop(progress.tick_now(count, total, &format!(": {}", active_names.join(", "))));
251+
}
249252
let event = self.rx.recv().unwrap();
250-
progress.clear();
253+
254+
progress_maybe_changed = match event {
255+
Message::Stdout(_) | Message::Stderr(_) => cx.bcx.config.extra_verbose(),
256+
_ => true,
257+
};
258+
if progress_maybe_changed {
259+
progress.clear();
260+
}
251261

252262
match event {
253263
Message::Run(cmd) => {

src/cargo/core/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ pub struct CliUnstable {
311311
pub package_features: bool,
312312
pub advanced_env: bool,
313313
pub config_profile: bool,
314+
pub compile_progress: bool,
314315
}
315316

316317
impl CliUnstable {
@@ -347,6 +348,7 @@ impl CliUnstable {
347348
"package-features" => self.package_features = true,
348349
"advanced-env" => self.advanced_env = true,
349350
"config-profile" => self.config_profile = true,
351+
"compile-progress" => self.compile_progress = true,
350352
_ => bail!("unknown `-Z` flag specified: {}", k),
351353
}
352354

src/doc/src/reference/unstable.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,19 @@ Example:
292292
```
293293
cargo +nightly build --build-plan -Z unstable-options
294294
```
295+
296+
### Compile progress
297+
* Tracking Issue: [rust-lang/cargo#2536](https://github.com/rust-lang/cargo/issues/2536)
298+
299+
The `-Z compile-progress` flag enables a progress bar while compiling.
300+
301+
```console
302+
$ cargo +nightly build -Z compile-progress
303+
Compiling libc v0.2.41
304+
Compiling void v1.0.2
305+
Compiling lazy_static v1.0.1
306+
Compiling regex v1.0.0
307+
Compiling ucd-util v0.1.1
308+
Compiling utf8-ranges v1.0.0
309+
Building [=======> ] 2/14: libc, regex, uc...
310+
```

0 commit comments

Comments
 (0)