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