@@ -145,6 +145,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
145
145
// First, take the command line options provided in the dependency information
146
146
let moduleDetails = try dependencyGraph. swiftModuleDetails ( of: moduleId)
147
147
moduleDetails. commandLine? . forEach { commandLine. appendFlags ( $0) }
148
+ // Prohibit implicit module loading
149
+ commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
150
+ " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-module-maps " )
148
151
149
152
// Resolve all dependency module inputs for this Swift module
150
153
try resolveExplicitModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
@@ -224,7 +227,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
224
227
// First, take the command line options provided in the dependency information
225
228
let moduleDetails = try dependencyGraph. clangModuleDetails ( of: moduleId)
226
229
moduleDetails. commandLine. forEach { commandLine. appendFlags ( $0) }
227
-
230
+ // Prohibit implicit module loading
231
+ commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " , " -fno-implicit-module-maps " )
232
+
228
233
// Add the `-target` option as inherited from the dependent Swift module's PCM args
229
234
pcmArgs. forEach { commandLine. appendFlags ( $0) }
230
235
@@ -242,6 +247,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
242
247
outputs. append ( TypedVirtualPath ( file: targetEncodedModulePath, type: . pcm) )
243
248
commandLine. appendFlags ( " -emit-pcm " , " -module-name " , moduleId. moduleName,
244
249
" -o " , targetEncodedModulePath. description)
250
+ commandLine. appendFlag ( " -direct-clang-cc1-module-build " )
251
+
252
+ // Fixup "-o -Xcc -Xclang -Xcc '<replace-me>'"
253
+ if let outputIndex = commandLine. firstIndex ( of: . flag( " <replace-me> " ) ) {
254
+ commandLine [ outputIndex] = . path( VirtualPath . lookup ( targetEncodedModulePath) )
255
+ }
245
256
246
257
// The only required input is the .modulemap for this module.
247
258
// Command line options in the dependency scanner output will include the
@@ -268,9 +279,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
268
279
private mutating func resolveExplicitModuleDependencies( moduleId: ModuleDependencyId , pcmArgs: [ String ] ,
269
280
inputs: inout [ TypedVirtualPath ] ,
270
281
commandLine: inout [ Job . ArgTemplate ] ) throws {
271
- // 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 " )
274
282
var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
275
283
var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
276
284
try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
@@ -298,11 +306,17 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
298
306
let clangModulePath =
299
307
TypedVirtualPath ( file: moduleArtifactInfo. modulePath. path,
300
308
type: . pcm)
309
+ // If an existing dependency module path stub exists, replace it.
310
+ if let existingIndex = commandLine. firstIndex ( of: . flag( " -fmodule-file= " + moduleArtifactInfo. moduleName + " =<replace-me> " ) ) {
311
+ commandLine [ existingIndex] = . flag( " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
312
+ } else {
313
+ commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
314
+ " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
315
+ }
316
+
301
317
let clangModuleMapPath =
302
318
TypedVirtualPath ( file: moduleArtifactInfo. moduleMapPath. path,
303
319
type: . clangModuleMap)
304
- commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
305
- " -fmodule-file= \( moduleArtifactInfo. moduleName) = \( clangModulePath. file. description) " )
306
320
commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
307
321
" -fmodule-map-file= \( clangModuleMapPath. file. description) " )
308
322
inputs. append ( clangModulePath)
0 commit comments