build_config,
profiles,
)?;
- ops::compile_targets(cx, &package_targets, export_dir.clone(), &exec)?
+ cx.compile(&package_targets, export_dir.clone(), &exec)?
};
ret.to_doc_test = to_builds.into_iter().cloned().collect();
use util::errors::{CargoResult, CargoResultExt};
use super::TargetConfig;
-use super::custom_build::{BuildDeps, BuildScripts, BuildState};
+use super::custom_build::{self, BuildDeps, BuildScripts, BuildState};
use super::fingerprint::Fingerprint;
+use super::job_queue::JobQueue;
use super::layout::Layout;
use super::links::Links;
-use super::{BuildConfig, Compilation, Kind};
+use super::{BuildConfig, Compilation, Executor, Kind, PackagesToBuild};
mod unit_dependencies;
use self::unit_dependencies::build_unit_dependencies;
Ok(cx)
}
+ // Returns a mapping of the root package plus its immediate dependencies to
+ // where the compiled libraries are all located.
+ pub fn compile(
+ mut self,
+ pkg_targets: &'a PackagesToBuild<'a>,
+ export_dir: Option<PathBuf>,
+ exec: &Arc<Executor>,
+ ) -> CargoResult<Compilation<'cfg>> {
+ let units = pkg_targets
+ .iter()
+ .flat_map(|&(pkg, ref targets)| {
+ let default_kind = if self.build_config.requested_target.is_some() {
+ Kind::Target
+ } else {
+ Kind::Host
+ };
+ targets.iter().map(move |&(target, profile)| Unit {
+ pkg,
+ target,
+ profile,
+ kind: if target.for_host() {
+ Kind::Host
+ } else {
+ default_kind
+ },
+ })
+ })
+ .collect::<Vec<_>>();
+
+ let mut queue = JobQueue::new(&self);
+ self.prepare_units(export_dir, &units)?;
+ self.prepare()?;
+ self.build_used_in_plugin_map(&units)?;
+ custom_build::build_map(&mut self, &units)?;
+
+ for unit in units.iter() {
+ // Build up a list of pending jobs, each of which represent
+ // compiling a particular package. No actual work is executed as
+ // part of this, that's all done next as part of the `execute`
+ // function which will run everything in order with proper
+ // parallelism.
+ super::compile(&mut self, &mut queue, unit, exec)?;
+ }
+
+ // Now that we've figured out everything that we're going to do, do it!
+ queue.execute(&mut self)?;
+
+ for unit in units.iter() {
+ for output in self.outputs(unit)?.iter() {
+ if output.flavor == FileFlavor::DebugInfo {
+ continue;
+ }
+
+ let bindst = match output.hardlink {
+ Some(ref link_dst) => link_dst,
+ None => &output.path,
+ };
+
+ if unit.profile.test {
+ self.compilation.tests.push((
+ unit.pkg.clone(),
+ unit.target.kind().clone(),
+ unit.target.name().to_string(),
+ output.path.clone(),
+ ));
+ } else if unit.target.is_bin() || unit.target.is_example() {
+ self.compilation.binaries.push(bindst.clone());
+ } else if unit.target.is_lib() {
+ let pkgid = unit.pkg.package_id().clone();
+ self.compilation
+ .libraries
+ .entry(pkgid)
+ .or_insert_with(HashSet::new)
+ .insert((unit.target.clone(), output.path.clone()));
+ }
+ }
+
+ for dep in self.dep_targets(unit).iter() {
+ if !unit.target.is_lib() {
+ continue;
+ }
+
+ if dep.profile.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().clone())
+ .or_insert_with(Vec::new)
+ .push(("OUT_DIR".to_string(), out_dir));
+ }
+
+ if !dep.target.is_lib() {
+ continue;
+ }
+ if dep.profile.doc {
+ continue;
+ }
+
+ let outputs = self.outputs(dep)?;
+ self.compilation
+ .libraries
+ .entry(unit.pkg.package_id().clone())
+ .or_insert_with(HashSet::new)
+ .extend(
+ outputs
+ .iter()
+ .map(|output| (dep.target.clone(), output.path.clone())),
+ );
+ }
+
+ let feats = self.resolve.features(unit.pkg.package_id());
+ if !feats.is_empty() {
+ self.compilation
+ .cfgs
+ .entry(unit.pkg.package_id().clone())
+ .or_insert_with(|| {
+ feats
+ .iter()
+ .map(|feat| format!("feature=\"{}\"", feat))
+ .collect()
+ });
+ }
+ let rustdocflags = self.rustdocflags_args(unit)?;
+ if !rustdocflags.is_empty() {
+ self.compilation
+ .rustdocflags
+ .entry(unit.pkg.package_id().clone())
+ .or_insert(rustdocflags);
+ }
+
+ super::output_depinfo(&mut self, unit)?;
+ }
+
+ for (&(ref pkg, _), output) in self.build_state.outputs.lock().unwrap().iter() {
+ self.compilation
+ .cfgs
+ .entry(pkg.clone())
+ .or_insert_with(HashSet::new)
+ .extend(output.cfgs.iter().cloned());
+
+ self.compilation
+ .extra_env
+ .entry(pkg.clone())
+ .or_insert_with(Vec::new)
+ .extend(output.env.iter().cloned());
+
+ for dir in output.library_paths.iter() {
+ self.compilation.native_dirs.insert(dir.clone());
+ }
+ }
+ self.compilation.target = self.target_triple().to_string();
+ Ok(self.compilation)
+ }
+
pub fn prepare_units(
&mut self,
export_dir: Option<PathBuf>,
-use std::collections::{HashMap, HashSet};
+use std::collections::HashMap;
use std::env;
use std::ffi::{OsStr, OsString};
use std::fs;
impl Executor for DefaultExecutor {}
-// Returns a mapping of the root package plus its immediate dependencies to
-// where the compiled libraries are all located.
-pub fn compile_targets<'a, 'cfg: 'a>(
- mut cx: Context<'a, 'cfg>,
- pkg_targets: &'a PackagesToBuild<'a>,
- export_dir: Option<PathBuf>,
- exec: &Arc<Executor>,
-) -> CargoResult<Compilation<'cfg>> {
- let units = pkg_targets
- .iter()
- .flat_map(|&(pkg, ref targets)| {
- let default_kind = if cx.build_config.requested_target.is_some() {
- Kind::Target
- } else {
- Kind::Host
- };
- targets.iter().map(move |&(target, profile)| Unit {
- pkg,
- target,
- profile,
- kind: if target.for_host() {
- Kind::Host
- } else {
- default_kind
- },
- })
- })
- .collect::<Vec<_>>();
-
- let mut queue = JobQueue::new(&cx);
- cx.prepare_units(export_dir, &units)?;
- cx.prepare()?;
- cx.build_used_in_plugin_map(&units)?;
- custom_build::build_map(&mut cx, &units)?;
-
- for unit in units.iter() {
- // Build up a list of pending jobs, each of which represent
- // compiling a particular package. No actual work is executed as
- // part of this, that's all done next as part of the `execute`
- // function which will run everything in order with proper
- // parallelism.
- compile(&mut cx, &mut queue, unit, exec)?;
- }
-
- // Now that we've figured out everything that we're going to do, do it!
- queue.execute(&mut cx)?;
-
- for unit in units.iter() {
- for output in cx.outputs(unit)?.iter() {
- if output.flavor == FileFlavor::DebugInfo {
- continue;
- }
-
- let bindst = match output.hardlink {
- Some(ref link_dst) => link_dst,
- None => &output.path,
- };
-
- if unit.profile.test {
- cx.compilation.tests.push((
- unit.pkg.clone(),
- unit.target.kind().clone(),
- unit.target.name().to_string(),
- output.path.clone(),
- ));
- } else if unit.target.is_bin() || unit.target.is_example() {
- cx.compilation.binaries.push(bindst.clone());
- } else if unit.target.is_lib() {
- let pkgid = unit.pkg.package_id().clone();
- cx.compilation
- .libraries
- .entry(pkgid)
- .or_insert_with(HashSet::new)
- .insert((unit.target.clone(), output.path.clone()));
- }
- }
-
- for dep in cx.dep_targets(unit).iter() {
- if !unit.target.is_lib() {
- continue;
- }
-
- if dep.profile.run_custom_build {
- let out_dir = cx.files().build_script_out_dir(dep).display().to_string();
- cx.compilation
- .extra_env
- .entry(dep.pkg.package_id().clone())
- .or_insert_with(Vec::new)
- .push(("OUT_DIR".to_string(), out_dir));
- }
-
- if !dep.target.is_lib() {
- continue;
- }
- if dep.profile.doc {
- continue;
- }
-
- let outputs = cx.outputs(dep)?;
- cx.compilation
- .libraries
- .entry(unit.pkg.package_id().clone())
- .or_insert_with(HashSet::new)
- .extend(
- outputs
- .iter()
- .map(|output| (dep.target.clone(), output.path.clone())),
- );
- }
-
- let feats = cx.resolve.features(unit.pkg.package_id());
- if !feats.is_empty() {
- cx.compilation
- .cfgs
- .entry(unit.pkg.package_id().clone())
- .or_insert_with(|| {
- feats
- .iter()
- .map(|feat| format!("feature=\"{}\"", feat))
- .collect()
- });
- }
- let rustdocflags = cx.rustdocflags_args(unit)?;
- if !rustdocflags.is_empty() {
- cx.compilation
- .rustdocflags
- .entry(unit.pkg.package_id().clone())
- .or_insert(rustdocflags);
- }
-
- output_depinfo(&mut cx, unit)?;
- }
-
- for (&(ref pkg, _), output) in cx.build_state.outputs.lock().unwrap().iter() {
- cx.compilation
- .cfgs
- .entry(pkg.clone())
- .or_insert_with(HashSet::new)
- .extend(output.cfgs.iter().cloned());
-
- cx.compilation
- .extra_env
- .entry(pkg.clone())
- .or_insert_with(Vec::new)
- .extend(output.env.iter().cloned());
-
- for dir in output.library_paths.iter() {
- cx.compilation.native_dirs.insert(dir.clone());
- }
- }
- cx.compilation.target = cx.target_triple().to_string();
- Ok(cx.compilation)
-}
-
fn compile<'a, 'cfg: 'a>(
cx: &mut Context<'a, 'cfg>,
jobs: &mut JobQueue<'a>,
pub use self::cargo_compile::{compile, compile_with_exec, compile_ws, CompileOptions};
pub use self::cargo_compile::{CompileFilter, CompileMode, FilterRule, MessageFormat, Packages};
pub use self::cargo_read_manifest::{read_package, read_packages};
-pub use self::cargo_rustc::{compile_targets, Compilation, Kind, Unit};
+pub use self::cargo_rustc::{Compilation, Kind, Unit};
pub use self::cargo_rustc::{is_bad_artifact_name, Context};
pub use self::cargo_rustc::{BuildConfig, BuildOutput, TargetConfig};
pub use self::cargo_rustc::{DefaultExecutor, Executor};