Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static ALLOWED_EMIT: Lazy<HashSet<&'static str>> =
/// 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<T>(
creator: &T,
crate_name: &str,
Expand Down Expand Up @@ -382,22 +382,25 @@ async fn get_compiler_outputs<T>(
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::<Vec<_>>();
trace!(
"get_compiler_outputs: got {} outputs in {}: {:?}",
outputs.len(),
fmt_duration_as_secs(&start.elapsed()),
outstr,
);
Ok(outputs)
}

impl Rust {
Expand Down Expand Up @@ -1382,6 +1385,20 @@ where
Ok((source_files, source_hashes, env_deps))
};

// Turn arguments into a simple Vec<OsString> to calculate outputs.
let flat_os_string_arguments: Vec<OsString> = 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",
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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<OsString> to calculate outputs.
let flat_os_string_arguments: Vec<OsString> = 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
Expand Down