Skip to content

Commit 38b8883

Browse files
committed
Merge remote-tracking branch 'origin/master' into cs_OnlyOneDependencyFile
2 parents 32cb042 + 360b48b commit 38b8883

23 files changed

+364
-84
lines changed

CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
cmake_minimum_required(VERSION 3.15.1)
10+
11+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
12+
13+
project(SwiftDriver LANGUAGES Swift)
14+
15+
set(SWIFT_VERSION 5)
16+
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})
17+
if(CMAKE_VERSION VERSION_LESS 3.16)
18+
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-swift-version$<SEMICOLON>${SWIFT_VERSION}>)
19+
set(CMAKE_LINK_LIBRARY_FLAG "-l")
20+
endif()
21+
22+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
23+
24+
if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows)
25+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
26+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
27+
else()
28+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
29+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
30+
endif()
31+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
32+
33+
option(BUILD_SHARED_LIBS "Build shared libraryes by default" YES)
34+
35+
find_package(TSC CONFIG REQUIRED)
36+
37+
find_package(LLBuild CONFIG)
38+
if(NOT LLBuild_FOUND)
39+
find_package(LLBuild REQUIRED)
40+
endif()
41+
42+
find_package(dispatch QUIET)
43+
find_package(Foundation QUIET)
44+
find_package(Yams CONFIG REQUIRED)
45+
46+
add_subdirectory(Sources)
47+
add_subdirectory(cmake/modules)

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// swift-tools-version:5.1
22
import PackageDescription
3+
import class Foundation.ProcessInfo
34

45
let package = Package(
56
name: "swift-driver",
67
platforms: [
7-
.macOS(.v10_13),
8+
.macOS(.v10_10),
89
],
910
products: [
1011
.executable(
@@ -20,11 +21,6 @@ let package = Package(
2021
name: "SwiftOptions",
2122
targets: ["SwiftOptions"]),
2223
],
23-
dependencies: [
24-
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("master")),
25-
.package(url: "https://github.com/apple/swift-llbuild.git", .branch("master")),
26-
.package(url: "https://github.com/jpsim/Yams.git", .branch("master")),
27-
],
2824
targets: [
2925
/// The driver library.
3026
.target(
@@ -59,3 +55,17 @@ let package = Package(
5955
],
6056
cxxLanguageStandard: .cxx14
6157
)
58+
59+
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
60+
package.dependencies += [
61+
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("master")),
62+
.package(url: "https://github.com/apple/swift-llbuild.git", .branch("master")),
63+
.package(url: "https://github.com/jpsim/Yams.git", .branch("master")),
64+
]
65+
} else {
66+
package.dependencies += [
67+
.package(path: "../swiftpm/swift-tools-support-core"),
68+
.package(path: "../yams"),
69+
.package(path: "../llbuild"),
70+
]
71+
}

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The `swift-driver` project is a new implementation of the Swift compiler driver
1111

1212
## Getting Started
1313

14-
Use the Swift package manager to build `swift-driver`:
14+
The preferred way to build `swift-driver` is to use the Swift package manager:
1515

