@@ -34,118 +34,14 @@ impl Sysroot {
3434 } ;
3535
3636 download. get_and_extract ( ModuleVariant :: Rustc ) ?;
37- // HACK(eddyb) commented out because we build our own stdlib
38- // (see `fn build_std` below).
39- // download.get_and_extract(ModuleVariant::Std)?;
37+ download. get_and_extract ( ModuleVariant :: Std ) ?;
4038 download. get_and_extract ( ModuleVariant :: Cargo ) ?;
4139 download. get_and_extract ( ModuleVariant :: RustSrc ) ?;
4240
43- let sysroot_dir = download. directory . join ( & download. rust_sha ) ;
4441 let sysroot = download. into_sysroot ( ) ?;
4542
46- // FIXME(eddyb) remove this once we no longer need to
47- // build our own stdlib (see `fn build_std` below).
48- sysroot. build_std ( sysroot_dir) ?;
49-
5043 Ok ( sysroot)
5144 }
52-
53- /// Build `std`+`test`+`proc_macro` in a similar way to Cargo's `-Zbuild-std`
54- /// feature, but only once, and move the resulting libraries into the sysroot.
55- ///
56- /// We only need this until https://github.com/rust-lang/cargo/pull/8073
57- /// reaches beta, because then `rust-lang/rust` builds will have that
58- /// treatment. For now, we only have access to that Cargo change here,
59- /// using the newly built Cargo.
60- ///
61- /// For more background on why we need this, see this comment:
62- /// https://github.com/rust-lang/rust/issues/69060#issuecomment-604928032
63- /// (in short, Cargo used to include `rustc -vV` output, which contains
64- /// the commit hash, into `-Cmetadata`, producing different `std`s,
65- /// and making the perf runs incomparable, up to several % of difference).
66- fn build_std ( & self , sysroot_dir : PathBuf ) -> anyhow:: Result < ( ) > {
67- // Make sure everything below gets absolute directories.
68- let sysroot_dir = sysroot_dir. canonicalize ( ) ?;
69-
70- let sysroot_rustlib_dir = sysroot_dir. join ( "lib/rustlib" ) ;
71- let rust_src_dir = sysroot_rustlib_dir. join ( "src/rust" ) ;
72-
73- // HACK(eddyb) add a top-level `Cargo.toml` that has the necessary
74- // `patch.crates-io` entries for `rustc-std-workspace-{core,alloc,std}`.
75- // (maybe `rust-src` should include such a `Cargo.toml`?)
76- fs:: write (
77- rust_src_dir. join ( "Cargo.toml" ) ,
78- "\
79- [workspace]
80- members = ['src/libtest']
81-
82- [patch.crates-io]
83- # See comments in `tools/rustc-std-workspace-core/README.md` for what's going on
84- # here
85- rustc-std-workspace-core = { path = 'src/tools/rustc-std-workspace-core' }
86- rustc-std-workspace-alloc = { path = 'src/tools/rustc-std-workspace-alloc' }
87- rustc-std-workspace-std = { path = 'src/tools/rustc-std-workspace-std' }
88- " ,
89- ) ?;
90-
91- // HACK(eddyb) we need `std` to run the build scripts to build `std`.
92- let vanilla_sysroot_dir = {
93- let vanilla_download = SysrootDownload {
94- directory : sysroot_dir. join ( "vanilla-sysroot" ) ,
95- rust_sha : self . sha . clone ( ) ,
96- triple : self . triple . clone ( ) ,
97- } ;
98- vanilla_download. get_and_extract ( ModuleVariant :: Std ) ?;
99- vanilla_download. directory . join ( vanilla_download. rust_sha )
100- } ;
101-
102- let rustflags = format ! (
103- "--sysroot={sysroot} --remap-path-prefix={remap_from}={remap_to}" ,
104- sysroot = vanilla_sysroot_dir. display( ) ,
105- remap_from = rust_src_dir. display( ) ,
106- remap_to = "/rustc/REDACTED_SHA_HASH/"
107- ) ;
108-
109- // Run Cargo to produce `$local_build_target_dir/release/deps/lib*.rlib`.
110- let local_build_target_dir = sysroot_dir. join ( "build-std-target" ) ;
111- let cargo_status = std:: process:: Command :: new ( & self . cargo )
112- . env ( "RUSTC" , & self . rustc )
113- . env ( "RUSTFLAGS" , rustflags)
114- . env ( "__CARGO_DEFAULT_LIB_METADATA" , "rustc-perf-std" )
115- . args ( & [ "build" , "--release" ] )
116- . arg ( "--target-dir" )
117- . arg ( & local_build_target_dir)
118- . args ( & [ "--features" , "panic-unwind" , "--features" , "backtrace" ] )
119- . arg ( "--manifest-path" )
120- . arg ( rust_src_dir. join ( "src/libtest/Cargo.toml" ) )
121- . status ( ) ?;
122- if !cargo_status. success ( ) {
123- return Err ( anyhow ! (
124- "unable to build stdlib for {} triple {}" ,
125- self . sha,
126- self . triple
127- ) ) ;
128- }
129-
130- // Move all of the `rlib` files into the main sysroot.
131- let sysroot_target_lib_dir = sysroot_rustlib_dir. join ( & self . triple ) . join ( "lib" ) ;
132- fs:: create_dir_all ( & sysroot_target_lib_dir) ?;
133- for entry in fs:: read_dir ( local_build_target_dir. join ( "release/deps" ) ) ? {
134- let entry = entry?;
135- let path = entry. path ( ) ;
136- if let ( Some ( name) , Some ( ext) ) = ( path. file_name ( ) , path. extension ( ) ) {
137- if ext == "rlib" {
138- fs:: rename ( & path, sysroot_target_lib_dir. join ( name) ) ?;
139- }
140- }
141- }
142-
143- // Clean up, to avoid accidental usage of these directories.
144- fs:: remove_dir_all ( vanilla_sysroot_dir) ?;
145- fs:: remove_dir_all ( local_build_target_dir) ?;
146-
147- Ok ( ( ) )
148- }
14945}
15046
15147impl Drop for Sysroot {
0 commit comments