Skip to content

Commit 89a2c61

Browse files
committed
[Explicit Module Builds] Support Versioned PCMs
There exists a strict limitation that a compatible PCM must have the exact same target version with the loading module (either a Swift module or another PCM). This means that each PCM may have to be built multiple times, once for each unique (SDK, architecture, toolchain) tuple of some loading module. This PR introduces support for generating versioned PCMs for each loading module. Because now there is more state that we needed to keep track of when generating jobs for module dependencies, this state, along with the Inter-Module Dependency Graph, now live in the `ExplicitModuleBuildHandler`, which is constructed on-demand by the driver in the explicit module build mode. The handler is responsible for generating dependency build jobs and for vending out dependency modules as inputs/command-line options whenever the driver creates a compile job in Explicit Module Build Mode. Because this PR rewrites/refactores the majority of existing Explicit Module Build code, I tooke the opportunity to re-organize some of the files as well. Resolves rdar://problem/63944640
1 parent 8718e2c commit 89a2c61

11 files changed

+507
-249
lines changed

Sources/SwiftDriver/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
add_library(SwiftDriver
10-
"Dependency Scanning/ModuleDependencyBuildGeneration.swift"
11-
"Dependency Scanning/InterModuleDependencyGraph.swift"
10+
"Explicit Module Builds/ClandModuleBuildJobCache.swift"
11+
"Explicit Module Builds/ExplicitModuleBuildHandler.swift"
12+
"Explicit Module Builds/InterModuleDependencyGraph.swift"
13+
"Explicit Module Builds/ModuleDependencyScanning.swift"
1214

1315
Driver/CompilerMode.swift
1416
Driver/DebugInfo.swift
@@ -17,7 +19,6 @@ add_library(SwiftDriver
1719
Driver/ModuleOutputInfo.swift
1820
Driver/OutputFileMap.swift
1921
Driver/ToolExecutionDelegate.swift
20-
Driver/ModuleDependencyScanning.swift
2122

2223
Execution/JobExecutor.swift
2324
Execution/ParsableOutput.swift

Sources/SwiftDriver/Dependency Scanning/ModuleDependencyBuildGeneration.swift

Lines changed: 0 additions & 160 deletions
This file was deleted.

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public struct Driver {
2626
case conflictingOptions(Option, Option)
2727
// Explicit Module Build Failures
2828
case malformedModuleDependency(String, String)
29+
case missingPCMArguments(String)
2930
case missingModuleDependency(String)
3031
case dependencyScanningFailure(Int, String)
3132

@@ -49,6 +50,8 @@ public struct Driver {
4950
// Explicit Module Build Failures
5051
case .malformedModuleDependency(let moduleName, let errorDescription):
5152
return "Malformed Module Dependency: \(moduleName), \(errorDescription)"
53+
case .missingPCMArguments(let moduleName):
54+
return "Missing extraPcmArgs to build Clang module: \(moduleName)"
5255
case .missingModuleDependency(let moduleName):
5356
return "Missing Module Dependency Info: \(moduleName)"
5457
case .dependencyScanningFailure(let code, let error):
@@ -169,10 +172,10 @@ public struct Driver {
169172
/// This will force the driver to first emit the module and then run compile jobs.
170173
public var forceEmitModuleInSingleInvocation: Bool = false
171174

172-
/// The module dependency graph, which is populated during the planning phase
173-
/// only when all modules will be prebuilt and treated as explicit by the
174-
/// various compilation jobs.
175-
public var interModuleDependencyGraph: InterModuleDependencyGraph? = nil
175+
/// Handler for constructing module build jobs using Explicit Module Builds.
176+
/// Constructed during the planning phase only when all modules will be prebuilt and treated
177+
/// as explicit by the various compilation jobs.
178+
public var explicitModuleBuildHandler: ExplicitModuleBuildHandler? = nil
176179

177180
/// Handler for emitting diagnostics to stderr.
178181
public static let stderrDiagnosticsHandler: DiagnosticsEngine.DiagnosticsHandler = { diagnostic in
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===----------------- ClangModuleBuildJobCache.swift ---------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/// Maps tuples (ModuleDependencyId, [String]), where [String] is an array of pcm build opitions,
14+
/// to the job used to build this module with these specified build options.
15+
struct ClangModuleBuildJobCache {
16+
17+
/// As tuples cannot be Hashable, wrap (ModuleDependencyId, [String]) into a struct pair
18+
private struct ModuleArgumentPair : Hashable {
19+
let moduleId: ModuleDependencyId
20+
let buildArgs: [String]
21+
}
22+
23+
private var cache: [ModuleArgumentPair: Job] = [:]
24+
25+
var allJobs: [Job] {
26+
return Array(cache.values)
27+
}
28+
29+
subscript(index: (ModuleDependencyId, [String])) -> Job? {
30+
get {
31+
return cache[ModuleArgumentPair(moduleId: index.0, buildArgs: index.1)]
32+
}
33+
set(newValue) {
34+
cache[ModuleArgumentPair(moduleId: index.0, buildArgs: index.1)] = newValue
35+
}
36+
}
37+
}
38+

0 commit comments

Comments
 (0)