Skip to content
Merged
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
12 changes: 10 additions & 2 deletions swift/internal/linking.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ def _register_static_library_link_action(
)
args = actions.args()
args.add_all(command_line)
args.add_all(objects)

filelist_args = actions.args()
if swift_toolchain.linker_supports_filelist:
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)
Copy link
Member

Choose a reason for hiding this comment

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

can't args files be nested? so you could args.add(filelist_args)?

Copy link
Member

Choose a reason for hiding this comment

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

ah I see this was asked below as well


env = cc_common.get_environment_variables(
action_name = CPP_LINK_STATIC_LIBRARY_ACTION_NAME,
Expand All @@ -73,7 +81,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
4 changes: 4 additions & 0 deletions swift/internal/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ The partial should be called with two arguments:
or dynamic runtime libraries.
* `is_test`: A `Boolean` value indicating whether the target being linked is a
test target.
""",
"linker_supports_filelist": """\
`Boolean`. Indicates whether or not the toolchain's linker supports the input
files passed to it via a file list.
""",
"object_format": """\
`String`. The object file format of the platform that the toolchain is
Expand Down
7 changes: 7 additions & 0 deletions swift/internal/swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ def _swift_toolchain_impl(ctx):
toolchain_root,
)

# The static archiver on Linux doesn't currently support the `-filelist`
# flag. This should be handled by the C++ toolchain once we migrate away
# from invoking the linker directly for static linking.
# See https://github.com/bazelbuild/rules_swift/pull/349#issuecomment-550353580.
linker_supports_filelist = True if ctx.attr.os == "darwin" else False
Copy link
Member

Choose a reason for hiding this comment

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

does this toolchain ever get used on darwin? I think you can only get the xcode one there?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh yeah

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

This could be:

    linker_supports_filelist = ctx.attr.os == "darwin"

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel so dumb 🤦🏼‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

haha, nbd, one of those things you don't notice without fresh eyes


# Combine build mode features, autoconfigured features, and required
# features.
requested_features = features_for_build_modes(ctx)
Expand Down Expand Up @@ -204,6 +210,7 @@ def _swift_toolchain_impl(ctx):
command_line_copts = ctx.fragments.swift.copts(),
cpu = ctx.attr.arch,
linker_opts_producer = linker_opts_producer,
linker_supports_filelist = linker_supports_filelist,
object_format = "elf",
optional_implicit_deps = [],
requested_features = requested_features,
Expand Down
1 change: 1 addition & 0 deletions swift/internal/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ def _xcode_swift_toolchain_impl(ctx):
command_line_copts = command_line_copts,
cpu = cpu,
linker_opts_producer = linker_opts_producer,
linker_supports_filelist = True,
object_format = "macho",
optional_implicit_deps = [],
requested_features = requested_features,
Expand Down