@@ -7,10 +7,9 @@ use crate::core::resolver::features::{FeaturesFor, ResolvedFeatures};
77use crate :: core:: resolver:: { HasDevUnits , ResolveOpts } ;
88use crate :: core:: { Dependency , PackageId , PackageSet , Resolve , SourceId , Workspace } ;
99use crate :: ops:: { self , Packages } ;
10- use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
10+ use crate :: util:: errors:: CargoResult ;
1111use std:: collections:: { HashMap , HashSet } ;
1212use std:: env;
13- use std:: fs;
1413use std:: path:: PathBuf ;
1514
1615/// Parse the `-Zbuild-std` flag.
@@ -39,48 +38,28 @@ pub fn resolve_std<'cfg>(
3938 crates : & [ String ] ,
4039) -> CargoResult < ( PackageSet < ' cfg > , Resolve , ResolvedFeatures ) > {
4140 let src_path = detect_sysroot_src_path ( target_data) ?;
42-
43- // Special std packages should be pulled from `library/` and should be
44- // prefixed with `rustc-std-workspace-` in certain places.
45- let libs_prefix = "library/" ;
46- let special_std_prefix = "rustc-std-workspace-" ;
47- let libs_path = src_path. join ( libs_prefix) ;
48-
49- // Crates in rust-src to build. libtest is in some sense the "root" package
50- // of std, as nothing else depends on it, so it must be explicitly added.
51- let mut members = vec ! [ format!( "{}test" , libs_prefix) ] ;
52-
53- // If rust-src contains a "vendor" directory, then patch in all the crates it contains.
54- let vendor_path = src_path. join ( "vendor" ) ;
55- let vendor_dir = fs:: read_dir ( & vendor_path)
56- . chain_err ( || format ! ( "could not read vendor path {}" , vendor_path. display( ) ) ) ?;
57- let patches = vendor_dir
58- . into_iter ( )
59- . map ( |entry| {
60- let entry = entry?;
61- let name = entry
62- . file_name ( )
63- . into_string ( )
64- . map_err ( |_| anyhow:: anyhow!( "package name wasn't utf8" ) ) ?;
65-
66- // Remap the rustc-std-workspace crates to the actual rust-src libraries
67- let path = if let Some ( real_name) = name. strip_prefix ( special_std_prefix) {
68- // Record this crate as something to build in the workspace
69- members. push ( format ! ( "{}{}" , libs_prefix, real_name) ) ;
70- libs_path. join ( & name)
71- } else {
72- entry. path ( )
73- } ;
74- let source_path = SourceId :: for_path ( & path) ?;
75- let dep = Dependency :: parse_no_deprecated ( & name, None , source_path) ?;
41+ let to_patch = [
42+ "rustc-std-workspace-core" ,
43+ "rustc-std-workspace-alloc" ,
44+ "rustc-std-workspace-std" ,
45+ ] ;
46+ let patches = to_patch
47+ . iter ( )
48+ . map ( |& name| {
49+ let source_path = SourceId :: for_path ( & src_path. join ( "library" ) . join ( name) ) ?;
50+ let dep = Dependency :: parse_no_deprecated ( name, None , source_path) ?;
7651 Ok ( dep)
7752 } )
78- . collect :: < CargoResult < Vec < _ > > > ( )
79- . chain_err ( || "failed to generate vendor patches" ) ?;
80-
53+ . collect :: < CargoResult < Vec < _ > > > ( ) ?;
8154 let crates_io_url = crate :: sources:: CRATES_IO_INDEX . parse ( ) . unwrap ( ) ;
8255 let mut patch = HashMap :: new ( ) ;
8356 patch. insert ( crates_io_url, patches) ;
57+ let members = vec ! [
58+ String :: from( "library/std" ) ,
59+ String :: from( "library/core" ) ,
60+ String :: from( "library/alloc" ) ,
61+ String :: from( "library/test" ) ,
62+ ] ;
8463 let ws_config = crate :: core:: WorkspaceConfig :: Root ( crate :: core:: WorkspaceRootConfig :: new (
8564 & src_path,
8665 & Some ( members) ,
0 commit comments