Skip to content

Commit aec6d08

Browse files
authored
Merge pull request #1043 from nkcsgexi/91061334
Always emitting private swift interfaces if public interfaces are emitted
2 parents 40ee43e + 4e1167f commit aec6d08

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ public struct Driver {
767767
emitModuleSeparately: emitModuleSeparately,
768768
outputFileMap: self.outputFileMap,
769769
moduleName: moduleOutputInfo.name)
770-
self.swiftPrivateInterfacePath = try Self.computeSupplementaryOutputPath(
770+
let givenPrivateInterfacePath = try Self.computeSupplementaryOutputPath(
771771
&parsedOptions, type: .privateSwiftInterface, isOutputOptions: [],
772772
outputPath: .emitPrivateModuleInterfacePath,
773773
compilerOutputType: compilerOutputType,
@@ -776,6 +776,19 @@ public struct Driver {
776776
outputFileMap: self.outputFileMap,
777777
moduleName: moduleOutputInfo.name)
778778

779+
// Always emitting private swift interfaces if public interfaces are emitted.'
780+
// With the introduction of features like @_spi_available, we may print public
781+
// and private interfaces differently even from the same codebase. For this reason,
782+
// we should always print private interfaces so that we don’t mix the public interfaces
783+
// with private Clang modules.
784+
if let swiftInterfacePath = self.swiftInterfacePath,
785+
givenPrivateInterfacePath == nil {
786+
self.swiftPrivateInterfacePath = VirtualPath.lookup(swiftInterfacePath)
787+
.replacingExtension(with: .privateSwiftInterface).intern()
788+
} else {
789+
self.swiftPrivateInterfacePath = givenPrivateInterfacePath
790+
}
791+
779792
var optimizationRecordFileType = FileType.yamlOptimizationRecord
780793
if let argument = parsedOptions.getLastArgument(.saveOptimizationRecordEQ)?.asSingle {
781794
switch argument {

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,18 @@ final class SwiftDriverTests: XCTestCase {
22922292
}
22932293
}
22942294

2295+
func testPrivateInterfacePathImplicit() throws {
2296+
var driver1 = try Driver(args: ["swiftc", "foo.swift", "-emit-module", "-module-name",
2297+
"foo", "-emit-module-interface",
2298+
"-enable-library-evolution"])
2299+
2300+
let plannedJobs = try driver1.planBuild()
2301+
XCTAssertEqual(plannedJobs.count, 2)
2302+
let emitInterfaceJob = plannedJobs[0]
2303+
XCTAssertTrue(emitInterfaceJob.commandLine.contains(.flag("-emit-module-interface-path")))
2304+
XCTAssertTrue(emitInterfaceJob.commandLine.contains(.flag("-emit-private-module-interface-path")))
2305+
}
2306+
22952307
func testSingleThreadedWholeModuleOptimizationCompiles() throws {
22962308
var envVars = ProcessEnv.vars
22972309
envVars["SWIFT_DRIVER_LD_EXEC"] = ld.nativePathString(escaped: false)

0 commit comments

Comments
 (0)