@@ -253,8 +253,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
253
253
inputs: inout [ TypedVirtualPath ] ,
254
254
commandLine: inout [ Job . ArgTemplate ] ) throws {
255
255
// Prohibit the frontend from implicitly building textual modules into binary modules.
256
- var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
257
- var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
256
+ var swiftDependencyArtifacts : Set < SwiftModuleArtifactInfo > = [ ]
257
+ var clangDependencyArtifacts : Set < ClangModuleArtifactInfo > = [ ]
258
258
try addModuleDependencies ( of: moduleId,
259
259
clangDependencyArtifacts: & clangDependencyArtifacts,
260
260
swiftDependencyArtifacts: & swiftDependencyArtifacts)
@@ -276,8 +276,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
276
276
inputs. append ( TypedVirtualPath ( file: headerDep. path, type: . pch) )
277
277
}
278
278
}
279
-
280
- // Clang module dependencies are specified on the command line explicitly
281
279
for moduleArtifactInfo in clangDependencyArtifacts {
282
280
let clangModulePath =
283
281
TypedVirtualPath ( file: moduleArtifactInfo. clangModulePath. path,
@@ -311,8 +309,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
311
309
312
310
private mutating func addModuleDependency( of moduleId: ModuleDependencyId ,
313
311
dependencyId: ModuleDependencyId ,
314
- clangDependencyArtifacts: inout [ ClangModuleArtifactInfo ] ,
315
- swiftDependencyArtifacts: inout [ SwiftModuleArtifactInfo ]
312
+ clangDependencyArtifacts: inout Set < ClangModuleArtifactInfo > ,
313
+ swiftDependencyArtifacts: inout Set < SwiftModuleArtifactInfo > ,
314
+ bridgingHeaderDeps: Set < ModuleDependencyId > ? = nil
316
315
) throws {
317
316
switch dependencyId {
318
317
case . swift:
@@ -325,7 +324,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
325
324
isFramework = swiftModuleDetails. isFramework ?? false
326
325
// Accumulate the required information about this dependency
327
326
// TODO: add .swiftdoc and .swiftsourceinfo for this module.
328
- swiftDependencyArtifacts. append (
327
+ swiftDependencyArtifacts. insert (
329
328
SwiftModuleArtifactInfo ( name: dependencyId. moduleName,
330
329
modulePath: TextualVirtualPath ( path: swiftModulePath. fileHandle) ,
331
330
isFramework: isFramework,
@@ -335,11 +334,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
335
334
let dependencyClangModuleDetails =
336
335
try dependencyGraph. clangModuleDetails ( of: dependencyId)
337
336
// Accumulate the required information about this dependency
338
- clangDependencyArtifacts. append (
337
+ clangDependencyArtifacts. insert (
339
338
ClangModuleArtifactInfo ( name: dependencyId. moduleName,
340
339
modulePath: TextualVirtualPath ( path: dependencyInfo. modulePath. path) ,
341
340
moduleMapPath: dependencyClangModuleDetails. moduleMapPath,
342
- moduleCacheKey: dependencyClangModuleDetails. moduleCacheKey) )
341
+ moduleCacheKey: dependencyClangModuleDetails. moduleCacheKey,
342
+ isBridgingHeaderDependency: bridgingHeaderDeps? . contains ( dependencyId) ?? true ) )
343
343
case . swiftPrebuiltExternal:
344
344
let prebuiltModuleDetails = try dependencyGraph. swiftPrebuiltDetails ( of: dependencyId)
345
345
let compiledModulePath = prebuiltModuleDetails. compiledModulePath
@@ -348,7 +348,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
348
348
. init( file: compiledModulePath. path, type: . swiftModule)
349
349
// Accumulate the required information about this dependency
350
350
// TODO: add .swiftdoc and .swiftsourceinfo for this module.
351
- swiftDependencyArtifacts. append (
351
+ swiftDependencyArtifacts. insert (
352
352
SwiftModuleArtifactInfo ( name: dependencyId. moduleName,
353
353
modulePath: TextualVirtualPath ( path: swiftModulePath. fileHandle) ,
354
354
headerDependencies: prebuiltModuleDetails. headerDependencyPaths,
@@ -359,19 +359,46 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
359
359
}
360
360
}
361
361
362
+ /// Collect the Set of all Clang module dependencies which are dependencies of either
363
+ /// the `moduleId` bridging header or dependencies of bridging headers
364
+ /// of any prebuilt binary Swift modules in the dependency graph.
365
+ private func collectHeaderModuleDeps( of moduleId: ModuleDependencyId ) throws -> Set < ModuleDependencyId > ? {
366
+ var bridgingHeaderDeps : Set < ModuleDependencyId > ? = nil
367
+ guard let moduleDependencies = reachabilityMap [ moduleId] else {
368
+ fatalError ( " Expected reachability information for the module: \( moduleId. moduleName) . " )
369
+ }
370
+ if let dependencySourceBridingHeaderDeps =
371
+ try dependencyGraph. moduleInfo ( of: moduleId) . bridgingHeaderModuleDependencies {
372
+ bridgingHeaderDeps = Set ( dependencySourceBridingHeaderDeps)
373
+ } else {
374
+ bridgingHeaderDeps = Set < ModuleDependencyId > ( )
375
+ }
376
+ // Collect all binary Swift module dependnecies' header input module dependencies
377
+ for dependencyId in moduleDependencies {
378
+ if case . swiftPrebuiltExternal( _) = dependencyId {
379
+ let prebuiltDependencyDetails = try dependencyGraph. swiftPrebuiltDetails ( of: dependencyId)
380
+ for headerDependency in prebuiltDependencyDetails. headerDependencyModuleDependencies ?? [ ] {
381
+ bridgingHeaderDeps!. insert ( headerDependency)
382
+ }
383
+ }
384
+ }
385
+ return bridgingHeaderDeps
386
+ }
387
+
362
388
/// Add a specific module dependency as an input and a corresponding command
363
389
/// line flag.
364
390
private mutating func addModuleDependencies( of moduleId: ModuleDependencyId ,
365
- clangDependencyArtifacts: inout [ ClangModuleArtifactInfo ] ,
366
- swiftDependencyArtifacts: inout [ SwiftModuleArtifactInfo ]
391
+ clangDependencyArtifacts: inout Set < ClangModuleArtifactInfo > ,
392
+ swiftDependencyArtifacts: inout Set < SwiftModuleArtifactInfo >
367
393
) throws {
368
394
guard let moduleDependencies = reachabilityMap [ moduleId] else {
369
395
fatalError ( " Expected reachability information for the module: \( moduleId. moduleName) . " )
370
396
}
371
397
for dependencyId in moduleDependencies {
372
398
try addModuleDependency ( of: moduleId, dependencyId: dependencyId,
373
399
clangDependencyArtifacts: & clangDependencyArtifacts,
374
- swiftDependencyArtifacts: & swiftDependencyArtifacts)
400
+ swiftDependencyArtifacts: & swiftDependencyArtifacts,
401
+ bridgingHeaderDeps: try collectHeaderModuleDeps ( of: moduleId) )
375
402
}
376
403
}
377
404
@@ -437,8 +464,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
437
464
public mutating func resolveBridgingHeaderDependencies( inputs: inout [ TypedVirtualPath ] ,
438
465
commandLine: inout [ Job . ArgTemplate ] ) throws {
439
466
let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
440
- var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
441
- var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
467
+ var swiftDependencyArtifacts : Set < SwiftModuleArtifactInfo > = [ ]
468
+ var clangDependencyArtifacts : Set < ClangModuleArtifactInfo > = [ ]
442
469
let mainModuleDetails = try dependencyGraph. swiftModuleDetails ( of: mainModuleId)
443
470
444
471
var addedDependencies : Set < ModuleDependencyId > = [ ]
@@ -498,8 +525,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
498
525
499
526
/// Serialize the output file artifacts for a given module in JSON format.
500
527
private func serializeModuleDependencies( for moduleId: ModuleDependencyId ,
501
- swiftDependencyArtifacts: [ SwiftModuleArtifactInfo ] ,
502
- clangDependencyArtifacts: [ ClangModuleArtifactInfo ]
528
+ swiftDependencyArtifacts: Set < SwiftModuleArtifactInfo > ,
529
+ clangDependencyArtifacts: Set < ClangModuleArtifactInfo >
503
530
) throws -> Data {
504
531
// The module dependency map in CAS needs to be stable.
505
532
// Sort the dependencies by name.
0 commit comments