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
1 change: 0 additions & 1 deletion swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,6 @@ def compile_action_configs(
action_configs.append(
ActionConfigInfo(
actions = all_compile_action_names() + [
SWIFT_ACTION_COMPILE_MODULE_INTERFACE,
SWIFT_ACTION_DUMP_AST,
SWIFT_ACTION_PRECOMPILE_C_MODULE,
],
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/module_interface/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("//swift:swift_binary.bzl", "swift_binary")
load("//swift:swift_import.bzl", "swift_import")
load("//test:transitions.bzl", "transition_binary")
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")

package(
Expand Down Expand Up @@ -56,3 +57,21 @@ swift_import(
swiftinterface = "//test/fixtures/module_interface/library:toy_outputs/ToyModule.swiftinterface",
tags = FIXTURE_TAGS,
)

swift_import(
name = "toy_module_interface",
module_name = "ToyModule",
swiftinterface = "//test/fixtures/module_interface/library:toy_interface/ToyModule.swiftinterface",
tags = FIXTURE_TAGS,
)

transition_binary(
name = "toy_module_interface_with_driver_flags",
swiftcopts = [
"-Xfrontend",
"-disable-availability-checking",
"-j1",
],
tags = FIXTURE_TAGS,
target = ":toy_module_interface",
)
7 changes: 7 additions & 0 deletions test/fixtures/module_interface/library/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ swift_library_artifact_collector(
target_compatible_with = ["@platforms//os:macos"],
)

swift_library_artifact_collector(
name = "toy_module_interface_artifact_collector",
swiftinterface = "toy_interface/ToyModule.swiftinterface",
tags = FIXTURE_TAGS,
target = ":toy_module_library",
)

swift_library(
name = "toy_module_library_without_library_evolution",
srcs = ["ToyModule.swift"],
Expand Down
16 changes: 16 additions & 0 deletions test/module_interface_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ def module_interface_test_suite(name, tags = []):
"""
all_tags = [name] + tags

build_test(
name = "{}_interface_only".format(name),
targets = [
"//test/fixtures/module_interface:toy_module_interface",
],
tags = all_tags,
)

build_test(
name = "{}_swiftcopt_driver_flags".format(name),
targets = [
"//test/fixtures/module_interface:toy_module_interface_with_driver_flags",
],
tags = all_tags,
)

# Verify that a `swift_binary` builds properly when depending on a
# `swift_import` target that references a `.swiftinterface` file.
build_test(
Expand Down
6 changes: 6 additions & 0 deletions test/transitions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _HOST_FEATURES = "//command_line_option:host_features"
_IOS_MINIMUM_OS = "//command_line_option:ios_minimum_os"
_MACOS_MINIMUM_OS = "//command_line_option:macos_minimum_os"
_PLATFORMS = "//command_line_option:platforms"
_SWIFTCOPTS = str(Label("//swift:copt"))
_TVOS_MINIMUM_OS = "//command_line_option:tvos_minimum_os"

_TRANSITION_OPTIONS = [
Expand All @@ -21,6 +22,7 @@ _TRANSITION_OPTIONS = [
_IOS_MINIMUM_OS,
_MACOS_MINIMUM_OS,
_PLATFORMS,
_SWIFTCOPTS,
_TVOS_MINIMUM_OS,
]

Expand All @@ -33,6 +35,7 @@ def _transition_impl(settings, attr):
_IOS_MINIMUM_OS: attr.ios_minimum_os or settings[_IOS_MINIMUM_OS],
_MACOS_MINIMUM_OS: attr.macos_minimum_os or attr.minimum_os or settings[_MACOS_MINIMUM_OS],
_PLATFORMS: [attr.platform] if attr.platform else settings[_PLATFORMS],
_SWIFTCOPTS: settings[_SWIFTCOPTS] + attr.swiftcopts,
_TVOS_MINIMUM_OS: attr.tvos_minimum_os or settings[_TVOS_MINIMUM_OS],
}

Expand Down Expand Up @@ -66,6 +69,9 @@ _TRANSITION_ATTRS = {
"platform": attr.string(
doc = "Optional target platform label (e.g. `@apple_support//platforms:macos_x86_64`).",
),
"swiftcopts": attr.string_list(
doc = "Swift compiler flags appended to `//swift:copt` for the transitioned target.",
),
"transitive_features": attr.string_list(
doc = "Feature strings appended to `//command_line_option:features` and `//command_line_option:host_features`.",
),
Expand Down
31 changes: 21 additions & 10 deletions tools/worker/swift_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ namespace {
using namespace bazel_rules_swift;

// Creates a temporary file and writes the given arguments to it, one per line.
// A leading -frontend is passed outside the response file by
// ArgsWithResponseFile because some swift-driver versions select the invocation
// mode before expanding response files.
static std::unique_ptr<TempFile> WriteResponseFile(
const std::vector<std::string>& args) {
auto response_file = TempFile::Create("swiftc_params.XXXXXX");
std::ofstream response_file_stream(response_file->GetPath());

for (const auto& arg : args) {
auto it = args.begin();
if (it != args.end() && *it == "-frontend") {
++it;
}
for (; it != args.end(); ++it) {
const auto& arg = *it;
// When Clang/Swift write out a response file to communicate from driver to
// frontend, they just quote every argument to be safe; we duplicate that
// instead of trying to be "smarter" and only quoting when necessary.
Expand Down Expand Up @@ -379,6 +387,17 @@ bool SupportsResponseFileInvocation(const std::vector<std::string>& args) {
return args.empty() || args.front() != "-modulewrap";
}

std::vector<std::string> ArgsWithResponseFile(
const std::vector<std::string>& tool_args,
const std::vector<std::string>& args, const TempFile& response_file) {
std::vector<std::string> spawn_args(tool_args);
if (!args.empty() && args.front() == "-frontend") {
spawn_args.push_back(args.front());
}
spawn_args.push_back("@" + response_file.GetPath());
return spawn_args;
}

// Spawns an executable, constructing the command line by writing `args` to a
// response file when the Swift invocation mode supports it and concatenating
// that after `tool_args` (which are passed outside the response file).
Expand All @@ -389,22 +408,14 @@ int SpawnJob(const std::vector<std::string>& tool_args,
std::vector<std::string> spawn_args(tool_args);
if (SupportsResponseFileInvocation(args)) {
auto response_file = WriteResponseFile(args);
spawn_args.push_back("@" + response_file->GetPath());
spawn_args = ArgsWithResponseFile(tool_args, args, *response_file);
return RunSubProcess(spawn_args, env, stderr_stream, stdout_to_stderr);
}

spawn_args.insert(spawn_args.end(), args.begin(), args.end());
return RunSubProcess(spawn_args, env, stderr_stream, stdout_to_stderr);
}

std::vector<std::string> ArgsWithResponseFile(
const std::vector<std::string>& tool_args,
const std::vector<std::string>& args, const TempFile& response_file) {
std::vector<std::string> spawn_args(tool_args);
spawn_args.push_back("@" + response_file.GetPath());
return spawn_args;
}

std::vector<std::string> FullArgsForDisplay(
const std::vector<std::string>& tool_args,
const std::vector<std::string>& args) {
Expand Down
Loading