@@ -46,12 +46,12 @@ pub(crate) struct Vendor {
4646 pub ( crate ) versioned_dirs : bool ,
4747 /// The root directory of the source code.
4848 pub ( crate ) root_dir : PathBuf ,
49- /// The target directory for storing vendored dependencies.
50- pub ( crate ) output_dir : PathBuf ,
49+ /// The target directory for storing vendored dependencies if different from root_dir .
50+ pub ( crate ) output_dir : Option < PathBuf > ,
5151}
5252
5353impl Step for Vendor {
54- type Output = VendorOutput ;
54+ type Output = ( ) ;
5555 const DEFAULT : bool = true ;
5656 const ONLY_HOSTS : bool = true ;
5757
@@ -64,15 +64,15 @@ impl Step for Vendor {
6464 sync_args : run. builder . config . cmd . vendor_sync_args ( ) ,
6565 versioned_dirs : run. builder . config . cmd . vendor_versioned_dirs ( ) ,
6666 root_dir : run. builder . src . clone ( ) ,
67- output_dir : run . builder . src . join ( VENDOR_DIR ) ,
67+ output_dir : None ,
6868 } ) ;
6969 }
7070
7171 /// Executes the vendoring process.
7272 ///
7373 /// This function runs `cargo vendor` and ensures all required submodules
7474 /// are initialized before vendoring begins.
75- fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
75+ fn run ( self , builder : & Builder < ' _ > ) {
7676 builder. info ( & format ! ( "Vendoring sources to {:?}" , self . root_dir) ) ;
7777
7878 let mut cmd = command ( & builder. initial_cargo ) ;
@@ -105,15 +105,19 @@ impl Step for Vendor {
105105 cmd. env ( "RUSTC_BOOTSTRAP" , "1" ) ;
106106 cmd. env ( "RUSTC" , & builder. initial_rustc ) ;
107107
108- cmd. current_dir ( self . root_dir ) . arg ( & self . output_dir ) ;
108+ cmd. current_dir ( & self . root_dir ) . arg ( if let Some ( output_dir) = & self . output_dir {
109+ output_dir. join ( VENDOR_DIR )
110+ } else {
111+ // Make sure to use a relative path here to ensure dist tarballs
112+ // can be unpacked to a different drectory.
113+ VENDOR_DIR . into ( )
114+ } ) ;
109115
110116 let config = cmd. run_capture_stdout ( builder) ;
111- VendorOutput { config : config. stdout ( ) }
112- }
113- }
114117
115- /// Stores the result of the vendoring step.
116- #[ derive( Debug , Clone ) ]
117- pub ( crate ) struct VendorOutput {
118- pub ( crate ) config : String ,
118+ // Write .cargo/config.toml
119+ let cargo_config_dir = self . output_dir . unwrap_or ( self . root_dir ) . join ( ".cargo" ) ;
120+ builder. create_dir ( & cargo_config_dir) ;
121+ builder. create ( & cargo_config_dir. join ( "config.toml" ) , & config. stdout ( ) ) ;
122+ }
119123}
0 commit comments