Skip to content

Verify emitted modules interfaces of public frameworks by default #832

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
Sep 21, 2021
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
12 changes: 5 additions & 7 deletions Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,15 @@ extension Driver {

private mutating func addVerifyJobs(emitModuleJob: Job, addJob: (Job) -> Void )
throws {
// Turn this flag on by default with the env var or for public frameworks.
let onByDefault = env["ENABLE_DEFAULT_INTERFACE_VERIFIER"] != nil ||
parsedOptions.getLastArgument(.libraryLevel)?.asSingle == "api"

guard
parsedOptions.hasArgument(.enableLibraryEvolution),
parsedOptions.hasFlag(positive: .verifyEmittedModuleInterface,
negative: .noVerifyEmittedModuleInterface,
default: true),
default: onByDefault),

// Don't verify by default modules emitted from a merge-module job
// as it's more likely to be invalid
Expand All @@ -444,12 +448,6 @@ extension Driver {
default: false)
else { return }

// FIXME: remove this when we are confident to enable interface verification
// by default.
if env["ENABLE_DEFAULT_INTERFACE_VERIFIER"] == nil &&
!parsedOptions.hasArgument(.verifyEmittedModuleInterface) {
return
}
func addVerifyJob(forPrivate: Bool) throws {
let isNeeded =
forPrivate
Expand Down
24 changes: 24 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4107,6 +4107,30 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(verifyJob.inputs[0] == emitInterfaceOutput[0])
XCTAssertTrue(verifyJob.commandLine.contains(.path(emitInterfaceOutput[0].file)))
}

// Enabled by default when the library-level is api.
do {
var driver = try Driver(args: ["swiftc", "foo.swift", "-emit-module", "-module-name",
"foo", "-emit-module-interface",
"-enable-library-evolution",
"-whole-module-optimization",
"-library-level", "api"])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 2)
XCTAssertTrue(plannedJobs.contains() {$0.kind == .verifyModuleInterface})
}

// Not enabled by default when the library-level is spi.
do {
var driver = try Driver(args: ["swiftc", "foo.swift", "-emit-module", "-module-name",
"foo", "-emit-module-interface",
"-enable-library-evolution",
"-whole-module-optimization",
"-library-level", "spi"])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 1)
XCTAssertEqual(plannedJobs[0].kind, .compile)
}
}

func testPCHGeneration() throws {
Expand Down