@@ -302,8 +302,28 @@ def extra(self) -> str:
302
302
return "," .join (flags )
303
303
304
304
305
+ def generate_cargo_build_command (
306
+ bins : List [str ],
307
+ examples : List [str ],
308
+ rd : RepositoryDetails ,
309
+ ) -> List [str ]:
310
+ rustflags = rustc_flags .coverage if rd .coverage else []
311
+
312
+ cargo_build = [* rd .cargo ("build" , channel = None , rustflags = rustflags )]
313
+
314
+ for bin in bins :
315
+ cargo_build .extend (["--bin" , bin ])
316
+ for example in examples :
317
+ cargo_build .extend (["--example" , example ])
318
+
319
+ if rd .release_mode :
320
+ cargo_build .append ("--release" )
321
+
322
+ return cargo_build
323
+
324
+
305
325
class CargoBuild (CargoPreImage ):
306
- """A pre-image action that builds a single binary with Cargo."""
326
+ """A pre-image action that builds individual binaries with Cargo."""
307
327
308
328
def __init__ (self , rd : RepositoryDetails , path : Path , config : Dict [str , Any ]):
309
329
super ().__init__ (rd , path )
@@ -314,26 +334,10 @@ def __init__(self, rd: RepositoryDetails, path: Path, config: Dict[str, Any]):
314
334
self .strip = config .pop ("strip" , True )
315
335
self .split_debuginfo = config .pop ("split_debuginfo" , False )
316
336
self .extract = config .pop ("extract" , {})
317
- self .rustflags = config .pop ("rustflags" , [])
318
- self .channel = None
319
- if rd .coverage :
320
- self .rustflags += rustc_flags .coverage
321
337
if len (self .bins ) == 0 and len (self .examples ) == 0 :
322
338
raise ValueError ("mzbuild config is missing pre-build target" )
323
339
324
340
def build (self ) -> None :
325
- cargo_build = [
326
- * self .rd .cargo ("build" , channel = self .channel , rustflags = self .rustflags )
327
- ]
328
-
329
- for bin in self .bins :
330
- cargo_build .extend (["--bin" , bin ])
331
- for example in self .examples :
332
- cargo_build .extend (["--example" , example ])
333
-
334
- if self .rd .release_mode :
335
- cargo_build .append ("--release" )
336
- spawn .runv (cargo_build , cwd = self .rd .root )
337
341
cargo_profile = "release" if self .rd .release_mode else "debug"
338
342
339
343
def copy (exe : Path ) -> None :
@@ -392,6 +396,10 @@ def copy(exe: Path) -> None:
392
396
copy (Path ("examples" ) / example )
393
397
394
398
if self .extract :
399
+ cargo_build = generate_cargo_build_command (
400
+ self .bins , self .examples , self .rd
401
+ )
402
+
395
403
output = spawn .capture (
396
404
cargo_build + ["--message-format=json" ],
397
405
cwd = self .rd .root ,
@@ -584,6 +592,16 @@ def build(self) -> None:
584
592
for dep in self .dependencies .values ():
585
593
dep .acquire ()
586
594
spawn .runv (["git" , "clean" , "-ffdX" , self .image .path ])
595
+ bins = []
596
+ examples = []
597
+ for pre_image in self .image .pre_images :
598
+ if isinstance (pre_image , CargoBuild ):
599
+ bins .extend (pre_image .bins )
600
+ examples .extend (pre_image .examples )
601
+
602
+ cargo_build = generate_cargo_build_command (bins , examples , self .image .rd )
603
+ spawn .runv (cargo_build , cwd = self .image .rd .root )
604
+
587
605
for pre_image in self .image .pre_images :
588
606
pre_image .run ()
589
607
build_args = {
0 commit comments