Skip to content
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
16 changes: 14 additions & 2 deletions swift/toolchains/swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ def _swift_unix_linkopts_cc_info(
cpu,
os,
toolchain_label,
toolchain_root):
toolchain_root,
toolchain_files = None):
"""Returns a `CcInfo` containing flags that should be passed to the linker.

The provider returned by this function will be used as an implicit
Expand All @@ -361,6 +362,8 @@ def _swift_unix_linkopts_cc_info(
toolchain_label: The label of the Swift toolchain that will act as the
owner of the linker input propagating the flags.
toolchain_root: The toolchain's root directory.
toolchain_files: Optional depset of files from the Swift toolchain that
should be passed as additional inputs to the linker.

Returns:
A `CcInfo` provider that will provide linker flags to binaries that
Expand Down Expand Up @@ -396,6 +399,7 @@ def _swift_unix_linkopts_cc_info(
cc_common.create_linker_input(
owner = toolchain_label,
user_link_flags = depset(linkopts),
additional_inputs = toolchain_files if toolchain_files else depset(),
),
]),
),
Expand Down Expand Up @@ -450,6 +454,7 @@ def _swift_toolchain_impl(ctx):
ctx.attr.os,
ctx.label,
toolchain_root,
ctx.attr.toolchain_files[DefaultInfo].files if ctx.attr.toolchain_files else None,
)

# TODO: Remove once we drop bazel 7.x support
Expand Down Expand Up @@ -494,7 +499,7 @@ def _swift_toolchain_impl(ctx):
toolchain_root = toolchain_root,
use_autolink_extract = SWIFT_FEATURE_USE_AUTOLINK_EXTRACT in ctx.features,
use_module_wrap = SWIFT_FEATURE_USE_MODULE_WRAP in ctx.features,
additional_tools = [ctx.file.version_file],
additional_tools = [ctx.file.version_file] + (ctx.attr.toolchain_files[DefaultInfo].files.to_list() if ctx.attr.toolchain_files else []),
tool_executable_suffix = ctx.attr.tool_executable_suffix,
)
all_action_configs = _all_action_configs(
Expand Down Expand Up @@ -635,6 +640,13 @@ configuration options that are applied to targets on a per-package basis.
"root": attr.string(
mandatory = True,
),
"toolchain_files": attr.label(
doc = """\
A filegroup containing all the files in the Swift toolchain. These files will be\
passed as inputs to all Swift compile and link actions, enabling sandboxed builds.\
""",
mandatory = False,
),
"version_file": attr.label(
mandatory = True,
allow_single_file = True,
Expand Down
4 changes: 2 additions & 2 deletions tools/common/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ void PosixSpawnIORedirector::ConsumeAllSubprocessOutput(
// are controlled by the lifetime of the strings in args.
std::vector<const char *> ConvertToCArgs(const std::vector<std::string> &args) {
std::vector<const char *> c_args;
std::string filename = std::filesystem::path(args[0]).filename().string();
c_args.push_back(&*std::next(args[0].rbegin(), filename.length() - 1));
// Keep full path so Swift driver can find swift-frontend relative to argv[0]
c_args.push_back(args[0].c_str());
for (int i = 1; i < args.size(); i++) {
c_args.push_back(args[i].c_str());
}
Expand Down