Skip to content

Extend embuilder deferred building mode to ports #23924

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import argparse
import fnmatch
import logging
import os
import sys
import time
from contextlib import contextmanager
Expand Down Expand Up @@ -171,8 +172,8 @@ def clear_port(port_name):


def build_port(port_name):
with get_port_variant(port_name) as port_name:
ports.build_port(port_name, settings)
with get_port_variant(port_name) as port_name_base:
ports.build_port(port_name_base, settings)


def get_system_tasks():
Expand Down Expand Up @@ -281,6 +282,9 @@ def main():
if auto_tasks:
print('Building targets: %s' % ' '.join(tasks))

if USE_NINJA:
os.environ['EMBUILDER_PORT_BUILD_DEFERRED'] = '1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So its not currently possible use ninja in non-deferred mode? I guess thats OK?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ninja still works in non-deferred mode. If you do EMCC_USE_NINJA=1 test/runner.py core0 it will build the libraries on-demand in non-deferred mode with ninja. Deferred mode only makes sense when using embuilder though.


for what in tasks:
for old, new in legacy_prefixes.items():
if what.startswith(old):
Expand Down
6 changes: 3 additions & 3 deletions tools/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get_lib(libname, *args, **kwargs):

# Request a cached file. If it isn't in the cache, it will be created with
# the given creator function
def get(shortname, creator, what=None, force=False, quiet=False, deferred=False):
def get(shortname, creator, what=None, force=False, quiet=False):
ensure_setup()
cachename = Path(cachedir, shortname)
# Check for existence before taking the lock in case we can avoid the
Expand All @@ -177,8 +177,8 @@ def get(shortname, creator, what=None, force=False, quiet=False, deferred=False)
logger.info(message)
utils.safe_ensure_dirs(cachename.parent)
creator(str(cachename))
if not deferred:
assert cachename.exists()
if not os.getenv('EMBUILDER_PORT_BUILD_DEFERRED'):
assert cachename.is_file()
if not quiet:
logger.info(' - ok')

Expand Down
9 changes: 6 additions & 3 deletions tools/ports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def build_port(src_dir, output_path, port_name, includes=[], flags=[], cxxflags=
ninja_file = os.path.join(build_dir, 'build.ninja')
system_libs.ensure_sysroot()
system_libs.create_ninja_file(srcs, ninja_file, output_path, cflags=cflags)
system_libs.run_ninja(build_dir)
if not os.getenv('EMBUILDER_PORT_BUILD_DEFERRED'):
system_libs.run_ninja(build_dir)
else:
commands = []
objects = []
Expand Down Expand Up @@ -577,9 +578,11 @@ def add_cflags(args, settings): # noqa: U100
needed = get_needed_ports(settings)

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


Expand Down
3 changes: 1 addition & 2 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ def build(self):
return cache.get(self.get_path(), self.do_build, force=USE_NINJA == 2, quiet=USE_NINJA)

def generate(self):
return cache.get(self.get_path(), self.do_generate, force=USE_NINJA == 2, quiet=USE_NINJA,
deferred=True)
return cache.get(self.get_path(), self.do_generate, force=USE_NINJA == 2, quiet=USE_NINJA)

def get_link_flag(self):
"""
Expand Down