pub fn resolve_std<'cfg>(
    ws: &Workspace<'cfg>,
    target_data: &RustcTargetData,
    requested_target: CompileKind,
    crates: &[String],
) -> CargoResult<(PackageSet<'cfg>, Resolve, ResolvedFeatures)> {
    let src_path = detect_sysroot_src_path(target_data)?;
    let to_patch = [
        "rustc-std-workspace-core",
        "rustc-std-workspace-alloc",
        "rustc-std-workspace-std",
    ];
    let patches = to_patch
        .iter()
        .map(|&name| {
            let source_path = SourceId::for_path(&src_path.join("src").join("tools").join(name))?;
            let dep = Dependency::parse_no_deprecated(name, None, source_path)?;
            Ok(dep)
        })
        .collect::<CargoResult<Vec<_>>>()?;
    let crates_io_url = crate::sources::CRATES_IO_INDEX.parse().unwrap();
    let mut patch = HashMap::new();
    patch.insert(crates_io_url, patches);
    let members = vec![
        String::from("src/libstd"),
        String::from("src/libcore"),
        String::from("src/liballoc"),
        String::from("src/libtest"),
    ];
    let ws_config = crate::core::WorkspaceConfig::Root(crate::core::WorkspaceRootConfig::new(
        &src_path,
        &Some(members),
        /*default_members*/ &None,
        /*exclude*/ &None,
    ));
    let virtual_manifest = crate::core::VirtualManifest::new(
        /*replace*/ Vec::new(),
        patch,
        ws_config,
        /*profiles*/ None,
        crate::core::Features::default(),
    );

    let config = ws.config();
    // This is a delicate hack. In order for features to resolve correctly,
    // the resolver needs to run a specific "current" member of the workspace.
    // Thus, in order to set the features for `std`, we need to set `libtest`
    // to be the "current" member. `libtest` is the root, and all other
    // standard library crates are dependencies from there. Since none of the
    // other crates need to alter their features, this should be fine, for
    // now. Perhaps in the future features will be decoupled from the resolver
    // and it will be easier to control feature selection.
    let current_manifest = src_path.join("src/libtest/Cargo.toml");
    // TODO: Consider doing something to enforce --locked? Or to prevent the
    // lock file from being written, such as setting ephemeral.
    let mut std_ws = Workspace::new_virtual(src_path, current_manifest, virtual_manifest, config)?;
    // Don't require optional dependencies in this workspace, aka std's own
    // `[dev-dependencies]`. No need for us to generate a `Resolve` which has
    // those included because we'll never use them anyway.
    std_ws.set_require_optional_deps(false);
    // `test` is not in the default set because it is optional, but it needs
    // to be part of the resolve in case we do need it.
    let mut spec_pkgs = Vec::from(crates);
    spec_pkgs.push("test".to_string());
    let spec = Packages::Packages(spec_pkgs);
    let specs = spec.to_package_id_specs(&std_ws)?;
    let features = vec!["panic-unwind".to_string(), "backtrace".to_string()];
    // dev_deps setting shouldn't really matter here.
    let opts = ResolveOpts::new(
        /*dev_deps*/ false, &features, /*all_features*/ false,
        /*uses_default_features*/ true,
    );
    let resolve = ops::resolve_ws_with_opts(
        &std_ws,
        target_data,
        requested_target,
        &opts,
        &specs,
        HasDevUnits::No,
    )?;
    Ok((
        resolve.pkg_set,
        resolve.targeted_resolve,
        resolve.resolved_features,
    ))
}
/// Resolve the standard library dependencies.
Resolve the standard library dependencies.
Resolve the standard library dependencies .
pub fn resolve_std<'cfg>(
    ws: &Workspace<'cfg>,
    target_data: &RustcTargetData,
    requested_target: CompileKind,
    crates: &[String],
) -> CargoResult<(PackageSet<'cfg>, Resolve, ResolvedFeatures)> {
    let src_path = detect_sysroot_src_path(target_data)?;
    let to_patch = [
        "rustc-std-workspace-core",
        "rustc-std-workspace-alloc",
        "rustc-std-workspace-std",
    ];
    let patches = to_patch
        .iter()
        .map(|&name| {
            let source_path = SourceId::for_path(&src_path.join("src").join("tools").join(name))?;
            let dep = Dependency::parse_no_deprecated(name, None, source_path)?;
            Ok(dep)
        })
        .collect::<CargoResult<Vec<_>>>()?;
    let crates_io_url = crate::sources::CRATES_IO_INDEX.parse().unwrap();
    let mut patch = HashMap::new();
    patch.insert(crates_io_url, patches);
    let members = vec![
        String::from("src/libstd"),
        String::from("src/libcore"),
        String::from("src/liballoc"),
        String::from("src/libtest"),
    ];
    let ws_config = crate::core::WorkspaceConfig::Root(crate::core::WorkspaceRootConfig::new(
        &src_path,
        &Some(members),
        /*default_members*/ &None,
        /*exclude*/ &None,
    ));
    let virtual_manifest = crate::core::VirtualManifest::new(
        /*replace*/ Vec::new(),
        patch,
        ws_config,
        /*profiles*/ None,
        crate::core::Features::default(),
    );
    let config = ws.config();
    // This is a delicate hack. In order for features to resolve correctly,
    // the resolver needs to run a specific "current" member of the workspace.
    // Thus, in order to set the features for `std`, we need to set `libtest`
    // to be the "current" member. `libtest` is the root, and all other
    // standard library crates are dependencies from there. Since none of the
    // other crates need to alter their features, this should be fine, for
    // now. Perhaps in the future features will be decoupled from the resolver
    // and it will be easier to control feature selection.
    let current_manifest = src_path.join("src/libtest/Cargo.toml");
    // TODO: Consider doing something to enforce --locked? Or to prevent the
    // lock file from being written, such as setting ephemeral.
    let mut std_ws = Workspace::new_virtual(src_path, current_manifest, virtual_manifest, config)?;
    // Don't require optional dependencies in this workspace, aka std's own
    // `[dev-dependencies]`. No need for us to generate a `Resolve` which has
    // those included because we'll never use them anyway.
    std_ws.set_require_optional_deps(false);
    // `test` is not in the default set because it is optional, but it needs
    // to be part of the resolve in case we do need it.
    let mut spec_pkgs = Vec::from(crates);
    spec_pkgs.push("test".to_string());
    let spec = Packages::Packages(spec_pkgs);
    let specs = spec.to_package_id_specs(&std_ws)?;
    let features = vec!["panic-unwind".to_string(), "backtrace".to_string()];
    // dev_deps setting shouldn't really matter here.
    let opts = ResolveOpts::new(
        /*dev_deps*/ false, &features, /*all_features*/ false,
        /*uses_default_features*/ true,
    );
    let resolve = ops::resolve_ws_with_opts(
        &std_ws,
        target_data,
        requested_target,
        &opts,
        &specs,
        HasDevUnits::No,
    )?;
    Ok((
        resolve.pkg_set,
        resolve.targeted_resolve,
        resolve.resolved_features,
    ))
}
pub fn resolve_std < ' cfg > ( ws : & Workspace < ' cfg > , target_data : & RustcTargetData , requested_target : CompileKind , crates : & [ String ] , ) -> CargoResult < ( PackageSet < ' cfg > , Resolve , ResolvedFeatures ) > { let src_path = detect_sysroot_src_path ( target_data ) ? ; let to_patch = [ " " , " " , " " , ] ; let patches = to_patch . iter ( ) . map ( | & name | { let source_path = SourceId :: for_path ( & src_path . join ( " " ) . join ( " " ) . join ( name ) ) ? ; let dep = Dependency :: parse_no_deprecated ( name , None , source_path ) ? ; Ok ( dep ) } ) . collect :: < CargoResult < Vec < _ > > > ( ) ? ; let crates_io_url = crate :: sources :: CRATES_IO_INDEX . parse ( ) . unwrap ( ) ; let mut patch = HashMap :: new ( ) ; patch . insert ( crates_io_url , patches ) ; let members = vec ! [ String from ( " " ) String from ( " " ) String from ( " " ) String from ( " " ) ] ; let ws_config = crate :: core :: WorkspaceConfig :: Root ( crate :: core :: WorkspaceRootConfig :: new ( & src_path , & Some ( members ) , /*default_members*/ & None , /*exclude*/ & None , ) ) ; let virtual_manifest = crate :: core :: VirtualManifest :: new ( /*replace*/ Vec :: new ( ) , patch , ws_config , /*profiles*/ None , crate :: core :: Features :: default ( ) , ) ; let config = ws . config ( ) ; // This is a delicate hack. In order for features to resolve correctly, // the resolver needs to run a specific "current" member of the workspace. // Thus, in order to set the features for `std`, we need to set `libtest` // to be the "current" member. `libtest` is the root, and all other // standard library crates are dependencies from there. Since none of the // other crates need to alter their features, this should be fine, for // now. Perhaps in the future features will be decoupled from the resolver // and it will be easier to control feature selection. let current_manifest = src_path . join ( " " ) ; // TODO: Consider doing something to enforce --locked? Or to prevent the // lock file from being written, such as setting ephemeral. let mut std_ws = Workspace :: new_virtual ( src_path , current_manifest , virtual_manifest , config ) ? ; // Don't require optional dependencies in this workspace, aka std's own // `[dev-dependencies]`. No need for us to generate a `Resolve` which has // those included because we'll never use them anyway. std_ws . set_require_optional_deps ( false ) ; // `test` is not in the default set because it is optional, but it needs // to be part of the resolve in case we do need it. let mut spec_pkgs = Vec :: from ( crates ) ; spec_pkgs . push ( " " . to_string ( ) ) ; let spec = Packages :: Packages ( spec_pkgs ) ; let specs = spec . to_package_id_specs ( & std_ws ) ? ; let features = vec ! [ " " to_string ( ) " " to_string ( ) ] ; // dev_deps setting shouldn't really matter here. let opts = ResolveOpts :: new ( /*dev_deps*/ false , & features , /*all_features*/ false , /*uses_default_features*/ true , ) ; let resolve = ops :: resolve_ws_with_opts ( & std_ws , target_data , requested_target , & opts , & specs , HasDevUnits :: No , ) ? ; Ok ( ( resolve . pkg_set , resolve . targeted_resolve , resolve . resolved_features , ) ) }
Resolve the standard library dependencies.
Resolve the standard library dependencies .
ws
&Workspace<'cfg>
target_data
&RustcTargetData
requested_target
CompileKind
crates
&[String]
ws
&Workspace<'cfg>
target_data
&RustcTargetData
requested_target
CompileKind
crates
&[String]