Skip to content

Commit 4bd5495

Browse files
committed
Keep update with the latest layout
1 parent ed1b8c2 commit 4bd5495

File tree

116 files changed

+10216
-2718
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+10216
-2718
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.15.1)
1010

1111
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
1212

13-
project(SwiftDriver LANGUAGES Swift)
13+
project(SwiftDriver LANGUAGES C Swift)
1414

1515
set(SWIFT_VERSION 5)
1616
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})
@@ -19,6 +19,9 @@ if(CMAKE_VERSION VERSION_LESS 3.16)
1919
set(CMAKE_LINK_LIBRARY_FLAG "-l")
2020
endif()
2121

22+
# ensure Swift compiler can find _CSwiftDriver
23+
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-I$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}/Sources/_CSwiftDriver/include>)
24+
2225
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
2326

2427
if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows)

Package.resolved

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

Package.swift

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,34 @@ let package = Package(
2424
.library(
2525
name: "SwiftDriver",
2626
targets: ["SwiftDriver"]),
27+
.library(
28+
name: "SwiftDriverDynamic",
29+
type: .dynamic,
30+
targets: ["SwiftDriver"]),
2731
.library(
2832
name: "SwiftOptions",
2933
targets: ["SwiftOptions"]),
34+
.library(
35+
name: "SwiftDriverExecution",
36+
targets: ["SwiftDriverExecution"]),
3037
],
3138
targets: [
39+
.target(name: "_CSwiftDriver"),
40+
3241
/// The driver library.
3342
.target(
3443
name: "SwiftDriver",
35-
dependencies: ["SwiftOptions", "SwiftToolsSupport-auto", "Yams"]),
44+
dependencies: ["SwiftOptions", "SwiftToolsSupport-auto", "Yams", "_CSwiftDriver"]),
45+
46+
/// The execution library.
47+
.target(
48+
name: "SwiftDriverExecution",
49+
dependencies: ["SwiftDriver", "SwiftToolsSupport-auto"]),
50+
51+
/// Driver tests.
3652
.testTarget(
3753
name: "SwiftDriverTests",
38-
dependencies: ["SwiftDriver", "swift-driver"]),
54+
dependencies: ["SwiftDriver", "SwiftDriverExecution", "swift-driver"]),
3955

