@@ -224,7 +224,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
224224 // First, take the command line options provided in the dependency information
225225 let moduleDetails = try dependencyGraph. clangModuleDetails ( of: moduleId)
226226 moduleDetails. commandLine. forEach { commandLine. appendFlags ( $0) }
227-
227+
228228 // Add the `-target` option as inherited from the dependent Swift module's PCM args
229229 pcmArgs. forEach { commandLine. appendFlags ( $0) }
230230
@@ -242,6 +242,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
242242 outputs. append ( TypedVirtualPath ( file: targetEncodedModulePath, type: . pcm) )
243243 commandLine. appendFlags ( " -emit-pcm " , " -module-name " , moduleId. moduleName,
244244 " -o " , targetEncodedModulePath. description)
245+ commandLine. appendFlag ( " -direct-clang-cc1-module-build " )
246+
247+ // Fixup "-o -Xcc -Xclang -Xcc '<replace-me>'"
248+ if let outputIndex = commandLine. firstIndex ( of: . flag( " <replace-me> " ) ) {
249+ commandLine [ outputIndex] = . path( VirtualPath . lookup ( targetEncodedModulePath) )
250+ }
245251
246252 // The only required input is the .modulemap for this module.
247253 // Command line options in the dependency scanner output will include the
@@ -269,8 +275,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
269275 inputs: inout [ TypedVirtualPath ] ,
270276 commandLine: inout [ Job . ArgTemplate ] ) throws {
271277 // Prohibit the frontend from implicitly building textual modules into binary modules.
272- commandLine. appendFlags ( " -disable-implicit-swift-modules " , " -Xcc " , " -Xclang " , " -Xcc " ,
273- " -fno-implicit-modules " , " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-module-maps " )
278+ commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
279+ " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-modules " ,
280+ " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-module-maps " )
274281 var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
275282 var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
276283 try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
@@ -298,11 +305,17 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
298305 let clangModulePath =
299306 TypedVirtualPath ( file: moduleArtifactInfo. modulePath. path,
300307 type: . pcm)
308+ // If an existing dependency module path stub exists, replace it.
309+ if let existingIndex = commandLine. firstIndex ( of: . flag( " -fmodule-file= " + moduleArtifactInfo. moduleName + " =<replace-me> " ) ) {
310+ commandLine [ existingIndex] = . flag( " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
311+ } else {
312+ commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
313+ " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
314+ }
315+
301316 let clangModuleMapPath =
302317 TypedVirtualPath ( file: moduleArtifactInfo. moduleMapPath. path,
303318 type: . clangModuleMap)
304- commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
305- " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
306319 commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
307320 " -fmodule-map-file= \( clangModuleMapPath. file. description) " )
308321 inputs. append ( clangModulePath)
0 commit comments