@@ -253,8 +253,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
253253 inputs: inout [ TypedVirtualPath ] ,
254254 commandLine: inout [ Job . ArgTemplate ] ) throws {
255255 // 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 > = [ ]
258258 try addModuleDependencies ( of: moduleId,
259259 clangDependencyArtifacts: & clangDependencyArtifacts,
260260 swiftDependencyArtifacts: & swiftDependencyArtifacts)
@@ -276,8 +276,6 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
276276 inputs. append ( TypedVirtualPath ( file: headerDep. path, type: . pch) )
277277 }
278278 }
279-
280- // Clang module dependencies are specified on the command line explicitly
281279 for moduleArtifactInfo in clangDependencyArtifacts {
282280 let clangModulePath =
283281 TypedVirtualPath ( file: moduleArtifactInfo. clangModulePath. path,
@@ -311,8 +309,9 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
311309
312310 private mutating func addModuleDependency( of moduleId: ModuleDependencyId ,
313311 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
316315 ) throws {
317316 switch dependencyId {
318317 case . swift:
@@ -325,7 +324,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
325324 isFramework = swiftModuleDetails. isFramework ?? false
326325 // Accumulate the required information about this dependency
327326 // TODO: add .swiftdoc and .swiftsourceinfo for this module.
328- swiftDependencyArtifacts. append (
327+ swiftDependencyArtifacts. insert (
329328 SwiftModuleArtifactInfo ( name: dependencyId. moduleName,
330329 modulePath: TextualVirtualPath ( path: swiftModulePath. fileHandle) ,
331330 isFramework: isFramework,
@@ -335,11 +334,12 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
335334 let dependencyClangModuleDetails =
336335 try dependencyGraph. clangModuleDetails ( of: dependencyId)
337336 // Accumulate the required information about this dependency
338- clangDependencyArtifacts. append (
337+ clangDependencyArtifacts. insert (
339338 ClangModuleArtifactInfo ( name: dependencyId. moduleName,
340339 modulePath: TextualVirtualPath ( path: dependencyInfo. modulePath. path) ,
341340 moduleMapPath: dependencyClangModuleDetails. moduleMapPath,
342- moduleCacheKey: dependencyClangModuleDetails. moduleCacheKey) )
341+ moduleCacheKey: dependencyClangModuleDetails. moduleCacheKey,
342+ isBridgingHeaderDependency: bridgingHeaderDeps? . contains ( dependencyId) ?? true ) )
343343 case . swiftPrebuiltExternal:
344344 let prebuiltModuleDetails = try dependencyGraph. swiftPrebuiltDetails ( of: dependencyId)
345345 let compiledModulePath = prebuiltModuleDetails. compiledModulePath
@@ -348,7 +348,7 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
348348 . init( file: compiledModulePath. path, type: . swiftModule)
349349 // Accumulate the required information about this dependency
350350 // TODO: add .swiftdoc and .swiftsourceinfo for this module.
351- swiftDependencyArtifacts. append (
351+ swiftDependencyArtifacts. insert (
352352 SwiftModuleArtifactInfo ( name: dependencyId. moduleName,
353353 modulePath: TextualVirtualPath ( path: swiftModulePath. fileHandle) ,
354354 headerDependencies: prebuiltModuleDetails. headerDependencyPaths,
@@ -359,19 +359,46 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
359359 }
360360 }
361361
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+
362388 /// Add a specific module dependency as an input and a corresponding command
363389 /// line flag.
364390 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 >
367393 ) throws {
368394 guard let moduleDependencies = reachabilityMap [ moduleId] else {
369395 fatalError ( " Expected reachability information for the module: \( moduleId. moduleName) . " )
370396 }
371397 for dependencyId in moduleDependencies {
372398 try addModuleDependency ( of: moduleId, dependencyId: dependencyId,
373399 clangDependencyArtifacts: & clangDependencyArtifacts,
374- swiftDependencyArtifacts: & swiftDependencyArtifacts)
400+ swiftDependencyArtifacts: & swiftDependencyArtifacts,
401+ bridgingHeaderDeps: try collectHeaderModuleDeps ( of: moduleId) )
375402 }
376403 }
377404
@@ -437,8 +464,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
437464 public mutating func resolveBridgingHeaderDependencies( inputs: inout [ TypedVirtualPath ] ,
438465 commandLine: inout [ Job . ArgTemplate ] ) throws {
439466 let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
440- var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
441- var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
467+ var swiftDependencyArtifacts : Set < SwiftModuleArtifactInfo > = [ ]
468+ var clangDependencyArtifacts : Set < ClangModuleArtifactInfo > = [ ]
442469 let mainModuleDetails = try dependencyGraph. swiftModuleDetails ( of: mainModuleId)
443470
444471 var addedDependencies : Set < ModuleDependencyId > = [ ]
@@ -498,8 +525,8 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
498525
499526 /// Serialize the output file artifacts for a given module in JSON format.
500527 private func serializeModuleDependencies( for moduleId: ModuleDependencyId ,
501- swiftDependencyArtifacts: [ SwiftModuleArtifactInfo ] ,
502- clangDependencyArtifacts: [ ClangModuleArtifactInfo ]
528+ swiftDependencyArtifacts: Set < SwiftModuleArtifactInfo > ,
529+ clangDependencyArtifacts: Set < ClangModuleArtifactInfo >
503530 ) throws -> Data {
504531 // The module dependency map in CAS needs to be stable.
505532 // Sort the dependencies by name.
0 commit comments