@@ -224,7 +224,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
224
224
// First, take the command line options provided in the dependency information
225
225
let moduleDetails = try dependencyGraph. clangModuleDetails ( of: moduleId)
226
226
moduleDetails. commandLine. forEach { commandLine. appendFlags ( $0) }
227
-
227
+
228
228
// Add the `-target` option as inherited from the dependent Swift module's PCM args
229
229
pcmArgs. forEach { commandLine. appendFlags ( $0) }
230
230
@@ -242,6 +242,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
242
242
outputs. append ( TypedVirtualPath ( file: targetEncodedModulePath, type: . pcm) )
243
243
commandLine. appendFlags ( " -emit-pcm " , " -module-name " , moduleId. moduleName,
244
244
" -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
+ }
245
251
246
252
// The only required input is the .modulemap for this module.
247
253
// Command line options in the dependency scanner output will include the
@@ -269,8 +275,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
269
275
inputs: inout [ TypedVirtualPath ] ,
270
276
commandLine: inout [ Job . ArgTemplate ] ) throws {
271
277
// 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 " )
274
281
var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
275
282
var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
276
283
try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
@@ -298,11 +305,17 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
298
305
let clangModulePath =
299
306
TypedVirtualPath ( file: moduleArtifactInfo. modulePath. path,
300
307
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
+
301
316
let clangModuleMapPath =
302
317
TypedVirtualPath ( file: moduleArtifactInfo. moduleMapPath. path,
303
318
type: . clangModuleMap)
304
- commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
305
- " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
306
319
commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
307
320
" -fmodule-map-file= \( clangModuleMapPath. file. description) " )
308
321
inputs. append ( clangModulePath)
0 commit comments