Skip to content

Commit 40c31b6

Browse files
authored
Merge pull request #603 from swiftlang/owenv/modulewrap-fix
Fix the criteria for enabling modulewrap in release builds
2 parents a7a9630 + e2311ff commit 40c31b6

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

Tests/SWBBuildSystemTests/BuildOperationTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import SWBTestSupport
3030

3131
@Suite(.requireXcode16())
3232
fileprivate struct BuildOperationTests: CoreBasedTests {
33-
@Test(.requireSDKs(.host), arguments: ["clang", "swiftc"])
34-
func commandLineTool(linkerDriver: String) async throws {
33+
@Test(.requireSDKs(.host), arguments: [("clang", "-Onone"), ("swiftc", "-Onone"), ("swiftc", "-Owholemodule")])
34+
func commandLineTool(linkerDriver: String, optimizationLevel: String) async throws {
3535
try await withTemporaryDirectory { (tmpDir: Path) in
3636
let testProject = try await TestProject(
3737
"TestProject",
@@ -55,6 +55,7 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
5555
"SUPPORTED_PLATFORMS": "$(HOST_PLATFORM)",
5656
"SWIFT_VERSION": swiftVersion,
5757
"LINKER_DRIVER": linkerDriver,
58+
"SWIFT_OPTIMIZATION_LEVEL": optimizationLevel,
5859
])
5960
],
6061
targets: [

0 commit comments

Comments
 (0)