Skip to content

Commit 0ceb626

Browse files
Do not inherit host destination's extra flags for target destination
Host environment specific flags, such as XCTest module directory, were implicitly inherited by target destination. It caused unexpected reference to host module file, so drop them explicitly
1 parent 6f8a435 commit 0ceb626

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

Sources/Commands/SwiftTool.swift

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,9 @@ public class SwiftTool {
838838
// Create custom toolchain if present.
839839
if let customDestination = self.options.customCompileDestination {
840840
destination = try Destination(fromFile: customDestination)
841+
} else if let target = self.options.customCompileTriple,
842+
let targetDestination = Destination.defaultDestination(for: target, host: hostDestination) {
843+
destination = targetDestination
841844
} else {
842845
// Otherwise use the host toolchain.
843846
destination = hostDestination
@@ -854,18 +857,6 @@ public class SwiftTool {
854857
}
855858
if let sdk = self.options.customCompileSDK {
856859
destination.sdk = sdk
857-
} else if let target = destination.target, target.isWASI() {
858-
// Set default SDK path when target is WASI whose SDK is embeded
859-
// in Swift toolchain
860-
do {
861-
let compilers = try UserToolchain.determineSwiftCompilers(binDir: destination.binDir)
862-
destination.sdk = compilers.compile
863-
.parentDirectory // bin
864-
.parentDirectory // usr
865-
.appending(components: "share", "wasi-sysroot")
866-
} catch {
867-
return .failure(error)
868-
}
869860
}
870861
destination.archs = options.archs
871862

Sources/Workspace/Destination.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ public struct Destination: Encodable, Equatable {
178178
}
179179
/// Cache storage for sdk platform path.
180180
private static var _sdkPlatformFrameworkPath: (fwk: AbsolutePath, lib: AbsolutePath)? = nil
181+
182+
/// Returns a default destination of a given target environment
183+
public static func defaultDestination(for triple: Triple, host: Destination) -> Destination? {
184+
if triple.isWASI() {
185+
let wasiSysroot = host.binDir
186+
.parentDirectory // usr
187+
.appending(components: "share", "wasi-sysroot")
188+
return Destination(
189+
target: triple,
190+
sdk: wasiSysroot,
191+
binDir: host.binDir,
192+
extraCCFlags: [],
193+
extraSwiftCFlags: [],
194+
extraCPPFlags: []
195+
)
196+
}
197+
return nil
198+
}
181199
}
182200

183201
extension Destination {

0 commit comments

Comments
 (0)