@@ -137,56 +137,32 @@ void ClangImporter::recordModuleDependencies(
137137 }
138138
139139 std::vector<std::string> swiftArgs;
140- // We are using Swift frontend mode.
141- swiftArgs.push_back (" -frontend" );
142- // We pass the entire argument list via -Xcc, so the invocation should
143- // use extra clang options alone.
144- swiftArgs.push_back (" -only-use-extra-clang-opts" );
145140 auto addClangArg = [&](Twine arg) {
146141 swiftArgs.push_back (" -Xcc" );
147142 swiftArgs.push_back (arg.str ());
148143 };
149- auto addClangFrontendArg = [&](Twine arg) {
150- addClangArg (" -Xclang" );
151- addClangArg (arg);
152- };
153144
154- // Add args reported by the scanner.
155- auto It = clangModuleDep.BuildArguments .begin ();
156- auto ItEnd = clangModuleDep.BuildArguments .end ();
157- // Skip -cc1.
158- ++It;
159-
160- while (It != ItEnd) {
161- StringRef arg = *It;
162- // Remove the -target arguments because we should use the target triple
163- // specified with `-clang-target` on the scanner invocation, or
164- // from the depending Swift modules.
165- if (arg == " -target" ) {
166- It += 2 ;
167- } else if (arg.startswith (" -fapinotes-swift-version=" )) {
168- // Remove the apinotes version because we should use the language version
169- // specified in the interface file.
170- It += 1 ;
171- } else {
172- addClangFrontendArg (*It);
173- ++ It;
174- }
175- }
145+ // We are using Swift frontend mode.
146+ swiftArgs.push_back (" -frontend" );
176147
177- // If the scanner is invoked with '-clang-target', ensure this is the target
178- // used to build this PCM.
179- if (Impl.SwiftContext .LangOpts .ClangTarget .hasValue ()) {
180- llvm::Triple triple = Impl.SwiftContext .LangOpts .ClangTarget .getValue ();
181- addClangArg (" -target" );
182- addClangArg (triple.str ());
183- }
148+ // We pass the entire argument list via -Xcc, so the invocation should
149+ // use extra clang options alone.
150+ swiftArgs.push_back (" -only-use-extra-clang-opts" );
184151
185152 // Swift frontend action: -emit-pcm
186153 swiftArgs.push_back (" -emit-pcm" );
187154 swiftArgs.push_back (" -module-name" );
188155 swiftArgs.push_back (clangModuleDep.ID .ModuleName );
189156
157+ // Ensure that the resulting PCM build invocation uses Clang frontend directly
158+ swiftArgs.push_back (" -direct-clang-cc1-module-build" );
159+
160+ // Swift frontend option for input file path (Foo.modulemap).
161+ swiftArgs.push_back (clangModuleDep.ClangModuleMapFile );
162+
163+ // Add args reported by the scanner.
164+ llvm::for_each (clangModuleDep.BuildArguments , addClangArg);
165+
190166 // Pass down search paths to the -emit-module action.
191167 // Unlike building Swift modules, we need to include all search paths to
192168 // the clang invocation to build PCMs because transitive headers can only
@@ -201,8 +177,6 @@ void ClangImporter::recordModuleDependencies(
201177 addClangArg ((path.IsSystem ? " -Fsystem" : " -F" ) + path.Path );
202178 }
203179
204- // Swift frontend option for input file path (Foo.modulemap).
205- swiftArgs.push_back (clangModuleDep.ClangModuleMapFile );
206180 // Module-level dependencies.
207181 llvm::StringSet<> alreadyAddedModules;
208182 auto dependencies = ModuleDependencies::forClangModule (
0 commit comments