@@ -55,6 +55,13 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
5555 /// Does this compile support `.explicitInterfaceModuleBuild`
5656 private var supportsExplicitInterfaceBuild : Bool
5757
58+ /// Cached command-line additions for all main module compile jobs
59+ private struct ResolvedModuleDependenciesCommandLineComponents {
60+ let inputs : [ TypedVirtualPath ]
61+ let commandLine : [ Job . ArgTemplate ]
62+ }
63+ private var resolvedMainModuleDependenciesArgs : ResolvedModuleDependenciesCommandLineComponents ? = nil
64+
5865 public init ( dependencyGraph: InterModuleDependencyGraph ,
5966 toolchain: Toolchain ,
6067 dependencyOracle: InterModuleDependencyOracle ,
@@ -396,18 +403,30 @@ public typealias ExternalTargetModuleDetailsMap = [ModuleDependencyId: ExternalT
396403 /// inputs and command line flags.
397404 public mutating func resolveMainModuleDependencies( inputs: inout [ TypedVirtualPath ] ,
398405 commandLine: inout [ Job . ArgTemplate ] ) throws {
399- let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
400-
401- let mainModuleDetails = try dependencyGraph. swiftModuleDetails ( of: mainModuleId)
402- if let additionalArgs = mainModuleDetails. commandLine {
403- additionalArgs. forEach { commandLine. appendFlag ( $0) }
406+ // If not previously computed, gather all dependency input files and command-line arguments
407+ if resolvedMainModuleDependenciesArgs == nil {
408+ var inputAdditions : [ TypedVirtualPath ] = [ ]
409+ var commandLineAdditions : [ Job . ArgTemplate ] = [ ]
410+ let mainModuleId : ModuleDependencyId = . swift( dependencyGraph. mainModuleName)
411+ let mainModuleDetails = try dependencyGraph. swiftModuleDetails ( of: mainModuleId)
412+ if let additionalArgs = mainModuleDetails. commandLine {
413+ additionalArgs. forEach { commandLine. appendFlag ( $0) }
414+ }
415+ commandLineAdditions. appendFlags ( " -disable-implicit-swift-modules " ,
416+ " -Xcc " , " -fno-implicit-modules " ,
417+ " -Xcc " , " -fno-implicit-module-maps " )
418+ try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
419+ inputs: & inputAdditions,
420+ commandLine: & commandLineAdditions)
421+ resolvedMainModuleDependenciesArgs = ResolvedModuleDependenciesCommandLineComponents (
422+ inputs: inputAdditions,
423+ commandLine: commandLineAdditions
424+ )
404425 }
405- commandLine. appendFlags ( " -disable-implicit-swift-modules " ,
406- " -Xcc " , " -fno-implicit-modules " ,
407- " -Xcc " , " -fno-implicit-module-maps " )
408- try resolveExplicitModuleDependencies ( moduleId: mainModuleId,
409- inputs: & inputs,
410- commandLine: & commandLine)
426+
427+ inputs. append ( contentsOf: resolvedMainModuleDependenciesArgs!. inputs)
428+ commandLine. append ( contentsOf: resolvedMainModuleDependenciesArgs!. commandLine)
429+ return
411430 }
412431
413432 /// Resolve all module dependencies of the main module and add them to the lists of
0 commit comments