4056
/// The options library.
4157
.target(
@@ -48,7 +64,7 @@ let package = Package(
4864
/// The primary driver executable.
4965
.target(
5066
name: "swift-driver",
51-
dependencies: ["SwiftDriver"]),
67+
dependencies: ["SwiftDriverExecution", "SwiftDriver"]),
5268

5369
/// The help executable.
5470
.target(
@@ -66,7 +82,7 @@ let package = Package(
6682
if ProcessInfo.processInfo.environment["SWIFT_DRIVER_LLBUILD_FWK"] == nil {
6783
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
6884
package.dependencies += [
69-
.package(url: "https://github.com/apple/swift-llbuild.git", .branch("master")),
85+
.package(url: "https://github.com/apple/swift-llbuild.git", .branch("main")),
7086
]
7187
} else {
7288
// In Swift CI, use a local path to llbuild to interoperate with tools
@@ -75,21 +91,21 @@ if ProcessInfo.processInfo.environment["SWIFT_DRIVER_LLBUILD_FWK"] == nil {
7591
.package(path: "../llbuild"),
7692
]
7793
}
78-
package.targets.first(where: { $0.name == "SwiftDriver" })!.dependencies += ["llbuildSwift"]
94+
package.targets.first(where: { $0.name == "SwiftDriverExecution" })!.dependencies += ["llbuildSwift"]
7995
}
8096

8197
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
8298
package.dependencies += [
83-
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("master")),
99+
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("main")),
84100
.package(url: "https://github.com/jpsim/Yams.git", .upToNextMinor(from: "4.0.0")),
85101
// The 'swift-argument-parser' version declared here must match that
86102
// used by 'swift-package-manager' and 'sourcekit-lsp'. Please coordinate
87103
// dependency version changes here with those projects.
88-
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.1")),
104+
.package(url: "https://github.com/apple/swift-argument-parser.git", .branch("main")),
89105
]
90106
} else {
91107
package.dependencies += [
92-
.package(path: "../swiftpm/swift-tools-support-core"),
108+
.package(path: "../swift-tools-support-core"),
93109
.package(path: "../yams"),
94110
.package(path: "../swift-argument-parser"),
95111
]

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Swift's compiler driver is a program that coordinates the compilation of Swift source code into various compiled results: executables, libraries, object files, Swift modules and interfaces, etc. It is the program one invokes from the command line to build Swift code (i.e., `swift` or `swiftc`) and is often invoked on the developer's behalf by a build system such as the [Swift Package Manager (SwiftPM)](https://github.com/apple/swift-package-manager) or Xcode's build system.
44

5-
The `swift-driver` project is a new implementation of the Swift compiler driver that is intended to replace the [existing driver](https://github.com/apple/swift/tree/master/lib/Driver) with a more extensible, maintainable, and robust code base. The specific goals of this project include:
5+
The `swift-driver` project is a new implementation of the Swift compiler driver that is intended to replace the [existing driver](https://github.com/apple/swift/tree/main/lib/Driver) with a more extensible, maintainable, and robust code base. The specific goals of this project include:
66

77
* A maintainable, robust, and flexible Swift code base
88
* Library-based architecture that allows better integration with build tools
@@ -42,9 +42,9 @@ available. Doing so requires several dependencies to be built first,
4242
all with CMake:
4343

4444
* (Non-Apple platforms only) [swift-corelibs-foundation](https://github.com/apple/swift-corelibs-foundation)
45-
* [llbuild](https://github.com/apple/swift-llbuild) configure CMake with `-DLLBUILD_SUPPORT_BINDINGS="Swift"` when building
45+
* [llbuild](https://github.com/apple/swift-llbuild) configure CMake with `-DLLBUILD_SUPPORT_BINDINGS="Swift"` and `-DCMAKE_OSX_ARCHITECTURES=x86_64` (If building on Intel) when building
4646
```
47-
cmake -B <llbuild-build-dir> -G Ninja <llbuild-source-dir> -DLLBUILD_SUPPORT_BINDINGS="Swift"
47+
cmake -B <llbuild-build-dir> -G Ninja <llbuild-source-dir> -DLLBUILD_SUPPORT_BINDINGS="Swift" -DCMAKE_OSX_ARCHITECTURES=x86_64
4848
```
4949
* [swift-argument-parser](https://github.com/apple/swift-argument-parser)
5050
* [Yams](https://github.com/jpsim/Yams)
@@ -61,7 +61,7 @@ The new Swift driver is a work in progress, and there are numerous places for an
6161

6262
### Driver Documentation
6363

64-
For a conceptual overview of the driver, see [The Swift Driver, Compilation Model, and Command-Line Experience](https://github.com/apple/swift/blob/master/docs/Driver.md). To learn more about the internals, see [Driver Design & Internals](https://github.com/apple/swift/blob/master/docs/DriverInternals.md) and [Parseable Driver Output](https://github.com/apple/swift/blob/master/docs/DriverParseableOutput.md).
64+
For a conceptual overview of the driver, see [The Swift Driver, Compilation Model, and Command-Line Experience](https://github.com/apple/swift/blob/main/docs/Driver.md). To learn more about the internals, see [Driver Design & Internals](https://github.com/apple/swift/blob/main/docs/DriverInternals.md) and [Parseable Driver Output](https://github.com/apple/swift/blob/main/docs/DriverParseableOutput.md).
6565

6666
### Testing
6767

@@ -100,7 +100,14 @@ Using:
100100
apple/swift-driver#208
101101
@swift-ci smoke test
102102
```
103-
@swift-ci cross-repository testing facilities are described [here](https://github.com/apple/swift/blob/master/docs/ContinuousIntegration.md#cross-repository-testing).
103+
@swift-ci cross-repository testing facilities are described [here](https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#cross-repository-testing).
104+
105+
### Testing in Xcode with custom toolchain
106+
After the toolchain is installed, Xcode needs to be told to use it. This can mean two things, building the driver with the toolchain and telling the driver to use the toolchain when running.
107+
108+
Building with the toolchain is easy, set the toolchain in Xcode: Menu Bar > Xcode > Toolchains > select your toolchain
109+
110+
Running the driver requires setting the TOOLCHAINS environment variable. This tells xcrun which toolchain to use (on darwin xcrun is used to find tools). This variable is the name of the toolchain and not the path (ex: `Swift Development Snapshot`). Important note: xcrun lookup is lower priority than the SWIFT_EXEC_*_EXEC family of environment variables, the tools directory, and any tools in the same directory as the driver (This includes a driver installed in a toolchain). Even though TOOLCHAINS is not highest priority it's a convenient way to run the xctest suite using a custom toolchain.
104111

105112
#### Preparing a Linux docker for debug
106113

@@ -126,7 +133,7 @@ $ apt-get install libncurses-dev
126133

127134
### Rebuilding `Options.swift`
128135

129-
`Options.swift`, which contains the complete set of options that can be parsed by the driver, is automatically generated from the [option tables in the Swift compiler](https://github.com/apple/swift/tree/master/include/swift/Option). If you need to regenerate `Options.swift`, you will need to [build the Swift compiler](https://github.com/apple/swift#building-swift) and then build `makeOptions` program with a `-I` that allows the generated `Options.inc` to
136+
`Options.swift`, which contains the complete set of options that can be parsed by the driver, is automatically generated from the [option tables in the Swift compiler](https://github.com/apple/swift/tree/main/include/swift/Option). If you need to regenerate `Options.swift`, you will need to [build the Swift compiler](https://github.com/apple/swift#building-swift) and then build `makeOptions` program with a `-I` that allows the generated `Options.inc` to
130137
be found, e.g.:
131138

132139
```
@@ -152,7 +159,7 @@ The goal of the new Swift driver is to provide a drop-in replacement for the exi
152159
* [ ] Find a better way to describe aliases for options. Can they be of some other type `OptionAlias` so we can't make the mistake of (e.g.) asking for an alias option when we're translating options?
153160
* [ ] Diagnose unused options on the command line
154161
* [ ] Typo correction for misspelled option names
155-
* [ ] Find a better way than `makeOptions.cpp` to translate the command-line options from [Swift's repository](https://github.com/apple/swift/tree/master/include/swift/Option) into `Options.swift`.
162+
* [ ] Find a better way than `makeOptions.cpp` to translate the command-line options from [Swift's repository](https://github.com/apple/swift/tree/main/include/swift/Option) into `Options.swift`.
156163
* Platform support
157164
* [x] Teach the `DarwinToolchain` to also handle iOS, tvOS, watchOS
158165
* [x] Fill out the `GenericUnixToolchain` toolchain to get it working
@@ -173,10 +180,10 @@ The goal of the new Swift driver is to provide a drop-in replacement for the exi
173180
* [x] Complete `OutputFileMap` implementation to handle all file types uniformly
174181
* Testing
175182
* [ ] Build stuff with SwiftPM or Xcode or your favorite build system, using `swift-driver`. Were the results identical? What changed?
176-
* [x] Shim in `swift-driver` so it can run the Swift repository's [driver test suite](https://github.com/apple/swift/tree/master/test/Driver).
183+
* [x] Shim in `swift-driver` so it can run the Swift repository's [driver test suite](https://github.com/apple/swift/tree/main/test/Driver).
177184
* [ ] Investigate differences in the test results for the Swift repository's driver test suite (above) between the existing and new driver.
178-
* [ ] Port interesting tests from the Swift repository's [driver test suite](https://github.com/apple/swift/tree/master/test/Driver) over to XCTest
185+
* [ ] Port interesting tests from the Swift repository's [driver test suite](https://github.com/apple/swift/tree/main/test/Driver) over to XCTest
179186
* [ ] Fuzz the command-line options to try to crash the Swift driver itself
180187
* Integration
181-
* [ ] Teach the Swift compiler's [`build-script`](https://github.com/apple/swift/blob/master/utils/build-script) to build `swift-driver`.
182-
* [ ] Building on the above, teach the Swift compiler's [`build-toolchain`](https://github.com/apple/swift/blob/master/utils/build-toolchain) to install `swift-driver` as the primary driver so we can test full toolchains with the new driver
188+
* [ ] Teach the Swift compiler's [`build-script`](https://github.com/apple/swift/blob/main/utils/build-script) to build `swift-driver`.
189+
* [ ] Building on the above, teach the Swift compiler's [`build-toolchain`](https://github.com/apple/swift/blob/main/utils/build-toolchain) to install `swift-driver` as the primary driver so we can test full toolchains with the new driver

Sources/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9+
add_subdirectory(_CSwiftDriver)
910
add_subdirectory(SwiftOptions)
1011
add_subdirectory(SwiftDriver)
12+
add_subdirectory(SwiftDriverExecution)
1113
add_subdirectory(swift-driver)
1214
add_subdirectory(swift-help)

Sources/SwiftDriver/CMakeLists.txt

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
add_library(SwiftDriver
1010
"Explicit Module Builds/ClangModuleBuildJobCache.swift"
11-
"Explicit Module Builds/ExplicitModuleBuildHandler.swift"
12-
"Explicit Module Builds/PlaceholderDependencyResolution.swift"
1311
"Explicit Module Builds/ClangVersionedDependencyResolution.swift"
14-
"Explicit Module Builds/InterModuleDependencyGraph.swift"
12+
"Explicit Module Builds/ExplicitDependencyBuildPlanner.swift"
1513
"Explicit Module Builds/ModuleDependencyScanning.swift"
14+
"Explicit Module Builds/PlaceholderDependencyResolution.swift"
1615
"Explicit Module Builds/SerializableModuleArtifacts.swift"
16+
"Explicit Module Builds/Inter Module Dependencies/CommonDependencyOperations.swift"
17+
"Explicit Module Builds/Inter Module Dependencies/InterModuleDependencyGraph.swift"
18+
"Explicit Module Builds/Inter Module Dependencies/InterModuleDependencyOracle.swift"
1719

1820
Driver/CompilerMode.swift
1921
Driver/DebugInfo.swift
@@ -22,18 +24,29 @@ add_library(SwiftDriver
2224
Driver/ModuleOutputInfo.swift
2325
Driver/OutputFileMap.swift
2426
Driver/ToolExecutionDelegate.swift
27+
Driver/DriverVersion.swift
2528

2629
Execution/ArgsResolver.swift
27-
Execution/MultiJobExecutor.swift
2830
Execution/DriverExecutor.swift
2931
Execution/ParsableOutput.swift
3032
Execution/ProcessProtocol.swift
31-
Execution/llbuild.swift
3233

34+
"Incremental Compilation/ModuleDependencyGraph Parts/Integrator.swift"
35+
"Incremental Compilation/ModuleDependencyGraph Parts/Node.swift"
36+
"Incremental Compilation/ModuleDependencyGraph Parts/NodeFinder.swift"
37+
"Incremental Compilation/ModuleDependencyGraph Parts/SwiftDeps.swift"
38+
"Incremental Compilation/ModuleDependencyGraph Parts/Tracer.swift"
39+
"Incremental Compilation/BidirectionalMap.swift"
40+
"Incremental Compilation/BuildRecord.swift"
41+
"Incremental Compilation/BuildRecordInfo.swift"
42+
"Incremental Compilation/DependencyKey.swift"
43+
"Incremental Compilation/DictionaryOfDictionaries.swift"
3344
"Incremental Compilation/IncrementalCompilationState.swift"
34-
"Incremental Compilation/InputIInfoMap.swift"
3545
"Incremental Compilation/InputInfo.swift"
46+
"Incremental Compilation/ModuleDependencyGraph.swift"
47+
"Incremental Compilation/Multidictionary.swift"
3648
"Incremental Compilation/SourceFileDependencyGraph.swift"
49+
"Incremental Compilation/TwoDMap.swift"
3750

3851
Jobs/AutolinkExtractJob.swift
3952
Jobs/BackendJob.swift
@@ -59,14 +72,14 @@ add_library(SwiftDriver
5972
Jobs/VerifyDebugInfoJob.swift
6073
Jobs/VerifyModuleInterfaceJob.swift
6174
Jobs/WindowsToolchain+LinkerSupport.swift
75+
Jobs/WebAssemblyToolchain+LinkerSupport.swift
6276

6377
Toolchains/DarwinToolchain.swift
6478
Toolchains/GenericUnixToolchain.swift
6579
Toolchains/Toolchain.swift
6680
Toolchains/WindowsToolchain.swift
81+
Toolchains/WebAssemblyToolchain.swift
6782

68-
Utilities/Bits.swift
69-
Utilities/Bitstream.swift
7083
Utilities/DOTJobGraphSerializer.swift
7184
Utilities/DateAdditions.swift
7285
Utilities/Diagnostics.swift
@@ -86,11 +99,11 @@ add_library(SwiftDriver
8699
target_link_libraries(SwiftDriver PUBLIC
87100
TSCBasic
88101
TSCUtility
89-
SwiftOptions
90-
llbuildSwift)
102+
SwiftOptions)
91103
target_link_libraries(SwiftDriver PRIVATE
92104
CYaml
93-
Yams)
105+
Yams
106+
CSwiftDriver)
94107

95108
set_property(GLOBAL APPEND PROPERTY SWIFTDRIVER_EXPORTS SwiftDriver)
96109

Sources/SwiftDriver/Driver/CompilerMode.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
/// The mode of the compiler.
13-
public enum CompilerMode: Equatable {
13+
@_spi(Testing) public enum CompilerMode: Equatable {
1414
/// A standard compilation, using multiple frontend invocations and -primary-file.
1515
case standardCompile
1616

@@ -33,7 +33,7 @@ public enum CompilerMode: Equatable {
3333

3434
/// Information about batch mode, which is used to determine how to form
3535
/// the batches of jobs.
36-
public struct BatchModeInfo: Equatable {
36+
@_spi(Testing) public struct BatchModeInfo: Equatable {
3737
let seed: Int?
3838
let count: Int?
3939
let sizeLimit: Int?
@@ -62,6 +62,28 @@ extension CompilerMode {
6262
}
6363
}
6464

65+
public var isStandardCompilationForPlanning: Bool {
66+
switch self {
67+
case .immediate, .repl, .compilePCM:
68+
return false
69+
case .batchCompile, .standardCompile, .singleCompile:
70+
return true
71+
}
72+
}
73+
74+
public var batchModeInfo: BatchModeInfo? {
75+
switch self {
76+
case let .batchCompile(info):
77+
return info
78+
default:
79+
return nil
80+
}
81+
}
82+
83+
public var isBatchCompile: Bool {
84+
batchModeInfo != nil
85+
}
86+
6587
// Whether this compilation mode supports the use of bridging pre-compiled
6688
// headers.
6789
public var supportsBridgingPCH: Bool {

Sources/SwiftDriver/Driver/DebugInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// The debug information produced by the driver.
14-
public struct DebugInfo {
14+
@_spi(Testing) public struct DebugInfo {
1515

1616
/// Describes the format used for debug information.
1717
public enum Format: String {

0 commit comments

Comments
 (0)