diff --git a/swift/toolchains/config/compile_config.bzl b/swift/toolchains/config/compile_config.bzl index 4079c436f..374f393aa 100644 --- a/swift/toolchains/config/compile_config.bzl +++ b/swift/toolchains/config/compile_config.bzl @@ -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, ], diff --git a/test/fixtures/module_interface/BUILD b/test/fixtures/module_interface/BUILD index aead964e4..64f707f5f 100644 --- a/test/fixtures/module_interface/BUILD +++ b/test/fixtures/module_interface/BUILD @@ -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( @@ -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", +) diff --git a/test/fixtures/module_interface/library/BUILD b/test/fixtures/module_interface/library/BUILD index 24db25f08..1dc0f3b70 100644 --- a/test/fixtures/module_interface/library/BUILD +++ b/test/fixtures/module_interface/library/BUILD @@ -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"], diff --git a/test/module_interface_tests.bzl b/test/module_interface_tests.bzl index bfb502c42..9b7ce551a 100644 --- a/test/module_interface_tests.bzl +++ b/test/module_interface_tests.bzl @@ -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( diff --git a/test/transitions.bzl b/test/transitions.bzl index da9023bcf..390a6318b 100644 --- a/test/transitions.bzl +++ b/test/transitions.bzl @@ -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 = [ @@ -21,6 +22,7 @@ _TRANSITION_OPTIONS = [ _IOS_MINIMUM_OS, _MACOS_MINIMUM_OS, _PLATFORMS, + _SWIFTCOPTS, _TVOS_MINIMUM_OS, ] @@ -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], } @@ -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`.", ), diff --git a/tools/worker/swift_runner.cc b/tools/worker/swift_runner.cc index 5c96bb9a0..ca6636346 100644 --- a/tools/worker/swift_runner.cc +++ b/tools/worker/swift_runner.cc @@ -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 WriteResponseFile( const std::vector& 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. @@ -379,6 +387,17 @@ bool SupportsResponseFileInvocation(const std::vector& args) { return args.empty() || args.front() != "-modulewrap"; } +std::vector ArgsWithResponseFile( + const std::vector& tool_args, + const std::vector& args, const TempFile& response_file) { + std::vector 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). @@ -389,7 +408,7 @@ int SpawnJob(const std::vector& tool_args, std::vector 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); } @@ -397,14 +416,6 @@ int SpawnJob(const std::vector& tool_args, return RunSubProcess(spawn_args, env, stderr_stream, stdout_to_stderr); } -std::vector ArgsWithResponseFile( - const std::vector& tool_args, - const std::vector& args, const TempFile& response_file) { - std::vector spawn_args(tool_args); - spawn_args.push_back("@" + response_file.GetPath()); - return spawn_args; -} - std::vector FullArgsForDisplay( const std::vector& tool_args, const std::vector& args) {