Skip to content

Commit 603d7ee

Browse files
Do not inherit host destination's extra flags for target destination (#3703)
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 87126a3 commit 603d7ee

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
@@ -791,6 +791,9 @@ public class SwiftTool {
791791
// Create custom toolchain if present.
792792
if let customDestination = self.options.customCompileDestination {
793793
destination = try Destination(fromFile: customDestination)
794+
} else if let target = self.options.customCompileTriple,
795+
let targetDestination = Destination.defaultDestination(for: target, host: hostDestination) {
796+
destination = targetDestination
794797
} else {
795798
// Otherwise use the host toolchain.
796799
destination = hostDestination
@@ -807,18 +810,6 @@ public class SwiftTool {
807810
}
808811
if let sdk = self.options.customCompileSDK {
809812
destination.sdk = sdk
810-
} else if let target = destination.target, target.isWASI() {
811-
// Set default SDK path when target is WASI whose SDK is embeded
812-
// in Swift toolchain
813-
do {
814-
let compilers = try UserToolchain.determineSwiftCompilers(binDir: destination.binDir)
815-
destination.sdk = compilers.compile
816-
.parentDirectory // bin
817-
.parentDirectory // usr
818-
.appending(components: "share", "wasi-sysroot")
819-
} catch {
820-
return .failure(error)
821-
}
822813
}
823814
destination.archs = options.archs
824815

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)