Skip to content
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

[5.10] Don't add an autolink-extract job unless actually linking ELF/Wasm objects, matching the original C++ driver #1480

Merged
merged 1 commit into from
Jan 8, 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
3 changes: 2 additions & 1 deletion Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import struct TSCBasic.RelativePath
// FIXME: Also handle Cygwin and MinGW
extension Driver {
/*@_spi(Testing)*/ public var isAutolinkExtractJobNeeded: Bool {
[.elf, .wasm].contains(targetTriple.objectFormat) && lto == nil
[.elf, .wasm].contains(targetTriple.objectFormat) && lto == nil &&
linkerOutputType != nil
}

mutating func autolinkExtractJob(inputs: [TypedVirtualPath]) throws -> Job? {
Expand Down
14 changes: 4 additions & 10 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3358,25 +3358,19 @@ final class SwiftDriverTests: XCTestCase {
}
}

#if os(Linux) || os(Android)
let autoLinkExtractJob = 1
#else
let autoLinkExtractJob = 0
#endif

do {
// non library-evolution builds require a single job, because cross-module-optimization is enabled by default.
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module-path", rebase("Test.swiftmodule", at: root), "-c", "-o", rebase("test.o", at: root), "-wmo", "-O" ])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 1 + autoLinkExtractJob)
XCTAssertEqual(plannedJobs.count, 1)
XCTAssertTrue(plannedJobs[0].commandLine.contains(.flag("-enable-default-cmo")))
}

do {
// library-evolution builds can emit the module in a separate job.
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module-path", rebase("Test.swiftmodule", at: root), "-c", "-o", rebase("test.o", at: root), "-wmo", "-O", "-enable-library-evolution" ])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 2 + autoLinkExtractJob)
XCTAssertEqual(plannedJobs.count, 2)
XCTAssertFalse(plannedJobs[0].commandLine.contains(.flag("-enable-default-cmo")))
XCTAssertFalse(plannedJobs[1].commandLine.contains(.flag("-enable-default-cmo")))
}
Expand All @@ -3385,7 +3379,7 @@ final class SwiftDriverTests: XCTestCase {
// When disabling cross-module-optimization, the module can be emitted in a separate job.
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module-path", rebase("Test.swiftmodule", at: root), "-c", "-o", rebase("test.o", at: root), "-wmo", "-O", "-disable-cmo" ])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 2 + autoLinkExtractJob)
XCTAssertEqual(plannedJobs.count, 2)
XCTAssertFalse(plannedJobs[0].commandLine.contains(.flag("-enable-default-cmo")))
XCTAssertFalse(plannedJobs[1].commandLine.contains(.flag("-enable-default-cmo")))
}
Expand All @@ -3394,7 +3388,7 @@ final class SwiftDriverTests: XCTestCase {
// non optimized builds can emit the module in a separate job.
var driver = try Driver(args: ["swiftc", "foo.swift", "bar.swift", "-module-name", "Test", "-emit-module-path", rebase("Test.swiftmodule", at: root), "-c", "-o", rebase("test.o", at: root), "-wmo" ])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 2 + autoLinkExtractJob)
XCTAssertEqual(plannedJobs.count, 2)
XCTAssertFalse(plannedJobs[0].commandLine.contains(.flag("-enable-default-cmo")))
XCTAssertFalse(plannedJobs[1].commandLine.contains(.flag("-enable-default-cmo")))
}
Expand Down