Skip to content

[6.0] Schedule an emit-module-separately job even if an input is not compilable #1589

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 4 commits into from
May 15, 2024
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
4 changes: 2 additions & 2 deletions Sources/SwiftDriver/Jobs/EmitModuleJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension Driver {

// Add the inputs.
for input in self.inputFiles where input.type.isPartOfSwiftCompilation {
commandLine.append(.path(input.file))
try addPathArgument(input.file, to: &commandLine)
inputs.append(input)
}

Expand Down Expand Up @@ -136,7 +136,7 @@ extension Driver {
moduleOutputInfo: ModuleOutputInfo,
inputFiles: [TypedVirtualPath]) -> Bool {
if moduleOutputInfo.output == nil ||
!inputFiles.allSatisfy({ $0.type.isPartOfSwiftCompilation }) {
!inputFiles.contains(where: { $0.type.isPartOfSwiftCompilation }) {
return false
}

Expand Down
18 changes: 17 additions & 1 deletion Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3088,7 +3088,7 @@ final class SwiftDriverTests: XCTestCase {
func testWMOWithNonSourceInputFirstAndModuleOutput() throws {
var driver1 = try Driver(args: [
"swiftc", "-wmo", "danger.o", "foo.swift", "bar.swift", "wibble.swift", "-module-name", "Test",
"-driver-filelist-threshold=0", "-emit-module", "-emit-library"
"-driver-filelist-threshold=0", "-emit-module", "-emit-library", "-no-emit-module-separately-wmo"
])
let plannedJobs = try driver1.planBuild().removingAutolinkExtractJobs()
XCTAssertEqual(plannedJobs.count, 2)
Expand Down Expand Up @@ -3467,6 +3467,22 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertEqual(plannedJobs.count, 4)
XCTAssertEqual(Set(plannedJobs.map { $0.kind }), Set([.compile, .emitModule, .link]))
}

do {
// Schedule an emit-module separately job even if there are non-compilable inputs.
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.dylib", "-emit-library", "foo.dylib", "-emit-module-path", "foo.swiftmodule"],
env: envVars)
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 3)
XCTAssertEqual(Set(plannedJobs.map { $0.kind }), Set([.compile, .emitModule, .link]))

let emitJob = try plannedJobs.findJob(.emitModule)
XCTAssertTrue(try emitJob.commandLine.contains(where: { $0 == .path(.relative(try .init(validating: "foo.swift")))}))
XCTAssertFalse(try emitJob.commandLine.contains(where: { $0 == .path(.relative(try .init(validating: "bar.dylib")))}))

let linkJob = try plannedJobs.findJob(.link)
XCTAssertTrue(try linkJob.commandLine.contains(where: { $0 == .path(.relative(try .init(validating: "bar.dylib")))}))
}
}

func testEmitModuleSeparatelyWMO() throws {
Expand Down