Skip to content

Commit d8c4f60

Browse files
committed
Fix cross-compilation problems
1 parent 31d2556 commit d8c4f60

File tree

6 files changed

+44
-45
lines changed

6 files changed

+44
-45
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ public struct Driver {
373373
Self.validateProfilingArgs(&parsedOptions,
374374
fileSystem: fileSystem,
375375
workingDirectory: workingDirectory,
376-
diagnosticEngine: diagnosticEngine,
377-
targetTriple: self.frontendTargetInfo.target.triple)
376+
diagnosticEngine: diagnosticEngine)
378377
Self.validateCompilationConditionArgs(&parsedOptions, diagnosticEngine: diagnosticEngine)
379378
Self.validateFrameworkSearchPathArgs(&parsedOptions, diagnosticEngine: diagnosticEngine)
380379
Self.validateCoverageArgs(&parsedOptions, diagnosticsEngine: diagnosticEngine)
@@ -1300,6 +1299,11 @@ extension Driver {
13001299
sanitizerSupported = false
13011300
}
13021301

1302+
// Currently only ASAN is supported on Windows.
1303+
if sanitizer != .address && targetTriple.isWindows {
1304+
sanitizerSupported = false
1305+
}
1306+
13031307
if !sanitizerSupported {
13041308
diagnosticEngine.emit(
13051309
.error_unsupported_opt_for_target(
@@ -1659,32 +1663,12 @@ extension Driver {
16591663
static func validateProfilingArgs(_ parsedOptions: inout ParsedOptions,
16601664
fileSystem: FileSystem,
16611665
workingDirectory: AbsolutePath?,
1662-
diagnosticEngine: DiagnosticsEngine,
1663-
targetTriple: Triple) {
1666+
diagnosticEngine: DiagnosticsEngine) {
16641667
if parsedOptions.hasArgument(.profileGenerate) &&
16651668
parsedOptions.hasArgument(.profileUse) {
16661669
diagnosticEngine.emit(Error.conflictingOptions(.profileGenerate, .profileUse))
16671670
}
16681671

1669-
// Windows executables should be profiled with ETW, whose support needs to be
1670-
// implemented before we can enable the option.
1671-
if targetTriple.isWindows {
1672-
if parsedOptions.hasArgument(.profileGenerate) {
1673-
diagnosticEngine.emit(
1674-
.error_unsupported_opt_for_target(
1675-
arg: "-profile-generate",
1676-
target: targetTriple)
1677-
)
1678-
}
1679-
if parsedOptions.hasArgument(.profileUse) {
1680-
diagnosticEngine.emit(
1681-
.error_unsupported_opt_for_target(
1682-
arg: "-profile-use=",
1683-
target: targetTriple)
1684-
)
1685-
}
1686-
}
1687-
16881672
if let profileArgs = parsedOptions.getLastArgument(.profileUse)?.asMultiple,
16891673
let workingDirectory = workingDirectory ?? fileSystem.currentWorkingDirectory {
16901674
for profilingData in profileArgs {

Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@ extension Toolchain {
119119
parsedOptions: inout ParsedOptions,
120120
isShared: Bool
121121
) throws -> Bool {
122-
// Currently only ASAN is supported on Windows, but clang builds may
123-
// include runtime libraries for unsupported sanitizers. Manually
124-
// disable unsupported sanitizers.
125-
if targetTriple.isWindows && sanitizer != .address {
126-
return false
127-
}
128-
129122
let runtimeName = try runtimeLibraryName(
130123
for: sanitizer,
131124
targetTriple: targetTriple,

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public final class DarwinToolchain: Toolchain {
2626
/// The file system to use for any file operations.
2727
public let fileSystem: FileSystem
2828

29-
/// The suffix of executable files.
30-
public let executableSuffix = ""
31-
3229
/// Doubles as path cache and point for overriding normal lookup
3330
private var toolPaths = [Tool: AbsolutePath]()
3431

Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ public final class GenericUnixToolchain: Toolchain {
2121
/// The file system to use for queries.
2222
public let fileSystem: FileSystem
2323

24-
/// The suffix of executable files.
25-
public let executableSuffix = ""
26-
2724
/// Doubles as path cache and point for overriding normal lookup
2825
private var toolPaths = [Tool: AbsolutePath]()
2926

Sources/SwiftDriver/Toolchains/Toolchain.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public protocol Toolchain {
3838

3939
var executor: DriverExecutor { get }
4040

41-
var executableSuffix: String { get }
42-
4341
/// Retrieve the absolute path to a particular tool.
4442
func getToolPath(_ tool: Tool) throws -> AbsolutePath
4543

@@ -131,7 +129,12 @@ extension Toolchain {
131129
/// looks in the `executableDir`, `xcrunFind` or in the `searchPaths`.
132130
/// - Parameter executable: executable to look for [i.e. `swift`].
133131
func lookup(executable: String) throws -> AbsolutePath {
134-
let filename = executable + executableSuffix
132+
let filename: String
133+
#if os(Windows)
134+
filename = "\(executable).exe"
135+
#else
136+
filename = executable
137+
#endif
135138
if let overrideString = envVar(forExecutable: executable) {
136139
return try AbsolutePath(validating: overrideString)
137140
} else if let path = lookupExecutablePath(filename: filename, searchPaths: [executableDir]) {

Sources/SwiftDriver/Toolchains/WindowsToolchain.swift

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
import TSCBasic
13+
import SwiftOptions
1314

1415
/// Toolchain for Windows.
1516
public final class WindowsToolchain: Toolchain {
@@ -21,9 +22,6 @@ public final class WindowsToolchain: Toolchain {
2122
/// The file system to use for queries.
2223
public let fileSystem: FileSystem
2324

24-
/// The suffix of executable files.
25-
public let executableSuffix = ".exe"
26-
2725
/// Doubles as path cache and point for overriding normal lookup
2826
private var toolPaths = [Tool: AbsolutePath]()
2927

@@ -33,7 +31,7 @@ public final class WindowsToolchain: Toolchain {
3331
case .arm: return "armv7"
3432
case .x86: return "i386"
3533
case nil, .x86_64: return "x86_64"
36-
default: fatalError("unknown arch \(triple.archName) on Windows")
34+
default: fatalError("unknown arch \(triple.archName) for Windows")
3735
}
3836
}
3937

@@ -75,9 +73,9 @@ public final class WindowsToolchain: Toolchain {
7573
case .clang:
7674
return try lookup(executable: "clang")
7775
case .swiftAutolinkExtract:
78-
fatalError("Trying to look up \"swift-autolink-extract\" on Windows")
76+
return try lookup(executable: "swift-autolink-extract")
7977
case .dsymutil:
80-
fatalError("Trying to look up \"dsymutil\" on Windows")
78+
return try lookup(executable: "llvm-dsymutil")
8179
case .lldb:
8280
return try lookup(executable: "lldb")
8381
case .dwarfdump:
@@ -105,3 +103,30 @@ public final class WindowsToolchain: Toolchain {
105103
return "clang_rt.\(sanitizer.libraryName)-\(archName(for: targetTriple)).lib"
106104
}
107105
}
106+
107+
extension WindowsToolchain {
108+
public func validateArgs(_ parsedOptions: inout ParsedOptions,
109+
targetTriple: Triple,
110+
targetVariantTriple: Triple?,
111+
diagnosticsEngine: DiagnosticsEngine) throws {
112+
// Windows executables should be profiled with ETW, whose support needs to be
113+
// implemented before we can enable the option.
114+
if parsedOptions.hasArgument(.profileGenerate) {
115+
throw ToolchainValidationError.argumentNotSupported("-profile-generate")
116+
}
117+
if parsedOptions.hasArgument(.profileUse) {
118+
throw ToolchainValidationError.argumentNotSupported("-profile-use=")
119+
}
120+
}
121+
}
122+
123+
public enum ToolchainValidationError: Error, DiagnosticData {
124+
case argumentNotSupported(String)
125+
126+
public var description: String {
127+
switch self {
128+
case .argumentNotSupported(let argument):
129+
return "\(argument) is not supported for Windows"
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)