pub fn compile_targets<'a, 'cfg: 'a>(pkg_targets: &'a PackagesToBuild<'a>,
                                     deps: &'a PackageSet,
                                     resolve: &'a Resolve,
                                     sources: &'a SourceMap<'cfg>,
                                     config: &'cfg Config,
                                     build_config: BuildConfig,
                                     profiles: &'a Profiles)
                                     -> CargoResult<Compilation<'cfg>> {
    let units = pkg_targets.iter().flat_map(|&(pkg, ref targets)| {
        let default_kind = if build_config.requested_target.is_some() {
            Kind::Target
        } else {
            Kind::Host
        };
        targets.iter().map(move |&(target, profile)| {
            Unit {
                pkg: pkg,
                target: target,
                profile: profile,
                kind: if target.for_host() {Kind::Host} else {default_kind},
            }
        })
    }).collect::<Vec<_>>();
    try!(links::validate(deps));

    let dest = if build_config.release {"release"} else {"debug"};
    let root = deps.iter().find(|p| p.package_id() == resolve.root()).unwrap();
    let host_layout = Layout::new(config, root, None, &dest);
    let target_layout = build_config.requested_target.as_ref().map(|target| {
        layout::Layout::new(config, root, Some(&target), &dest)
    });

    let mut cx = try!(Context::new(resolve, sources, deps, config,
                                   host_layout, target_layout,
                                   build_config, profiles));

    let mut queue = JobQueue::new(&cx);

    try!(cx.prepare(root));
    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.
        try!(compile(&mut cx, &mut queue, unit));
    }

    // Now that we've figured out everything that we're going to do, do it!
    try!(queue.execute(cx.config));

    for unit in units.iter() {
        let out_dir = cx.layout(unit.pkg, unit.kind).build_out(unit.pkg)
                        .display().to_string();
        cx.compilation.extra_env.entry(unit.pkg.package_id().clone())
          .or_insert(Vec::new())
          .push(("OUT_DIR".to_string(), out_dir));

        for filename in try!(cx.target_filenames(unit)).iter() {
            let dst = cx.out_dir(unit).join(filename);
            if unit.profile.test {
                cx.compilation.tests.push((unit.pkg.clone(),
                                           unit.target.name().to_string(),
                                           dst));
            } else if unit.target.is_bin() || unit.target.is_example() {
                cx.compilation.binaries.push(dst);
            } else if unit.target.is_lib() {
                let pkgid = unit.pkg.package_id().clone();
                cx.compilation.libraries.entry(pkgid).or_insert(Vec::new())
                  .push((unit.target.clone(), dst));
            }
            if !unit.target.is_lib() { continue }

            // Include immediate lib deps as well
            for unit in cx.dep_targets(unit).iter() {
                let pkgid = unit.pkg.package_id();
                if !unit.target.is_lib() { continue }
                if unit.profile.doc { continue }
                if cx.compilation.libraries.contains_key(&pkgid) {
                    continue
                }

                let v = try!(cx.target_filenames(unit));
                let v = v.into_iter().map(|f| {
                    (unit.target.clone(), cx.out_dir(unit).join(f))
                }).collect::<Vec<_>>();
                cx.compilation.libraries.insert(pkgid.clone(), v);
            }
        }
    }

    let root_pkg = root.package_id();
    if let Some(feats) = cx.resolve.features(root_pkg) {
        cx.compilation.cfgs.extend(feats.iter().map(|feat| {
            format!("feature=\"{}\"", feat)
        }));
    }

    for (&(ref pkg, _), output) in cx.build_state.outputs.lock().unwrap().iter() {
        if pkg == root_pkg {
            cx.compilation.cfgs.extend(output.cfgs.iter().cloned());
        }
        for dir in output.library_paths.iter() {
            cx.compilation.native_dirs.insert(pkg.clone(), dir.clone());
        }
    }
    Ok(cx.compilation)
}
// Returns a mapping of the root package plus its immediate dependencies to
// where the compiled libraries are all located.
Returns a mapping of the root package plus its immediate dependencies to
where the compiled libraries are all located.
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>(pkg_targets: &'a PackagesToBuild<'a>,
                                     deps: &'a PackageSet,
                                     resolve: &'a Resolve,
                                     sources: &'a SourceMap<'cfg>,
                                     config: &'cfg Config,
                                     build_config: BuildConfig,
                                     profiles: &'a Profiles)
                                     -> CargoResult<Compilation<'cfg>> {
    let units = pkg_targets.iter().flat_map(|&(pkg, ref targets)| {
        let default_kind = if build_config.requested_target.is_some() {
            Kind::Target
        } else {
            Kind::Host
        };
        targets.iter().map(move |&(target, profile)| {
            Unit {
                pkg: pkg,
                target: target,
                profile: profile,
                kind: if target.for_host() {Kind::Host} else {default_kind},
            }
        })
    }).collect::<Vec<_>>();
    try!(links::validate(deps));
    let dest = if build_config.release {"release"} else {"debug"};
    let root = deps.iter().find(|p| p.package_id() == resolve.root()).unwrap();
    let host_layout = Layout::new(config, root, None, &dest);
    let target_layout = build_config.requested_target.as_ref().map(|target| {
        layout::Layout::new(config, root, Some(&target), &dest)
    });
    let mut cx = try!(Context::new(resolve, sources, deps, config,
                                   host_layout, target_layout,
                                   build_config, profiles));
    let mut queue = JobQueue::new(&cx);
    try!(cx.prepare(root));
    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.
        try!(compile(&mut cx, &mut queue, unit));
    }
    // Now that we've figured out everything that we're going to do, do it!
    try!(queue.execute(cx.config));
    for unit in units.iter() {
        let out_dir = cx.layout(unit.pkg, unit.kind).build_out(unit.pkg)
                        .display().to_string();
        cx.compilation.extra_env.entry(unit.pkg.package_id().clone())
          .or_insert(Vec::new())
          .push(("OUT_DIR".to_string(), out_dir));
        for filename in try!(cx.target_filenames(unit)).iter() {
            let dst = cx.out_dir(unit).join(filename);
            if unit.profile.test {
                cx.compilation.tests.push((unit.pkg.clone(),
                                           unit.target.name().to_string(),
                                           dst));
            } else if unit.target.is_bin() || unit.target.is_example() {
                cx.compilation.binaries.push(dst);
            } else if unit.target.is_lib() {
                let pkgid = unit.pkg.package_id().clone();
                cx.compilation.libraries.entry(pkgid).or_insert(Vec::new())
                  .push((unit.target.clone(), dst));
            }
            if !unit.target.is_lib() { continue }
            // Include immediate lib deps as well
            for unit in cx.dep_targets(unit).iter() {
                let pkgid = unit.pkg.package_id();
                if !unit.target.is_lib() { continue }
                if unit.profile.doc { continue }
                if cx.compilation.libraries.contains_key(&pkgid) {
                    continue
                }
                let v = try!(cx.target_filenames(unit));
                let v = v.into_iter().map(|f| {
                    (unit.target.clone(), cx.out_dir(unit).join(f))
                }).collect::<Vec<_>>();
                cx.compilation.libraries.insert(pkgid.clone(), v);
            }
        }
    }
    let root_pkg = root.package_id();
    if let Some(feats) = cx.resolve.features(root_pkg) {
        cx.compilation.cfgs.extend(feats.iter().map(|feat| {
            format!("feature=\"{}\"", feat)
        }));
    }
    for (&(ref pkg, _), output) in cx.build_state.outputs.lock().unwrap().iter() {
        if pkg == root_pkg {
            cx.compilation.cfgs.extend(output.cfgs.iter().cloned());
        }
        for dir in output.library_paths.iter() {
            cx.compilation.native_dirs.insert(pkg.clone(), dir.clone());
        }
    }
    Ok(cx.compilation)
}
pub fn compile_targets < ' a , ' cfg : ' a > ( pkg_targets : & ' a PackagesToBuild < ' a > , deps : & ' a PackageSet , resolve : & ' a Resolve , sources : & ' a SourceMap < ' cfg > , config : & ' cfg Config , build_config : BuildConfig , profiles : & ' a Profiles ) -> CargoResult < Compilation < ' cfg > > { let units = pkg_targets . iter ( ) . flat_map ( | & ( pkg , ref targets ) | { let default_kind = if build_config . requested_target . is_some ( ) { Kind :: Target } else { Kind :: Host } ; targets . iter ( ) . map ( move | & ( target , profile ) | { Unit { pkg : pkg , target : target , profile : profile , kind : if target . for_host ( ) { Kind :: Host } else { default_kind } , } } ) } ) . collect :: < Vec < _ > > ( ) ; try ! ( links validate ( deps ) ) ; let dest = if build_config . release { " " } else { " " } ; let root = deps . iter ( ) . find ( | p | p . package_id ( ) == resolve . root ( ) ) . unwrap ( ) ; let host_layout = Layout :: new ( config , root , None , & dest ) ; let target_layout = build_config . requested_target . as_ref ( ) . map ( | target | { layout :: Layout :: new ( config , root , Some ( & target ) , & dest ) } ) ; let mut cx = try ! ( Context new ( resolve sources deps config host_layout target_layout build_config profiles ) ) ; let mut queue = JobQueue :: new ( & cx ) ; try ! ( cx prepare ( root ) ) ; 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. try ! ( compile ( mut cx mut queue unit ) ) ; } // Now that we've figured out everything that we're going to do, do it! try ! ( queue execute ( cx config ) ) ; for unit in units . iter ( ) { let out_dir = cx . layout ( unit . pkg , unit . kind ) . build_out ( unit . pkg ) . display ( ) . to_string ( ) ; cx . compilation . extra_env . entry ( unit . pkg . package_id ( ) . clone ( ) ) . or_insert ( Vec :: new ( ) ) . push ( ( " " . to_string ( ) , out_dir ) ) ; for filename in try ! ( cx target_filenames ( unit ) ) . iter ( ) { let dst = cx . out_dir ( unit ) . join ( filename ) ; if unit . profile . test { cx . compilation . tests . push ( ( unit . pkg . clone ( ) , unit . target . name ( ) . to_string ( ) , dst ) ) ; } else if unit . target . is_bin ( ) || unit . target . is_example ( ) { cx . compilation . binaries . push ( dst ) ; } else if unit . target . is_lib ( ) { let pkgid = unit . pkg . package_id ( ) . clone ( ) ; cx . compilation . libraries . entry ( pkgid ) . or_insert ( Vec :: new ( ) ) . push ( ( unit . target . clone ( ) , dst ) ) ; } if ! unit . target . is_lib ( ) { continue } // Include immediate lib deps as well for unit in cx . dep_targets ( unit ) . iter ( ) { let pkgid = unit . pkg . package_id ( ) ; if ! unit . target . is_lib ( ) { continue } if unit . profile . doc { continue } if cx . compilation . libraries . contains_key ( & pkgid ) { continue } let v = try ! ( cx target_filenames ( unit ) ) ; let v = v . into_iter ( ) . map ( | f | { ( unit . target . clone ( ) , cx . out_dir ( unit ) . join ( f ) ) } ) . collect :: < Vec < _ > > ( ) ; cx . compilation . libraries . insert ( pkgid . clone ( ) , v ) ; } } } let root_pkg = root . package_id ( ) ; if let Some ( feats ) = cx . resolve . features ( root_pkg ) { cx . compilation . cfgs . extend ( feats . iter ( ) . map ( | feat | { format ! ( " \" \" " feat ) } ) ) ; } for ( & ( ref pkg , _ ) , output ) in cx . build_state . outputs . lock ( ) . unwrap ( ) . iter ( ) { if pkg == root_pkg { cx . compilation . cfgs . extend ( output . cfgs . iter ( ) . cloned ( ) ) ; } for dir in output . library_paths . iter ( ) { cx . compilation . native_dirs . insert ( pkg . clone ( ) , dir . clone ( ) ) ; } } Ok ( cx . compilation ) }
Returns a mapping of the root package plus its immediate dependencies to
where the compiled libraries are all located.
Returns a mapping of the root package plus its immediate dependencies to where the compiled libraries are all located .
pkg_targets
&'a PackagesToBuild<'a>
deps
&'a PackageSet
resolve
&'a Resolve
sources
&'a SourceMap<'cfg>
config
&'cfg Config
build_config
BuildConfig
profiles
&'a Profiles
pkg_targets
&'a PackagesToBuild<'a>
deps
&'a PackageSet
resolve
&'a Resolve
sources
&'a SourceMap<'cfg>
config
&'cfg Config
build_config
BuildConfig
profiles
&'a Profiles