Skip to content

Commit 660a709

Browse files
committed
Fix build
1 parent 46785ab commit 660a709

File tree

4 files changed

+36
-48
lines changed

4 files changed

+36
-48
lines changed

Sources/SwiftDriver/Driver/Driver.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public struct Driver {
280280
public static let stderrDiagnosticsHandler: DiagnosticsEngine.DiagnosticsHandler = { diagnostic in
281281
let stream = stderrStream
282282
if !(diagnostic.location is UnknownLocation) {
283-
stream <<< diagnostic.location.description <<< ": "
283+
stream <<< diagnostic.location.description <<< ": "
284284
}
285285

286286
switch diagnostic.message.behavior {
@@ -293,7 +293,7 @@ public struct Driver {
293293
case .remark:
294294
stream <<< "remark: "
295295
case .ignored:
296-
break
296+
break
297297
}
298298

299299
stream <<< diagnostic.localizedDescription <<< "\n"

Sources/SwiftDriver/Jobs/WindowsToolchain+LinkerSupport.swift

+8-10
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,13 @@ extension WindowsToolchain {
102102
isShared: hasRuntimeArgs
103103
)
104104

105-
let sharedResourceDirPath = try computeResourceDirPath(
106-
for: targetTriple,
107-
parsedOptions: &parsedOptions,
108-
isShared: true
109-
)
110-
111-
let swiftrtPath = sharedResourceDirPath.appending(
112-
components: archName(for: targetTriple), "swiftrt.obj"
113-
)
105+
guard let swiftrtPath = targetInfo.sdkPath?.path
106+
.appending(
107+
components: "usr", "lib", "swift", "windows",
108+
targetTriple.archName,
109+
"swiftrt.obj") else {
110+
throw ToolchainValidationError.sdkNotFound
111+
}
114112
commandLine.appendPath(swiftrtPath)
115113

116114
let inputFiles: [Job.ArgTemplate] = inputs.compactMap { input in
@@ -138,7 +136,7 @@ extension WindowsToolchain {
138136
// Add the runtime library link paths.
139137
for path in runtimePaths {
140138
commandLine.appendFlag(.L)
141-
commandLine.appendPath(path.appending(component: archName(for: targetTriple)))
139+
commandLine.appendPath(path.appending(component: targetTriple.archName))
142140
}
143141

144142
if hasRuntimeArgs {

Sources/SwiftDriver/Toolchains/WindowsToolchain.swift

+23-33
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,15 @@ import SwiftOptions
2727

2828
// An externally provided path from where we should find tools like ld
2929
public let toolDirectory: AbsolutePath?
30-
31-
public let dummyForTestingObjectFormat = Triple.ObjectFormat.coff
32-
33-
public func archName(for triple: Triple) -> String {
34-
switch triple.arch {
35-
case .aarch64: return "aarch64"
36-
case .arm: return "armv7"
37-
case .x86: return "i386"
38-
case nil, .x86_64: return "x86_64"
39-
default: fatalError("unknown arch \(triple.archName) for Windows")
40-
}
41-
}
4230

43-
public init(env: [String: String], executor: DriverExecutor, fileSystem: FileSystem = localFileSystem, toolDirectory: AbsolutePath? = nil) {
44-
self.env = env
45-
self.executor = executor
46-
self.fileSystem = fileSystem
47-
self.toolDirectory = toolDirectory
48-
}
31+
public let dummyForTestingObjectFormat = Triple.ObjectFormat.coff
4932

50-
33+
public init(env: [String: String], executor: DriverExecutor, fileSystem: FileSystem = localFileSystem, toolDirectory: AbsolutePath? = nil) {
34+
self.env = env
35+
self.executor = executor
36+
self.fileSystem = fileSystem
37+
self.toolDirectory = toolDirectory
38+
}
5139

5240
/// Retrieve the absolute path for a given tool.
5341
public func getToolPath(_ tool: Tool) throws -> AbsolutePath {
@@ -68,7 +56,6 @@ import SwiftOptions
6856
case .staticLinker:
6957
return try lookup(executable: "lib")
7058
case .dynamicLinker:
71-
// FIXME: This needs to look in the tools_directory first.
7259
return try lookup(executable: "link")
7360
case .clang:
7461
return try lookup(executable: "clang")
@@ -88,19 +75,19 @@ import SwiftOptions
8875
public func overrideToolPath(_ tool: Tool, path: AbsolutePath) {
8976
toolPaths[tool] = path
9077
}
91-
92-
/// Path to the StdLib inside the SDK.
93-
public func sdkStdlib(sdk: AbsolutePath, triple: Triple) -> AbsolutePath {
94-
sdk.appending(RelativePath("usr/lib/swift/windows")).appending(component: archName(for: triple))
95-
}
96-
97-
public func makeLinkerOutputFilename(moduleName: String, type: LinkOutputType) -> String {
98-
switch type {
99-
case .executable: return "\(moduleName).exe"
100-
case .dynamicLibrary: return "\(moduleName).dll"
101-
case .staticLibrary: return "lib\(moduleName).lib"
102-
}
78+
79+
/// Path to the StdLib inside the SDK.
80+
public func sdkStdlib(sdk: AbsolutePath, triple: Triple) -> AbsolutePath {
81+
sdk.appending(RelativePath("usr/lib/swift/windows")).appending(component: triple.archName)
82+
}
83+
84+
public func makeLinkerOutputFilename(moduleName: String, type: LinkOutputType) -> String {
85+
switch type {
86+
case .executable: return "\(moduleName).exe"
87+
case .dynamicLibrary: return "\(moduleName).dll"
88+
case .staticLibrary: return "lib\(moduleName).lib"
10389
}
90+
}
10491

10592
public func defaultSDKPath(_ target: Triple?) throws -> AbsolutePath? {
10693
return nil
@@ -113,7 +100,7 @@ import SwiftOptions
113100
targetTriple: Triple,
114101
isShared: Bool
115102
) throws -> String {
116-
return "clang_rt.\(sanitizer.libraryName)-\(archName(for: targetTriple)).lib"
103+
return "clang_rt.\(sanitizer.libraryName)-\(targetTriple.archName).lib"
117104
}
118105
}
119106

@@ -141,13 +128,16 @@ extension WindowsToolchain {
141128
public enum ToolchainValidationError: Error, DiagnosticData {
142129
case argumentNotSupported(String)
143130
case illegalCrtName(String)
131+
case sdkNotFound
144132

145133
public var description: String {
146134
switch self {
147135
case .argumentNotSupported(let argument):
148136
return "\(argument) is not supported for Windows"
149137
case .illegalCrtName(let argument):
150138
return "\(argument) is not a valid C Runtime for Windows"
139+
case .sdkNotFound:
140+
return "swift development on Windows always requires SDK of the target platform"
151141
}
152142
}
153143
}

Sources/swift-driver/main.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -31,9 +31,9 @@ do {
3131
// We are running as a subcommand, try to find the subcommand adjacent to the executable we are running as.
3232
// If we didn't find the tool there, let the OS search for it.
3333
#if os(Windows)
34-
let filename = subcommand + ".exe"
34+
let filename = subcommand + ".exe"
3535
#else
36-
let filename = subcommand
36+
let filename = subcommand
3737
#endif
3838
let subcommandPath = Process.findExecutable(arguments[0])?.parentDirectory.appending(component: filename)
3939
?? Process.findExecutable(filename)

0 commit comments

Comments
 (0)