Skip to content

Always emitting private swift interfaces if public interfaces are emitted #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ public struct Driver {
emitModuleSeparately: emitModuleSeparately,
outputFileMap: self.outputFileMap,
moduleName: moduleOutputInfo.name)
self.swiftPrivateInterfacePath = try Self.computeSupplementaryOutputPath(
let givenPrivateInterfacePath = try Self.computeSupplementaryOutputPath(
&parsedOptions, type: .privateSwiftInterface, isOutputOptions: [],
outputPath: .emitPrivateModuleInterfacePath,
compilerOutputType: compilerOutputType,
Expand All @@ -776,6 +776,19 @@ public struct Driver {
outputFileMap: self.outputFileMap,
moduleName: moduleOutputInfo.name)

// Always emitting private swift interfaces if public interfaces are emitted.'
// With the introduction of features like @_spi_available, we may print public
// and private interfaces differently even from the same codebase. For this reason,
// we should always print private interfaces so that we don’t mix the public interfaces
// with private Clang modules.
if let swiftInterfacePath = self.swiftInterfacePath,
givenPrivateInterfacePath == nil {
self.swiftPrivateInterfacePath = VirtualPath.lookup(swiftInterfacePath)
.replacingExtension(with: .privateSwiftInterface).intern()
} else {
self.swiftPrivateInterfacePath = givenPrivateInterfacePath
}

var optimizationRecordFileType = FileType.yamlOptimizationRecord
if let argument = parsedOptions.getLastArgument(.saveOptimizationRecordEQ)?.asSingle {
switch argument {
Expand Down
12 changes: 12 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,18 @@ final class SwiftDriverTests: XCTestCase {
}
}

func testPrivateInterfacePathImplicit() throws {
var driver1 = try Driver(args: ["swiftc", "foo.swift", "-emit-module", "-module-name",
"foo", "-emit-module-interface",
"-enable-library-evolution"])

let plannedJobs = try driver1.planBuild()
XCTAssertEqual(plannedJobs.count, 2)
let emitInterfaceJob = plannedJobs[0]
XCTAssertTrue(emitInterfaceJob.commandLine.contains(.flag("-emit-module-interface-path")))
XCTAssertTrue(emitInterfaceJob.commandLine.contains(.flag("-emit-private-module-interface-path")))
}

func testSingleThreadedWholeModuleOptimizationCompiles() throws {
var envVars = ProcessEnv.vars
envVars["SWIFT_DRIVER_LD_EXEC"] = ld.nativePathString(escaped: false)
Expand Down