@@ -13,6 +13,7 @@ use clap::Parser;
1313
1414use crate :: config:: { Config , VendorMode } ;
1515use crate :: context:: Context ;
16+ use crate :: lockfile:: { lock_context, write_lockfile} ;
1617use crate :: metadata:: CargoUpdateRequest ;
1718use crate :: metadata:: TreeResolver ;
1819use crate :: metadata:: { Annotations , Cargo , Generator , MetadataGenerator , VendorGenerator } ;
@@ -44,6 +45,10 @@ pub struct VendorOptions {
4445 #[ clap( long) ]
4546 pub splicing_manifest : PathBuf ,
4647
48+ /// The path to write a Bazel lockfile
49+ #[ clap( long) ]
50+ pub lockfile : Option < PathBuf > ,
51+
4752 /// The path to a [Cargo.lock](https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html) file.
4853 #[ clap( long) ]
4954 pub cargo_lockfile : Option < PathBuf > ,
@@ -205,8 +210,8 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
205210 . unwrap_or_else ( |path| panic ! ( "Temporary directory wasn't valid UTF-8: {:?}" , path) ) ;
206211
207212 // Generate a splicer for creating a Cargo workspace manifest
208- let splicer =
209- Splicer :: new ( temp_dir_path , splicing_manifest ) . context ( "Failed to create splicer" ) ?;
213+ let splicer = Splicer :: new ( temp_dir_path , splicing_manifest . clone ( ) )
214+ . context ( "Failed to create splicer" ) ?;
210215
211216 let cargo = Cargo :: new ( opt. cargo , opt. rustc . clone ( ) ) ;
212217
@@ -261,7 +266,7 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
261266 // Render build files
262267 let outputs = Renderer :: new (
263268 Arc :: new ( config. rendering . clone ( ) ) ,
264- Arc :: new ( config. supported_platform_triples ) ,
269+ Arc :: new ( config. supported_platform_triples . clone ( ) ) ,
265270 )
266271 . render ( & context, None ) ?;
267272
@@ -280,7 +285,7 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
280285 }
281286
282287 if matches ! ( config. rendering. vendor_mode, Some ( VendorMode :: Local ) ) {
283- VendorGenerator :: new ( cargo, opt. rustc . clone ( ) )
288+ VendorGenerator :: new ( cargo. clone ( ) , opt. rustc . clone ( ) )
284289 . generate ( manifest_path. as_path_buf ( ) , & vendor_dir)
285290 . context ( "Failed to vendor dependencies" ) ?;
286291 }
@@ -311,6 +316,13 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
311316 }
312317 }
313318
319+ // Write the rendering lockfile if requested.
320+ if let Some ( lockfile) = opt. lockfile {
321+ let lock_content = lock_context ( context, & config, & splicing_manifest, & cargo, & opt. rustc ) ?;
322+
323+ write_lockfile ( lock_content, & lockfile, opt. dry_run ) ?;
324+ }
325+
314326 Ok ( ( ) )
315327}
316328
0 commit comments