diff --git a/src/cargo/core/compiler/build_plan.rs b/src/cargo/core/compiler/build_plan.rs index d40d4a877f5..69e61970d79 100644 --- a/src/cargo/core/compiler/build_plan.rs +++ b/src/cargo/core/compiler/build_plan.rs @@ -113,9 +113,9 @@ impl BuildPlan { let id = self.plan.invocations.len(); self.invocation_map.insert(unit.buildkey(), id); let deps = cx - .dep_targets(unit) + .unit_deps(unit) .iter() - .map(|dep| self.invocation_map[&dep.buildkey()]) + .map(|dep| self.invocation_map[&dep.unit.buildkey()]) .collect(); let invocation = Invocation::new(unit, deps); self.plan.invocations.push(invocation); diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 33c6c536ecd..37dfa67210d 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -458,8 +458,8 @@ fn metadata_of<'a, 'cfg>( if !metas.contains_key(unit) { let meta = compute_metadata(unit, cx, metas); metas.insert(*unit, meta); - for unit in cx.dep_targets(unit) { - metadata_of(&unit, cx, metas); + for dep in cx.unit_deps(unit) { + metadata_of(&dep.unit, cx, metas); } } metas[unit].clone() @@ -532,15 +532,13 @@ fn compute_metadata<'a, 'cfg>( unit.features.hash(&mut hasher); // Mix in the target-metadata of all the dependencies of this target. - { - let mut deps_metadata = cx - .dep_targets(unit) - .iter() - .map(|dep| metadata_of(dep, cx, metas)) - .collect::>(); - deps_metadata.sort(); - deps_metadata.hash(&mut hasher); - } + let mut deps_metadata = cx + .unit_deps(unit) + .iter() + .map(|dep| metadata_of(&dep.unit, cx, metas)) + .collect::>(); + deps_metadata.sort(); + deps_metadata.hash(&mut hasher); // Throw in the profile we're compiling with. This helps caching // `panic=abort` and `panic=unwind` artifacts, additionally with various diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index d4acd1c7a9e..d64fe5a38be 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -187,18 +187,20 @@ impl<'a, 'cfg> Context<'a, 'cfg> { // If the unit has a build script, add `OUT_DIR` to the // environment variables. - for dep in self.dep_targets(unit).iter() { - if !unit.target.is_lib() { - continue; - } - - if dep.mode.is_run_custom_build() { - let out_dir = self.files().build_script_out_dir(dep).display().to_string(); - self.compilation - .extra_env - .entry(dep.pkg.package_id()) - .or_insert_with(Vec::new) - .push(("OUT_DIR".to_string(), out_dir)); + if unit.target.is_lib() { + for dep in &self.unit_dependencies[unit] { + if dep.unit.mode.is_run_custom_build() { + let out_dir = self + .files() + .build_script_out_dir(&dep.unit) + .display() + .to_string(); + self.compilation + .extra_env + .entry(dep.unit.pkg.package_id()) + .or_insert_with(Vec::new) + .push(("OUT_DIR".to_string(), out_dir)); + } } } @@ -361,18 +363,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> { self.files.as_ref().unwrap().outputs(unit, self.bcx) } - /// For a package, return all targets which are registered as dependencies - /// for that package. - /// NOTE: This is deprecated, use `unit_deps` instead. - // - // TODO: this ideally should be `-> &[Unit<'a>]`. - pub fn dep_targets(&self, unit: &Unit<'a>) -> Vec> { - self.unit_dependencies[unit] - .iter() - .map(|dep| dep.unit) - .collect() - } - /// Direct dependencies for the given unit. pub fn unit_deps(&self, unit: &Unit<'a>) -> &[UnitDep<'a>] { &self.unit_dependencies[unit] diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index aedaf447b7a..b68e2536cd2 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -133,10 +133,11 @@ fn emit_build_output( fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult { assert!(unit.mode.is_run_custom_build()); let bcx = &cx.bcx; - let dependencies = cx.dep_targets(unit); + let dependencies = cx.unit_deps(unit); let build_script_unit = dependencies .iter() - .find(|d| !d.mode.is_run_custom_build() && d.target.is_custom_build()) + .find(|d| !d.unit.mode.is_run_custom_build() && d.unit.target.is_custom_build()) + .map(|d| &d.unit) .expect("running a script not depending on an actual script"); let script_dir = cx.files().build_script_dir(build_script_unit); let script_out_dir = cx.files().build_script_out_dir(unit); @@ -225,21 +226,19 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes // // This information will be used at build-time later on to figure out which // sorts of variables need to be discovered at that time. - let lib_deps = { - dependencies - .iter() - .filter_map(|unit| { - if unit.mode.is_run_custom_build() { - Some(( - unit.pkg.manifest().links().unwrap().to_string(), - unit.pkg.package_id(), - )) - } else { - None - } - }) - .collect::>() - }; + let lib_deps = dependencies + .iter() + .filter_map(|dep| { + if dep.unit.mode.is_run_custom_build() { + Some(( + dep.unit.pkg.manifest().links().unwrap().to_string(), + dep.unit.pkg.package_id(), + )) + } else { + None + } + }) + .collect::>(); let pkg_name = unit.pkg.to_string(); let build_script_outputs = Arc::clone(&cx.build_script_outputs); let id = unit.pkg.package_id(); @@ -563,15 +562,15 @@ fn prepare_metabuild<'a, 'cfg>( deps: &[String], ) -> CargoResult<()> { let mut output = Vec::new(); - let available_deps = cx.dep_targets(unit); + let available_deps = cx.unit_deps(unit); // Filter out optional dependencies, and look up the actual lib name. let meta_deps: Vec<_> = deps .iter() .filter_map(|name| { available_deps .iter() - .find(|u| u.pkg.name().as_str() == name.as_str()) - .map(|dep| dep.target.crate_name()) + .find(|d| d.unit.pkg.name().as_str() == name.as_str()) + .map(|d| d.unit.target.crate_name()) }) .collect(); for dep in &meta_deps { @@ -669,7 +668,7 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>, units: &[Unit<'b>]) -> Ca // to rustc invocation caching schemes, so be sure to generate the same // set of build script dependency orderings via sorting the targets that // come out of the `Context`. - let mut dependencies = cx.dep_targets(unit); + let mut dependencies: Vec> = cx.unit_deps(unit).iter().map(|d| d.unit).collect(); dependencies.sort_by_key(|u| u.pkg.package_id()); for dep_unit in dependencies.iter() { diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index f7a65b963a1..9d378f2cafe 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -159,26 +159,25 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> { unit: &Unit<'a>, job: Job, ) -> CargoResult<()> { - let dependencies = cx.dep_targets(unit); + let dependencies = cx.unit_deps(unit); let mut queue_deps = dependencies .iter() - .cloned() - .filter(|unit| { + .filter(|dep| { // Binaries aren't actually needed to *compile* tests, just to run // them, so we don't include this dependency edge in the job graph. - !unit.target.is_test() && !unit.target.is_bin() + !dep.unit.target.is_test() && !dep.unit.target.is_bin() }) .map(|dep| { // Handle the case here where our `unit -> dep` dependency may // only require the metadata, not the full compilation to // finish. Use the tables in `cx` to figure out what kind // of artifact is associated with this dependency. - let artifact = if cx.only_requires_rmeta(unit, &dep) { + let artifact = if cx.only_requires_rmeta(unit, &dep.unit) { Artifact::Metadata } else { Artifact::All }; - (dep, artifact) + (dep.unit, artifact) }) .collect::>(); @@ -205,7 +204,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> { // transitively contains the `Metadata` edge. if unit.requires_upstream_objects() { for dep in dependencies { - depend_on_deps_of_deps(cx, &mut queue_deps, dep); + depend_on_deps_of_deps(cx, &mut queue_deps, dep.unit); } fn depend_on_deps_of_deps<'a>( @@ -213,9 +212,9 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> { deps: &mut HashMap, Artifact>, unit: Unit<'a>, ) { - for dep in cx.dep_targets(&unit) { - if deps.insert(dep, Artifact::All).is_none() { - depend_on_deps_of_deps(cx, deps, dep); + for dep in cx.unit_deps(&unit) { + if deps.insert(dep.unit, Artifact::All).is_none() { + depend_on_deps_of_deps(cx, deps, dep.unit); } } } diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 99fa9874739..36084e25e1f 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -157,8 +157,9 @@ fn compile<'a, 'cfg: 'a>( drop(p); // Be sure to compile all dependencies of this target as well. - for unit in cx.dep_targets(unit).iter() { - compile(cx, jobs, plan, unit, exec, false)?; + let deps = Vec::from(cx.unit_deps(unit)); // Create vec due to mutable borrow. + for dep in deps { + compile(cx, jobs, plan, &dep.unit, exec, false)?; } if build_plan { plan.add(cx, unit)?; diff --git a/src/cargo/core/compiler/output_depinfo.rs b/src/cargo/core/compiler/output_depinfo.rs index b77f28eba94..b6e3d4606f0 100644 --- a/src/cargo/core/compiler/output_depinfo.rs +++ b/src/cargo/core/compiler/output_depinfo.rs @@ -90,10 +90,11 @@ fn add_deps_for_unit<'a, 'b>( } // Recursively traverse all transitive dependencies - for dep_unit in context.dep_targets(unit).iter() { - let source_id = dep_unit.pkg.package_id().source_id(); + let unit_deps = Vec::from(context.unit_deps(unit)); // Create vec due to mutable borrow. + for dep in unit_deps { + let source_id = dep.unit.pkg.package_id().source_id(); if source_id.is_path() { - add_deps_for_unit(deps, context, dep_unit, visited)?; + add_deps_for_unit(deps, context, &dep.unit, visited)?; } } Ok(())