Skip to content

Commit

Permalink
Use a parameter file when linking Swift libraries when the host machine
Browse files Browse the repository at this point in the history
is macOS.

This is to prevent the linking failures if a `swift_library` target has
too many files that can cause its linking args to become longer than the
system's command length limits. This does not change the behavior when
building on Linux yet, since `ar` does not support passing arguments
using a parameter file.
  • Loading branch information
thii committed Aug 13, 2020
1 parent 49de7e5 commit cdc329e
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions swift/internal/linking.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ load(
)
load(":derived_files.bzl", "derived_files")

def _is_apple_platform_toolchain(swift_toolchain):
"""Returns `True` if the given Swift toolchain is for Apple platforms.
Args:
swift_toolchain: A `SwiftToolchainInfo` provider representing a Swift
compiler toolchain.
Returns:
`True` if the given Swift toolchain is for Apple platforms.
"""
return swift_toolchain.system_name == "darwin"

def _register_static_library_link_action(
actions,
cc_feature_configuration,
Expand Down Expand Up @@ -58,7 +70,17 @@ def _register_static_library_link_action(
)
args = actions.args()
args.add_all(command_line)
args.add_all(objects)
filelist_args = actions.args()

# Use a parameter file when building on macOS. `ar` on Linux does not
# support this yet, so we're passing parameters to the command line as is.
if _is_apple_platform_toolchain(swift_toolchain):
args.add("-filelist")
filelist_args.set_param_file_format("multiline")
filelist_args.use_param_file("%s", use_always = True)
filelist_args.add_all(objects)
else:
args.add_all(objects)

env = cc_common.get_environment_variables(
action_name = CPP_LINK_STATIC_LIBRARY_ACTION_NAME,
Expand All @@ -73,7 +95,7 @@ def _register_static_library_link_action(
execution_requirements = {req: "1" for req in execution_requirements_list}

actions.run(
arguments = [args],
arguments = [args, filelist_args],
env = env,
executable = archiver_path,
execution_requirements = execution_requirements,
Expand Down

0 comments on commit cdc329e

Please sign in to comment.