@@ -2162,11 +2162,6 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
21622162 return ( inputs, outputs)
21632163 } ( )
21642164
2165- if cbc. scope. evaluate ( BuiltinMacros . PLATFORM_REQUIRES_SWIFT_MODULEWRAP) && cbc. scope. evaluate ( BuiltinMacros . GCC_GENERATE_DEBUGGING_SYMBOLS) {
2166- let moduleWrapOutput = Path ( moduleFilePath. withoutSuffix + " .o " )
2167- moduleOutputPaths. append ( moduleWrapOutput)
2168- }
2169-
21702165 // Add const metadata outputs to extra compilation outputs
21712166 if await supportConstSupplementaryMetadata ( cbc, delegate, compilationMode: compilationMode) {
21722167 // If using whole module optimization then we use the -primary.swiftconstvalues file from the sole compilation task.
@@ -2254,6 +2249,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
22542249 return nil
22552250 } ( )
22562251
2252+ let emittingModuleSeparately : Bool
22572253 if eagerCompilationEnabled ( args: args, scope: cbc. scope, compilationMode: compilationMode, isUsingWholeModuleOptimization: isUsingWholeModuleOptimization) {
22582254 if isUsingWholeModuleOptimization {
22592255 args += [ " -emit-module-separately-wmo " ]
@@ -2262,8 +2258,24 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
22622258 }
22632259 // Cross-module optimization is not supported when emitting the swiftmodule separately.
22642260 args += [ " -disable-cmo " ]
2261+ emittingModuleSeparately = true
22652262 } else if isUsingWholeModuleOptimization && !usingLegacyDriver {
22662263 args += [ " -no-emit-module-separately-wmo " ]
2264+ emittingModuleSeparately = false
2265+ } else {
2266+ // Conservatively assume we're not emitting a module separately in the fallback case.
2267+ emittingModuleSeparately = false
2268+ }
2269+
2270+ // Conditions which all must be met to enable module wrapping:
2271+ // 1. The platform must require it
2272+ // 2. We must be compiling with debug info
2273+ // 3. We must be emitting a module separately
2274+ if cbc. scope. evaluate ( BuiltinMacros . PLATFORM_REQUIRES_SWIFT_MODULEWRAP) &&
2275+ cbc. scope. evaluate ( BuiltinMacros . GCC_GENERATE_DEBUGGING_SYMBOLS) &&
2276+ emittingModuleSeparately {
2277+ let moduleWrapOutput = Path ( moduleFilePath. withoutSuffix + " .o " )
2278+ moduleOutputPaths. append ( moduleWrapOutput)
22672279 }
22682280
22692281 // The rule info.
0 commit comments