Skip to content

Commit

Permalink
Merge pull request #1588 from xymus/ems-dylibs
Browse files Browse the repository at this point in the history
Schedule an emit-module-separately job even if an input is not compilable
  • Loading branch information
xymus committed May 1, 2024
2 parents 2ed37d1 + 4cbefd8 commit 20926ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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 @@ -3096,7 +3096,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 @@ -3504,6 +3504,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(emitJob.commandLine.contains(try toPathOption("foo.swift")))
XCTAssertFalse(emitJob.commandLine.contains(try toPathOption("bar.dylib")))

let linkJob = try plannedJobs.findJob(.link)
XCTAssertTrue(linkJob.commandLine.contains(try toPathOption("bar.dylib")))
}
}

func testEmitModuleSeparatelyWMO() throws {
Expand Down

0 comments on commit 20926ef

Please sign in to comment.