Skip to content

Commit

Permalink
Ninja: set default pool depth for MS link.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
lb90 committed Nov 21, 2024
1 parent 9f3f88f commit d1a07fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 12 additions & 3 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,15 @@ def detect_prefix(out):

raise MesonException(f'Could not determine vs dep dependency prefix string. output: {stderr} {stdout}')

def get_link_pool_depth(self) -> int:
depth = self.environment.coredata.optstore.get_value('backend_max_links')
if depth == 0:
for compiler in self.environment.coredata.compilers.host.values():
d = compiler.linker.get_default_pool_depth()
if d > 0 and (depth == 0 or d < depth):
depth = d
return depth;

def generate(self, capture: bool = False, vslite_ctx: T.Optional[T.Dict] = None) -> T.Optional[T.Dict]:
if vslite_ctx:
# We don't yet have a use case where we'd expect to make use of this,
Expand Down Expand Up @@ -632,7 +641,7 @@ def generate(self, capture: bool = False, vslite_ctx: T.Optional[T.Dict] = None)
outfile.write('# Do not edit by hand.\n\n')
outfile.write('ninja_required_version = 1.8.2\n\n')

num_pools = self.environment.coredata.optstore.get_value('backend_max_links')
num_pools = self.get_link_pool_depth()
if num_pools > 0:
outfile.write(f'''pool link_pool
depth = {num_pools}
Expand Down Expand Up @@ -2305,7 +2314,7 @@ def _rsp_options(self, tool: T.Union['Compiler', 'StaticLinker', 'DynamicLinker'
return options

def generate_static_link_rules(self) -> None:
num_pools = self.environment.coredata.optstore.get_value('backend_max_links')
num_pools = self.get_link_pool_depth()
if 'java' in self.environment.coredata.compilers.host:
self.generate_java_link()
for for_machine in MachineChoice:
Expand Down Expand Up @@ -2353,7 +2362,7 @@ def generate_static_link_rules(self) -> None:
self.add_rule(NinjaRule(rule, cmdlist, args, description, **options, extra=pool))

def generate_dynamic_link_rules(self) -> None:
num_pools = self.environment.coredata.optstore.get_value('backend_max_links')
num_pools = self.get_link_pool_depth()
for for_machine in MachineChoice:
complist = self.environment.coredata.compilers[for_machine]
for langname, compiler in complist.items():
Expand Down
13 changes: 13 additions & 0 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ def get_command_to_archive_shlib(self) -> T.List[str]:
#Only used by AIX.
return []

def get_default_pool_depth(self):
# Returns the ideal number of concurrent invocations.
# Returning 0 means no limit, so the default concurrency
# value (tipically the number of logical processors) is
# used
return 0


if T.TYPE_CHECKING:
StaticLinkerBase = StaticLinker
Expand Down Expand Up @@ -1368,6 +1375,12 @@ def get_win_subsystem_args(self, value: str) -> T.List[str]:
def fatal_warnings(self) -> T.List[str]:
return ['-WX']

def get_default_pool_depth(self):
# MS link.exe is internally multithreaded and uses lots of memory.
# we might check the amount of physical memory here, but it's not
# clear if parallel invocations of the linker bring any advantage.
return 1


class ClangClDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):

Expand Down

0 comments on commit d1a07fe

Please sign in to comment.