diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index 6857c4ad5..7ff711f96 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -238,7 +238,7 @@ static ALLOWED_EMIT: Lazy> = /// Version number for cache key. const CACHE_VERSION: &[u8] = b"6"; -/// Get absolute paths for all source files and env-deps listed in rustc's dep-info output. +/// Run `rustc --emit=dep-info` to get the list of source files and env-deps. async fn get_source_files_and_env_deps( creator: &T, crate_name: &str, @@ -382,22 +382,25 @@ async fn get_compiler_outputs( where T: Clone + CommandCreatorSync, { + let start = time::Instant::now(); let mut cmd = creator.clone().new_command_sync(executable); cmd.args(&arguments) .args(&["--print", "file-names"]) .env_clear() .envs(env_vars.to_vec()) .current_dir(cwd); - if log_enabled!(Trace) { - trace!("get_compiler_outputs: {:?}", cmd); - } + trace!("get_compiler_outputs: {:?}", cmd); let outputs = run_input_output(cmd, None).await?; let outstr = String::from_utf8(outputs.stdout).context("Error parsing rustc output")?; - if log_enabled!(Trace) { - trace!("get_compiler_outputs: {:?}", outstr); - } - Ok(outstr.lines().map(|l| l.to_owned()).collect()) + let outputs = outstr.lines().map(|l| l.to_owned()).collect::>(); + trace!( + "get_compiler_outputs: got {} outputs in {}: {:?}", + outputs.len(), + fmt_duration_as_secs(&start.elapsed()), + outstr, + ); + Ok(outputs) } impl Rust { @@ -1382,6 +1385,20 @@ where Ok((source_files, source_hashes, env_deps)) }; + // Turn arguments into a simple Vec to calculate outputs. + let flat_os_string_arguments: Vec = os_string_arguments + .iter() + .cloned() + .flat_map(|(arg, val)| iter::once(arg).chain(val)) + .collect(); + let outputs = get_compiler_outputs( + creator, + &self.executable, + flat_os_string_arguments, + &cwd, + &env_vars, + ); + // Hash the contents of the externs listed on the commandline. trace!( "[{}]: hashing {} externs", @@ -1423,17 +1440,19 @@ where let target_json_hash = hash_all(&target_json_files, pool); - // Perform all hashing operations on the files. + // Invoke the compiler and perform all hashing operations on the files. let ( (source_files, source_hashes, mut env_deps), extern_hashes, staticlib_hashes, target_json_hash, + mut outputs, ) = futures::try_join!( source_files_and_hashes_and_env_deps, extern_hashes, staticlib_hashes, - target_json_hash + target_json_hash, + outputs, )?; // If you change any of the inputs to the hash, you should change `CACHE_VERSION`. @@ -1539,21 +1558,6 @@ where // 10. The version of the compiler. self.version.hash(&mut HashToDigest { digest: &mut m }); - // Turn arguments into a simple Vec to calculate outputs. - let flat_os_string_arguments: Vec = os_string_arguments - .into_iter() - .flat_map(|(arg, val)| iter::once(arg).chain(val)) - .collect(); - - let mut outputs = get_compiler_outputs( - creator, - &self.executable, - flat_os_string_arguments, - &cwd, - &env_vars, - ) - .await?; - // metadata / dep-info don't ever generate binaries, but // rustc still makes them appear in the --print // file-names output (see