Skip to content

Commit d9e7b56

Browse files
authored
Add switch to disable batching of inputs when building system libs (#20929)
Basically gives emscripten developers a way to opt out of #20577. I've found it useful for debugging to build just one file at time and have absolute (not relative) paths in the build commands. This allows me to copy and paste a single failing command and run it in isolation when working on system library changes.
1 parent dddcae4 commit d9e7b56

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

tools/system_libs.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,17 @@ def build_objects(self, build_dir):
487487
By default, this builds all the source files returned by `self.get_files()`,
488488
with the `cflags` returned by `self.get_cflags()`.
489489
"""
490+
batch_inputs = int(os.environ.get('EMCC_BATCH_BUILD', '1'))
490491
batches = {}
491492
commands = []
492493
objects = set()
493494
cflags = self.get_cflags()
494495
if self.deterministic_paths:
495496
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}/=']
497500
cflags += [f'-ffile-prefix-map={source_dir}=/emsdk/emscripten',
498-
f'-ffile-prefix-map={relative_source_dir}/=',
499501
'-fdebug-compilation-dir=/emsdk/emscripten']
500502
case_insensitive = is_case_insensitive(build_dir)
501503
for src in self.get_files():
@@ -531,24 +533,27 @@ def build_objects(self, build_dir):
531533
object_uuid += 1
532534
o = os.path.join(build_dir, f'{object_basename}__{object_uuid}.o')
533535
commands.append(cmd + [src, '-o', o])
534-
else:
536+
elif batch_inputs:
535537
# Use relative paths to reduce the length of the command line.
536538
# This allows to avoid switching to a response file as often.
537539
src = os.path.relpath(src, build_dir)
538540
src = utils.normalize_path(src)
539541
batches.setdefault(tuple(cmd), []).append(src)
542+
else:
543+
commands.append(cmd + [src, '-o', o])
540544
objects.add(o)
541545

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))
552557

553558
run_build_commands(commands, num_inputs=len(objects), build_dir=build_dir)
554559
return objects

0 commit comments

Comments
 (0)