Skip to content
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

[DNM][WIP] Implement Windows toolchain #419

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9fcd3f2
Implement WindowsToolchain
stevapple Sep 13, 2020
9076ab2
Fix swiftrtPath
stevapple Sep 13, 2020
2c9716b
Fix various problems
stevapple Sep 14, 2020
8b7b0df
Derive executable file name from Toolchain
stevapple Sep 14, 2020
3c0feb3
Fix addPlatformSpecificLinkerArgs for WindowsToolchain
stevapple Sep 14, 2020
633801d
Fix clangLibraryPath for Windows
stevapple Sep 14, 2020
59877f1
Disable profiling support on Windows
stevapple Sep 16, 2020
4b69ec6
Disable unsupported sanitizers on Windows
stevapple Sep 16, 2020
31d2556
Merge branch 'master' into windows-toolchain
stevapple Sep 17, 2020
d8c4f60
Fix cross-compilation problems
stevapple Sep 17, 2020
ed1b8c2
Fix CRT support for Windows
stevapple Sep 17, 2020
4bd5495
Keep update with the latest layout
stevapple Dec 19, 2020
7e82541
Fix subcommand discovery
stevapple Dec 19, 2020
46785ab
Merge branch 'main' into windows-toolchain
stevapple Dec 19, 2020
660a709
Fix build
stevapple Dec 19, 2020
b1e5ef9
Implement functions to depress warnings
stevapple Dec 19, 2020
e270919
Disable LTO support on Windows
stevapple Dec 19, 2020
aa908ad
Improve flags usage
stevapple Dec 20, 2020
a3ca4ab
Fix MSVC Runtime options
stevapple Dec 20, 2020
5d38461
Minor fixes
stevapple Feb 20, 2021
204f061
Merge changes from upstream
stevapple Feb 20, 2021
6909152
Fix PATH
stevapple Feb 20, 2021
aa427ed
Fix some tests on Windows
stevapple Feb 23, 2021
58c6f7a
Fix some tests on Windows
stevapple Feb 23, 2021
9d308f1
Merge 'upstream/main' into windows-toolchain
stevapple Feb 23, 2021
a666df9
Minor fixes
stevapple Feb 23, 2021
d48e3e1
Style fixes
stevapple Feb 24, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/*.xcodeproj
xcuserdata/
.swiftpm
.idea/
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"repositoryURL": "https://github.com/apple/swift-argument-parser.git",
"state": {
"branch": null,
"revision": "92646c0cdbaca076c8d3d0207891785b3379cbff",
"version": "0.3.1"
"revision": "9564d61b08a5335ae0a36f789a7d71493eacadfc",
"version": "0.3.2"
}
},
{
"package": "llbuild",
"repositoryURL": "https://github.com/apple/swift-llbuild.git",
"state": {
"branch": "main",
"revision": "53e245a2cf429e0d97633c633ca9968f5eb21b15",
"revision": "1a03ded2f228eb602779add2ddf3f0c665384fbd",
"version": null
}
},
Expand All @@ -24,7 +24,7 @@
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": "main",
"revision": "207f9c6bc5e33eb8383266c0cd3129c1276f534b",
"revision": "2954e55faee5bfee928e844bb09e97fcfa8d24af",
"version": null
}
},
Expand All @@ -33,8 +33,8 @@
"repositoryURL": "https://github.com/jpsim/Yams.git",
"state": {
"branch": null,
"revision": "1bce5b89a11912fb8a8c48bd404bd24979472f27",
"version": "4.0.3"
"revision": "9003d51672e516cc59297b7e96bff1dfdedcb4ea",
"version": "4.0.4"
}
}
]
Expand Down
20 changes: 10 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ let package = Package(
dependencies: ["SwiftOptions", "ArgumentParser", "SwiftToolsSupport-auto"]),

/// The `makeOptions` utility (for importing option definitions).
.target(
name: "makeOptions",
dependencies: []),
// .target(
// name: "makeOptions",
// dependencies: []),
],
cxxLanguageStandard: .cxx14
)
Expand All @@ -98,13 +98,13 @@ if ProcessInfo.processInfo.environment["SWIFT_DRIVER_LLBUILD_FWK"] == nil {
}

if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("main")),
.package(url: "https://github.com/jpsim/Yams.git", .upToNextMinor(from: "4.0.0")),
// The 'swift-argument-parser' version declared here must match that
// used by 'swift-package-manager' and 'sourcekit-lsp'. Please coordinate
// dependency version changes here with those projects.
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.1")),
package.dependencies += [
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("main")),
.package(url: "https://github.com/jpsim/Yams.git", .upToNextMinor(from: "4.0.0")),
// The 'swift-argument-parser' version declared here must match that
// used by 'swift-package-manager' and 'sourcekit-lsp'. Please coordinate
// dependency version changes here with those projects.
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.2")),
]
} else {
package.dependencies += [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ The goal of the new Swift driver is to provide a drop-in replacement for the exi
* Platform support
* [x] Teach the `DarwinToolchain` to also handle iOS, tvOS, watchOS
* [x] Fill out the `GenericUnixToolchain` toolchain to get it working
* [ ] Implement a `WindowsToolchain`
* [x] Implement a `WindowsToolchain`
* [x] Implement proper tokenization for response files
* Compilation modes
* [x] Batch mode
Expand Down
4 changes: 3 additions & 1 deletion Sources/SwiftDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -79,11 +79,13 @@ add_library(SwiftDriver
Jobs/Toolchain+LinkerSupport.swift
Jobs/VerifyDebugInfoJob.swift
Jobs/VerifyModuleInterfaceJob.swift
Jobs/WindowsToolchain+LinkerSupport.swift
Jobs/WebAssemblyToolchain+LinkerSupport.swift

Toolchains/DarwinToolchain.swift
Toolchains/GenericUnixToolchain.swift
Toolchains/Toolchain.swift
Toolchains/WindowsToolchain.swift
Toolchains/WebAssemblyToolchain.swift

Utilities/DOTJobGraphSerializer.swift
Expand Down
28 changes: 22 additions & 6 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public struct Driver {
public static let stderrDiagnosticsHandler: DiagnosticsEngine.DiagnosticsHandler = { diagnostic in
let stream = stderrStream
if !(diagnostic.location is UnknownLocation) {
stream <<< diagnostic.location.description <<< ": "
stream <<< diagnostic.location.description <<< ": "
}

switch diagnostic.message.behavior {
Expand All @@ -324,7 +324,7 @@ public struct Driver {
case .remark:
stream <<< "remark: "
case .ignored:
break
break
}

stream <<< diagnostic.localizedDescription <<< "\n"
Expand Down Expand Up @@ -386,7 +386,7 @@ public struct Driver {

// Determine the compilation mode.
self.compilerMode = try Self.computeCompilerMode(&parsedOptions, driverKind: driverKind, diagnosticsEngine: diagnosticEngine)

self.shouldAttemptIncrementalCompilation = Self.shouldAttemptIncrementalCompilation(&parsedOptions,
diagnosticEngine: diagnosticsEngine,
compilerMode: compilerMode)
Expand Down Expand Up @@ -492,6 +492,9 @@ public struct Driver {
self.numParallelJobs = Self.determineNumParallelJobs(&parsedOptions, diagnosticsEngine: diagnosticEngine, env: env)

Self.validateWarningControlArgs(&parsedOptions, diagnosticEngine: diagnosticEngine)
Self.validateCRuntimeArgs(&parsedOptions,
diagnosticEngine: diagnosticsEngine,
targetTriple: self.frontendTargetInfo.target.triple)
Self.validateProfilingArgs(&parsedOptions,
fileSystem: fileSystem,
workingDirectory: workingDirectory,
Expand Down Expand Up @@ -795,7 +798,7 @@ extension Driver {
///
/// - Parameter content: response file's content to be tokenized.
private static func tokenizeResponseFile(_ content: String) -> [String] {
#if !os(macOS) && !os(Linux) && !os(Android)
#if !os(macOS) && !os(Linux) && !os(Android) && !os(Windows)
#warning("Response file tokenization unimplemented for platform; behavior may be incorrect")
#endif
return content.split { $0 == "\n" || $0 == "\r\n" }
Expand Down Expand Up @@ -1688,6 +1691,11 @@ extension Driver {
sanitizerSupported = false
}

// Currently only ASAN is supported on Windows.
if sanitizer != .address && targetTriple.isWindows {
sanitizerSupported = false
}

if !sanitizerSupported {
diagnosticEngine.emit(
.error_unsupported_opt_for_target(
Expand Down Expand Up @@ -2051,6 +2059,14 @@ extension Driver {
}
}

static func validateCRuntimeArgs(_ parsedOptions: inout ParsedOptions,
diagnosticEngine: DiagnosticsEngine,
targetTriple: Triple) {
if parsedOptions.hasArgument(.libc) && !targetTriple.isWindows {
diagnosticEngine.emit(.error_unsupported_opt_for_target(arg: "-libc", target: targetTriple))
}
}

static func validateProfilingArgs(_ parsedOptions: inout ParsedOptions,
fileSystem: FileSystem,
workingDirectory: AbsolutePath?,
Expand Down Expand Up @@ -2138,7 +2154,7 @@ extension Triple {
case .wasi:
return WebAssemblyToolchain.self
case .win32:
fatalError("Windows target not supported yet")
return WindowsToolchain.self
default:
diagnosticsEngine.emit(.error_unknown_target(triple))
throw Diagnostics.fatalError
Expand All @@ -2151,7 +2167,7 @@ extension Driver {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
static let defaultToolchainType: Toolchain.Type = DarwinToolchain.self
#elseif os(Windows)
static let defaultToolchainType: Toolchain.Type = { fatalError("Windows target not supported yet") }()
static let defaultToolchainType: Toolchain.Type = WindowsToolchain.self
#else
static let defaultToolchainType: Toolchain.Type = GenericUnixToolchain.self
#endif
Expand Down
5 changes: 3 additions & 2 deletions Sources/SwiftDriver/Driver/OutputFileMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public struct OutputFileMap: Hashable, Codable {
try fileSystem.writeFileContents(file, bytes: ByteString(contents))
}

/// Human-readable texual representation
/// Human-readable textual representation
var description: String {
var result = ""
func outputPairDescription(inputPath: VirtualPath, outputPair: (FileType, VirtualPath))
Expand Down Expand Up @@ -229,7 +229,8 @@ fileprivate struct OutputFileMapJSON: Codable {

/// Converts into virtual path entries.
func toVirtualOutputFileMap() throws -> [VirtualPath : [FileType : VirtualPath]] {
Dictionary(try entries.map { input, entry in
// TODO: Remove the filter after swift-tools-support-core#191
Dictionary(try entries.filter { $0.0 != "" }.map { input, entry in
(try VirtualPath(path: input), try entry.paths.mapValues(VirtualPath.init(path:)))
}, uniquingKeysWith: { $1 })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

// Use the type system to ensure that dependencies are transitively closed
// without doing too much work at the leaves of the call tree

public struct Transitively {}
public struct Directly {}

Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftDriver/Jobs/CommandLineArguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ extension Array where Element == Job.ArgTemplate {
public var joinedUnresolvedArguments: String {
return self.map {
switch $0 {
case .flag(let string):
return string.spm_shellEscaped()
case .path(let path):
return path.name.spm_shellEscaped()
case .flag(let string):
return string.spm_shellEscaped()
case .path(let path):
return path.name.spm_shellEscaped()
case .responseFilePath(let path):
return "@\(path.name.spm_shellEscaped())"
case let .joinedOptionAndPath(option, path):
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/Planning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extension Driver {
jobsBeforeCompiles.append(job)
}

var compileJobGroups = [CompileJobGroup]()
var compileJobGroups = [CompileJobGroup]()
func addCompileJobGroup(_ group: CompileJobGroup) {
compileJobGroups.append(group)
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/SwiftDriver/Jobs/Toolchain+InterpreterSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,14 @@ extension GenericUnixToolchain {
return envVars
}
}

extension WindowsToolchain {
public func platformSpecificInterpreterEnvironmentVariables(
env: [String : String],
parsedOptions: inout ParsedOptions,
sdkPath: VirtualPath?,
targetInfo: FrontendTargetInfo) throws -> [String: String] {
// TODO: See whether Windows needs `platformSpecificInterpreterEnvironmentVariables`
return [:]
}
}
8 changes: 6 additions & 2 deletions Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -50,7 +50,11 @@ extension Toolchain {
result.append(sdkPath.appending(components: "System", "iOSSupport", "usr", "lib", "swift"))
}

result.append(sdkPath.appending(components: "usr", "lib", "swift"))
if (triple.isWindows) {
result.append(sdkPath.appending(components: "usr", "lib", "swift", "windows"))
} else {
Comment on lines +53 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used to find the correct path to the runtime, or something else maybe? I know in a few other places we append targetTriple.platformName() only when needed which might help remove the workaround here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referred to the current layout of Windows toolchain and SDK, which is slightly different from other platforms. I think we need to unify SDK layout for the convenience of cross-compilation (and to eliminate differences across platforms), how do you think @compnerd ?

result.append(sdkPath.appending(components: "usr", "lib", "swift"))
}
}

return result
Expand Down
Loading