Skip to content

Commit c57d2a9

Browse files
authored
Extend embuilder deferred building mode to ports (#23924)
This allows embuilder build ALL to mix the ports builds together with the system_libs builds, for even faster build-linux speed. Headers are still installed eagerly during ports.get() (to allow dependencies to build their object files) but does not run ninja to build the ports until the explicit step at the end.
1 parent c05d5fd commit c57d2a9

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

embuilder.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import argparse
1616
import fnmatch
1717
import logging
18+
import os
1819
import sys
1920
import time
2021
from contextlib import contextmanager
@@ -171,8 +172,8 @@ def clear_port(port_name):
171172

172173

173174
def build_port(port_name):
174-
with get_port_variant(port_name) as port_name:
175-
ports.build_port(port_name, settings)
175+
with get_port_variant(port_name) as port_name_base:
176+
ports.build_port(port_name_base, settings)
176177

177178

178179
def get_system_tasks():
@@ -281,6 +282,9 @@ def main():
281282
if auto_tasks:
282283
print('Building targets: %s' % ' '.join(tasks))
283284

285+
if USE_NINJA:
286+
os.environ['EMBUILDER_PORT_BUILD_DEFERRED'] = '1'
287+
284288
for what in tasks:
285289
for old, new in legacy_prefixes.items():
286290
if what.startswith(old):

tools/cache.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def get_lib(libname, *args, **kwargs):
152152

153153
# Request a cached file. If it isn't in the cache, it will be created with
154154
# the given creator function
155-
def get(shortname, creator, what=None, force=False, quiet=False, deferred=False):
155+
def get(shortname, creator, what=None, force=False, quiet=False):
156156
ensure_setup()
157157
cachename = Path(cachedir, shortname)
158158
# Check for existence before taking the lock in case we can avoid the
@@ -177,8 +177,12 @@ def get(shortname, creator, what=None, force=False, quiet=False, deferred=False)
177177
logger.info(message)
178178
utils.safe_ensure_dirs(cachename.parent)
179179
creator(str(cachename))
180-
if not deferred:
181-
assert cachename.exists()
180+
# In embuilder/deferred building mode, the library is not actually compiled at
181+
# "creation" time; instead, the ninja files are built up incrementally, and
182+
# compiled all at once with a single ninja invocation. So in that case we
183+
# can't assert that the library was correctly built here.
184+
if not os.getenv('EMBUILDER_PORT_BUILD_DEFERRED'):
185+
assert cachename.is_file()
182186
if not quiet:
183187
logger.info(' - ok')
184188

tools/ports/__init__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ def build_port(src_dir, output_path, port_name, includes=[], flags=[], cxxflags=
203203
ninja_file = os.path.join(build_dir, 'build.ninja')
204204
system_libs.ensure_sysroot()
205205
system_libs.create_ninja_file(srcs, ninja_file, output_path, cflags=cflags)
206-
system_libs.run_ninja(build_dir)
206+
if not os.getenv('EMBUILDER_PORT_BUILD_DEFERRED'):
207+
system_libs.run_ninja(build_dir)
207208
else:
208209
commands = []
209210
objects = []
@@ -577,9 +578,11 @@ def add_cflags(args, settings): # noqa: U100
577578
needed = get_needed_ports(settings)
578579

579580
# Now get (i.e. build) the ports in dependency order. This is important because the
580-
# headers from one ports might be needed before we can build the next.
581+
# headers from one port might be needed before we can build the next.
581582
for port in dependency_order(needed):
582-
port.get(Ports, settings, shared)
583+
# When using embuilder, don't build the dependencies
584+
if not os.getenv('EMBUILDER_PORT_BUILD_DEFERRED'):
585+
port.get(Ports, settings, shared)
583586
args += port.process_args(Ports)
584587

585588

tools/system_libs.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,7 @@ def build(self):
431431
return cache.get(self.get_path(), self.do_build, force=USE_NINJA == 2, quiet=USE_NINJA)
432432

433433
def generate(self):
434-
return cache.get(self.get_path(), self.do_generate, force=USE_NINJA == 2, quiet=USE_NINJA,
435-
deferred=True)
434+
return cache.get(self.get_path(), self.do_generate, force=USE_NINJA == 2, quiet=USE_NINJA)
436435

437436
def get_link_flag(self):
438437
"""

0 commit comments

Comments
 (0)