@@ -13,6 +13,7 @@ use clap::Parser;
13
13
14
14
use crate :: config:: { Config , VendorMode } ;
15
15
use crate :: context:: Context ;
16
+ use crate :: lockfile:: { lock_context, write_lockfile} ;
16
17
use crate :: metadata:: CargoUpdateRequest ;
17
18
use crate :: metadata:: TreeResolver ;
18
19
use crate :: metadata:: { Annotations , Cargo , Generator , MetadataGenerator , VendorGenerator } ;
@@ -44,6 +45,10 @@ pub struct VendorOptions {
44
45
#[ clap( long) ]
45
46
pub splicing_manifest : PathBuf ,
46
47
48
+ /// The path to write a Bazel lockfile
49
+ #[ clap( long) ]
50
+ pub lockfile : Option < PathBuf > ,
51
+
47
52
/// The path to a [Cargo.lock](https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html) file.
48
53
#[ clap( long) ]
49
54
pub cargo_lockfile : Option < PathBuf > ,
@@ -205,8 +210,8 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
205
210
. unwrap_or_else ( |path| panic ! ( "Temporary directory wasn't valid UTF-8: {:?}" , path) ) ;
206
211
207
212
// 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" ) ?;
210
215
211
216
let cargo = Cargo :: new ( opt. cargo , opt. rustc . clone ( ) ) ;
212
217
@@ -261,7 +266,7 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
261
266
// Render build files
262
267
let outputs = Renderer :: new (
263
268
Arc :: new ( config. rendering . clone ( ) ) ,
264
- Arc :: new ( config. supported_platform_triples ) ,
269
+ Arc :: new ( config. supported_platform_triples . clone ( ) ) ,
265
270
)
266
271
. render ( & context, None ) ?;
267
272
@@ -280,7 +285,7 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
280
285
}
281
286
282
287
if matches ! ( config. rendering. vendor_mode, Some ( VendorMode :: Local ) ) {
283
- VendorGenerator :: new ( cargo, opt. rustc . clone ( ) )
288
+ VendorGenerator :: new ( cargo. clone ( ) , opt. rustc . clone ( ) )
284
289
. generate ( manifest_path. as_path_buf ( ) , & vendor_dir)
285
290
. context ( "Failed to vendor dependencies" ) ?;
286
291
}
@@ -311,6 +316,13 @@ pub fn vendor(opt: VendorOptions) -> anyhow::Result<()> {
311
316
}
312
317
}
313
318
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
+
314
326
Ok ( ( ) )
315
327
}
316
328
0 commit comments