Skip to content

Commit 115874c

Browse files
authored
Exclude swift-autolink-extractor no-op job for embedded Wasm (#1801)
This driver job has no effect (all autolinking sections are empty when building in this mode) and is actually prone to failure when Wasm reference types are used: ``` error: autolink-extract command failed with exit code 1 (use -v to see invocation) .build/wasm32-unknown-none-wasm/release/externref.build/externref.c.o' (invalid data relocation: table) ```
1 parent 6be25d9 commit 115874c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ import struct TSCBasic.RelativePath
1818
// FIXME: Also handle Cygwin and MinGW
1919
extension Driver {
2020
/*@_spi(Testing)*/ public var isAutolinkExtractJobNeeded: Bool {
21-
[.elf, .wasm].contains(targetTriple.objectFormat) && lto == nil &&
22-
linkerOutputType != nil
21+
mutating get {
22+
switch targetTriple.objectFormat {
23+
case .wasm where !parsedOptions.isEmbeddedEnabled:
24+
fallthrough
25+
26+
case .elf:
27+
return lto == nil && linkerOutputType != nil
28+
29+
default:
30+
return false
31+
}
32+
}
2333
}
2434

2535
mutating func autolinkExtractJob(inputs: [TypedVirtualPath]) throws -> Job? {

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6803,10 +6803,9 @@ final class SwiftDriverTests: XCTestCase {
68036803
do {
68046804
var driver = try Driver(args: ["swiftc", "-target", "wasm32-none-none-wasm", "test.swift", "-enable-experimental-feature", "Embedded", "-wmo", "-o", "a.wasm"], env: env)
68056805
let plannedJobs = try driver.planBuild()
6806-
XCTAssertEqual(plannedJobs.count, 3)
6806+
XCTAssertEqual(plannedJobs.count, 2)
68076807
let compileJob = plannedJobs[0]
6808-
let _ /*autolinkJob*/ = plannedJobs[1]
6809-
let linkJob = plannedJobs[2]
6808+
let linkJob = plannedJobs[1]
68106809
XCTAssertJobInvocationMatches(compileJob, .flag("-disable-objc-interop"))
68116810
XCTAssertFalse(linkJob.commandLine.contains(.flag("-force_load")))
68126811
XCTAssertFalse(linkJob.commandLine.contains(.flag("-rpath")))
@@ -6817,9 +6816,8 @@ final class SwiftDriverTests: XCTestCase {
68176816
do {
68186817
var driver = try Driver(args: ["swiftc", "-target", "wasm32-none-none-wasm", "test.o", "-enable-experimental-feature", "Embedded", "-wmo", "-o", "a.wasm"], env: env)
68196818
let plannedJobs = try driver.planBuild()
6820-
XCTAssertEqual(plannedJobs.count, 2)
6821-
let _ /*autolinkJob*/ = plannedJobs[0]
6822-
let linkJob = plannedJobs[1]
6819+
XCTAssertEqual(plannedJobs.count, 1)
6820+
let linkJob = plannedJobs[0]
68236821
XCTAssertFalse(linkJob.commandLine.contains(.flag("-force_load")))
68246822
XCTAssertFalse(linkJob.commandLine.contains(.flag("-rpath")))
68256823
XCTAssertFalse(linkJob.commandLine.contains(.flag("-lswiftCore")))

0 commit comments

Comments
 (0)