@@ -138,21 +138,40 @@ impl<'a> Prepare<'a> {
138138 }
139139
140140 fn fetch_deps ( & mut self ) -> Result < ( ) , Error > {
141- let mut missing_deps = false ;
142- let res = Command :: new ( self . workspace , self . toolchain . cargo ( ) )
143- . args ( & [ "fetch" , "--manifest-path" , "Cargo.toml" ] )
144- . cd ( self . source_dir )
145- . process_lines ( & mut |line, _| {
146- if line. contains ( "failed to load source for dependency" ) {
147- missing_deps = true ;
148- }
149- } )
150- . run ( ) ;
151- match res {
152- Ok ( _) => Ok ( ( ) ) ,
153- Err ( _) if missing_deps => Err ( PrepareError :: MissingDependencies . into ( ) ) ,
154- err => err. map_err ( |e| e. into ( ) ) ,
155- }
141+ fetch_deps ( self . workspace , self . toolchain , self . source_dir , & [ ] )
142+ }
143+ }
144+
145+ pub ( crate ) fn fetch_deps (
146+ workspace : & Workspace ,
147+ toolchain : & Toolchain ,
148+ source_dir : & Path ,
149+ fetch_build_std_targets : & [ & str ] ,
150+ ) -> Result < ( ) , Error > {
151+ let mut missing_deps = false ;
152+ let mut cmd = Command :: new ( workspace, toolchain. cargo ( ) )
153+ . args ( & [ "fetch" , "--manifest-path" , "Cargo.toml" ] )
154+ . cd ( source_dir) ;
155+ // Pass `-Zbuild-std` in case a build in the sandbox wants to use it;
156+ // build-std has to have the source for libstd's dependencies available.
157+ if !fetch_build_std_targets. is_empty ( ) {
158+ toolchain. add_component ( workspace, "rust-src" ) ?;
159+ cmd = cmd. args ( & [ "-Zbuild-std" ] ) . env ( "RUSTC_BOOTSTRAP" , "1" ) ;
160+ }
161+ for target in fetch_build_std_targets {
162+ cmd = cmd. args ( & [ "--target" , target] ) ;
163+ }
164+ let res = cmd
165+ . process_lines ( & mut |line, _| {
166+ if line. contains ( "failed to load source for dependency" ) {
167+ missing_deps = true ;
168+ }
169+ } )
170+ . run ( ) ;
171+ match res {
172+ Ok ( _) => Ok ( ( ) ) ,
173+ Err ( _) if missing_deps => Err ( PrepareError :: MissingDependencies . into ( ) ) ,
174+ err => err. map_err ( |e| e. into ( ) ) ,
156175 }
157176}
158177
0 commit comments