1616
```
1717
$ swift build
@@ -32,6 +32,26 @@ SWIFT_EXEC=$SOME_PATH/swiftc swift build
3232

3333
Similarly, one can use the new Swift driver within Xcode by adding a custom build setting (usually at the project level) named `SWIFT_EXEC` that refers to `$SOME_PATH/swiftc`.
3434

35+
## Building with CMake
36+
37+
`swift-driver` can also be built with CMake, which is suggested for
38+
environments where the Swift Package Manager is not yet
39+
available. Doing so requires several dependencies to be built first,
40+
all with CMake:
41+
42+
* (Non-Apple platforms only) [swift-corelibs-foundation](https://github.com/apple/swift-corelibs-foundation)
43+
* [llbuild](https://github.com/apple/swift-llbuild) configure CMake with `-DLLBUILD_SUPPORT_BINDINGS="Swift"` when building
44+
```
45+
cmake -B <llbuild-build-dir> -G Ninja <llbuild-source-dir> -DLLBUILD_SUPPORT_BINDINGS="Swift"
46+
```
47+
* [Yams](https://github.com/jpsim/Yams)
48+
49+
Once those dependencies have built, build `swift-driver` itself:
50+
```
51+
cmake -B <swift-driver-build-dir> -G Ninja <swift-driver-source-dir> -DTSC_DIR=<swift-tools-support-core-build-dir>/cmake/modules -DLLBuild_DIR=<llbuild-build-dir>/cmake/modules -DYams_DIR=<yamls-build-dir>/cmake/modules
52+
cmake --build <swift-driver-build-dir>
53+
```
54+
3555
## Developing `swift-driver`
3656

3757
The new Swift driver is a work in progress, and there are numerous places for anyone with an interest to contribute! This section covers testing, miscellaneous development tips and tricks, and a rough development plan showing what work still needs to be done.

Sources/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_subdirectory(SwiftOptions)
10+
add_subdirectory(SwiftDriver)
11+
add_subdirectory(swift-driver)
12+
add_subdirectory(swift-help)

Sources/SwiftDriver/CMakeLists.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(SwiftDriver
10+
Driver/CompilerMode.swift
11+
Driver/DebugInfo.swift
12+
Driver/Driver.swift
13+
Driver/LinkKind.swift
14+
Driver/OutputFileMap.swift
15+
Driver/ToolExecutionDelegate.swift
16+
17+
Execution/JobExecutor.swift
18+
Execution/ParsableOutput.swift
19+
Execution/ProcessProtocol.swift
20+
Execution/llbuild.swift
21+
22+
"Incremental Compilation/IncrementalCompilation.swift"
23+
"Incremental Compilation/InputIInfoMap.swift"
24+
"Incremental Compilation/InputInfo.swift"
25+
26+
Jobs/AutolinkExtractJob.swift
27+
Jobs/CommandLineArguments.swift
28+
Jobs/CompileJob.swift
29+
Jobs/DarwinToolchain+LinkerSupport.swift
30+
Jobs/EmitModuleJob.swift
31+
Jobs/FrontendJobHelpers.swift
32+
Jobs/GenerateDSYMJob.swift
33+
Jobs/GeneratePCHJob.swift
34+
Jobs/GeneratePCMJob.swift
35+
Jobs/GenericUnixToolchain+LinkerSupport.swift
36+
Jobs/InterpretJob.swift
37+
Jobs/Job.swift
38+
Jobs/LinkJob.swift
39+
Jobs/MergeModuleJob.swift
40+
Jobs/Planning.swift
41+
Jobs/ReplJob.swift
42+
Jobs/Toolchain+InterpreterSupport.swift
43+
Jobs/Toolchain+LinkerSupport.swift
44+
Jobs/VerifyDebugInfoJob.swift
45+
46+
Toolchains/DarwinToolchain.swift
47+
Toolchains/GenericUnixToolchain.swift
48+
Toolchains/Toolchain.swift
49+
50+
Utilities/DOTJobGraphSerializer.swift
51+
Utilities/DateAdditions.swift
52+
Utilities/Diagnostics.swift
53+
Utilities/FileType.swift
54+
Utilities/PredictableRandomNumberGenerator.swift
55+
Utilities/RelativePathAdditions.swift
56+
Utilities/Sanitizer.swift
57+
Utilities/StringAdditions.swift
58+
Utilities/System.swift
59+
Utilities/Triple+Platforms.swift
60+
Utilities/Triple.swift
61+
Utilities/TypedVirtualPath.swift
62+
Utilities/VirtualPath.swift)
63+
64+
target_link_libraries(SwiftDriver PUBLIC
65+
TSCBasic
66+
SwiftOptions
67+
llbuildSwift
68+
CYaml
69+
Yams)
70+
71+
set_property(GLOBAL APPEND PROPERTY SWIFTDRIVER_EXPORTS SwiftDriver)
72+
73+
# NOTE: workaround for CMake not setting up include flags yet
74+
set_target_properties(SwiftDriver PROPERTIES
75+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
76+

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ public enum ModuleOutput: Equatable {
4242

4343
/// The Swift driver.
4444
public struct Driver {
45-
public enum Error: Swift.Error, DiagnosticData {
45+
public enum Error: Swift.Error, Equatable, DiagnosticData {
4646
case invalidDriverName(String)
4747
case invalidInput(String)
4848
case noJobsPassedToDriverFromEmptyInputFileList
4949
case relativeFrontendPath(String)
5050
case subcommandPassedToDriver
51+
case integratedReplRemoved
5152

5253
public var description: String {
5354
switch self {
@@ -62,6 +63,8 @@ public struct Driver {
6263
return "relative frontend path: \(path)"
6364
case .subcommandPassedToDriver:
6465
return "subcommand passed to driver"
66+
case .integratedReplRemoved:
67+
return "Compiler-internal integrated REPL has been removed; use the LLDB-enhanced REPL instead."
6568
}
6669
}
6770
}
@@ -298,7 +301,7 @@ public struct Driver {
298301
}
299302

300303
// Determine the compilation mode.
301-
self.compilerMode = Self.computeCompilerMode(&parsedOptions, driverKind: driverKind, diagnosticsEngine: diagnosticEngine)
304+
self.compilerMode = try Self.computeCompilerMode(&parsedOptions, driverKind: driverKind, diagnosticsEngine: diagnosticEngine)
302305

303306
// Figure out the primary outputs from the driver.
304307
(self.compilerOutputType, self.linkerOutputType) = Self.determinePrimaryOutputs(&parsedOptions, driverKind: driverKind, diagnosticsEngine: diagnosticEngine)
@@ -764,16 +767,19 @@ extension Driver {
764767
_ parsedOptions: inout ParsedOptions,
765768
driverKind: DriverKind,
766769
diagnosticsEngine: DiagnosticsEngine
767-
) -> CompilerMode {
770+
) throws -> CompilerMode {
768771
// Some output flags affect the compiler mode.
769772
if let outputOption = parsedOptions.getLast(in: .modes) {
770773
switch outputOption.option {
771774
case .emitPch, .emitImportedModules:
772775
return .singleCompile
773776

774-
case .repl, .deprecatedIntegratedRepl, .lldbRepl:
777+
case .repl, .lldbRepl:
775778
return .repl
776779

780+
case .deprecatedIntegratedRepl:
781+
throw Error.integratedReplRemoved
782+
777783
case .emitPcm:
778784
return .compilePCM
779785

Sources/SwiftDriver/Execution/JobExecutor.swift

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ struct JobExecutorBuildDelegate: LLBuildEngineDelegate {
256256
case ExecuteAllJobsRule.ruleName:
257257
return ExecuteAllJobsRule(key)
258258
case ExecuteJobRule.ruleName:
259-
return ExecuteJobRule(key)
259+
return ExecuteJobRule(key, context: context)
260260
default:
261261
fatalError("Unknown rule \(rule)")
262262
}
@@ -336,18 +336,18 @@ class ExecuteJobRule: LLBuildRule {
336336
override class var ruleName: String { "\(ExecuteJobRule.self)" }
337337

338338
private let key: RuleKey
339+
private let context: JobExecutor.Context
339340

340341
/// True if any of the inputs had any error.
341342
private var allInputsSucceeded: Bool = true
342343

343-
init(_ key: Key) {
344+
init(_ key: Key, context: JobExecutor.Context) {
344345
self.key = RuleKey(key)
346+
self.context = context
345347
super.init()
346348
}
347349

348350
override func start(_ engine: LLTaskBuildEngine) {
349-
let context = engine.jobExecutorContext
350-
351351
for (idx, input) in key.job.inputs.enumerated() {
352352
if let producingJob = context.producerMap[input.file] {
353353
let key = ExecuteJobRule.RuleKey(job: producingJob)
@@ -375,14 +375,11 @@ class ExecuteJobRule: LLBuildRule {
375375
return engine.taskIsComplete(DriverBuildValue.jobExecution(success: false))
376376
}
377377

378-
let context = engine.jobExecutorContext
379-
context.jobQueue.addOperation {
380-
self.executeJob(engine)
381-
}
378+
engine.taskIsComplete(self.executeJob(engine))
382379
}
383380

384-
private func executeJob(_ engine: LLTaskBuildEngine) {
385-
let context = engine.jobExecutorContext
381+
private func executeJob(_ engine: LLTaskBuildEngine) -> DriverBuildValue {
382+
let context = self.context
386383
let resolver = context.argsResolver
387384
let job = key.job
388385
let env = context.env.merging(job.extraEnvironment, uniquingKeysWith: { $1 })
@@ -423,6 +420,7 @@ class ExecuteJobRule: LLBuildRule {
423420
context.delegateQueue.async {
424421
let result = ProcessResult(
425422
arguments: [],
423+
environment: env,
426424
exitStatus: .terminated(code: 1),
427425
output: Result.success([]),
428426
stderrOutput: Result.success([])
@@ -432,15 +430,8 @@ class ExecuteJobRule: LLBuildRule {
432430
value = .jobExecution(success: false)
433431
}
434432

435-
engine.taskIsComplete(value)
433+
return value
436434
}
437435
}
438436

439437
extension Job: LLBuildValue { }
440-
441-
extension LLTaskBuildEngine {
442-
/// Returns the job executor context.
443-
var jobExecutorContext: JobExecutor.Context {
444-
return (delegate as! JobExecutorBuildDelegate).context
445-
}
446-
}

Sources/SwiftDriver/Execution/ParsableOutput.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public struct ParsableMessage {
3030

3131
public func toJSON() throws -> Data {
3232
let encoder = JSONEncoder()
33-
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
33+
if #available(macOS 10.13, *) {
34+
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
35+
} else {
36+
encoder.outputFormatting = [.prettyPrinted]
37+
}
3438
return try encoder.encode(self)
3539
}
3640
}

Sources/SwiftDriver/Execution/llbuild.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ public class LLTaskBuildEngine {
111111
self.engine = engine
112112
}
113113

114-
var delegate: LLBuildEngineDelegate {
115-
return (engine.engine.delegate as! LLBuildEngine.Delegate).delegate
116-
}
117-
118114
public func taskNeedsInput<T: LLBuildKey>(_ key: T, inputID: Int) {
119115
let encodedKey = RuleKey(
120116
rule: T.BuildRule.ruleName, data: key.toKey().data).toKey()

0 commit comments

Comments
 (0)