Skip to content

Do not inherit host destination's extra flags for target destination when cross-compiling #3703

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

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
15 changes: 3 additions & 12 deletions Sources/Commands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ public class SwiftTool {
// Create custom toolchain if present.
if let customDestination = self.options.customCompileDestination {
destination = try Destination(fromFile: customDestination)
} else if let target = self.options.customCompileTriple,
let targetDestination = Destination.defaultDestination(for: target, host: hostDestination) {
destination = targetDestination
} else {
// Otherwise use the host toolchain.
destination = hostDestination
Expand All @@ -854,18 +857,6 @@ public class SwiftTool {
}
if let sdk = self.options.customCompileSDK {
destination.sdk = sdk
} else if let target = destination.target, target.isWASI() {
// Set default SDK path when target is WASI whose SDK is embeded
// in Swift toolchain
do {
let compilers = try UserToolchain.determineSwiftCompilers(binDir: destination.binDir)
destination.sdk = compilers.compile
.parentDirectory // bin
.parentDirectory // usr
.appending(components: "share", "wasi-sysroot")
} catch {
return .failure(error)
}
}
destination.archs = options.archs

Expand Down
18 changes: 18 additions & 0 deletions Sources/Workspace/Destination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@ public struct Destination: Encodable, Equatable {
}
/// Cache storage for sdk platform path.
private static var _sdkPlatformFrameworkPath: (fwk: AbsolutePath, lib: AbsolutePath)? = nil

/// Returns a default destination of a given target environment
public static func defaultDestination(for triple: Triple, host: Destination) -> Destination? {
if triple.isWASI() {
let wasiSysroot = host.binDir
.parentDirectory // usr
.appending(components: "share", "wasi-sysroot")
return Destination(
target: triple,
sdk: wasiSysroot,
binDir: host.binDir,
extraCCFlags: [],
extraSwiftCFlags: [],
extraCPPFlags: []
)
}
return nil
}
}

extension Destination {
Expand Down