@@ -487,15 +487,17 @@ def build_objects(self, build_dir):
487
487
By default, this builds all the source files returned by `self.get_files()`,
488
488
with the `cflags` returned by `self.get_cflags()`.
489
489
"""
490
+ batch_inputs = int (os .environ .get ('EMCC_BATCH_BUILD' , '1' ))
490
491
batches = {}
491
492
commands = []
492
493
objects = set ()
493
494
cflags = self .get_cflags ()
494
495
if self .deterministic_paths :
495
496
source_dir = utils .path_from_root ()
496
- relative_source_dir = os .path .relpath (source_dir , build_dir )
497
+ if batch_inputs :
498
+ relative_source_dir = os .path .relpath (source_dir , build_dir )
499
+ cflags += [f'-ffile-prefix-map={ relative_source_dir } /=' ]
497
500
cflags += [f'-ffile-prefix-map={ source_dir } =/emsdk/emscripten' ,
498
- f'-ffile-prefix-map={ relative_source_dir } /=' ,
499
501
'-fdebug-compilation-dir=/emsdk/emscripten' ]
500
502
case_insensitive = is_case_insensitive (build_dir )
501
503
for src in self .get_files ():
@@ -531,24 +533,27 @@ def build_objects(self, build_dir):
531
533
object_uuid += 1
532
534
o = os .path .join (build_dir , f'{ object_basename } __{ object_uuid } .o' )
533
535
commands .append (cmd + [src , '-o' , o ])
534
- else :
536
+ elif batch_inputs :
535
537
# Use relative paths to reduce the length of the command line.
536
538
# This allows to avoid switching to a response file as often.
537
539
src = os .path .relpath (src , build_dir )
538
540
src = utils .normalize_path (src )
539
541
batches .setdefault (tuple (cmd ), []).append (src )
542
+ else :
543
+ commands .append (cmd + [src , '-o' , o ])
540
544
objects .add (o )
541
545
542
- # Choose a chunk size that is large enough to avoid too many subprocesses
543
- # but not too large to avoid task starvation.
544
- # For now the heuristic is to split inputs by 2x number of cores.
545
- chunk_size = max (1 , len (objects ) // (2 * shared .get_num_cores ()))
546
- # Convert batches to commands.
547
- for cmd , srcs in batches .items ():
548
- cmd = list (cmd )
549
- for i in range (0 , len (srcs ), chunk_size ):
550
- chunk_srcs = srcs [i :i + chunk_size ]
551
- commands .append (building .get_command_with_possible_response_file (cmd + chunk_srcs ))
546
+ if batch_inputs :
547
+ # Choose a chunk size that is large enough to avoid too many subprocesses
548
+ # but not too large to avoid task starvation.
549
+ # For now the heuristic is to split inputs by 2x number of cores.
550
+ chunk_size = max (1 , len (objects ) // (2 * shared .get_num_cores ()))
551
+ # Convert batches to commands.
552
+ for cmd , srcs in batches .items ():
553
+ cmd = list (cmd )
554
+ for i in range (0 , len (srcs ), chunk_size ):
555
+ chunk_srcs = srcs [i :i + chunk_size ]
556
+ commands .append (building .get_command_with_possible_response_file (cmd + chunk_srcs ))
552
557
553
558
run_build_commands (commands , num_inputs = len (objects ), build_dir = build_dir )
554
559
return objects
0 commit comments