Skip to content

Commit a3abea5

Browse files
Support ExplicitModule build for verifyModuleInterface Jobs
1 parent 544f829 commit a3abea5

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

Sources/SwiftDriver/Driver/Driver.swift

+5
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ public struct Driver {
207207
/// CacheKey for bridging header
208208
var bridgingHeaderCacheKey: String? = nil
209209

210+
/// CacheKey for swift interface
211+
var swiftInterfaceCacheKey: String? = nil
212+
/// CacheKey for private swift interface
213+
var privateSwiftInterfaceCacheKey: String? = nil
214+
210215
/// The set of input files
211216
@_spi(Testing) public let inputFiles: [TypedVirtualPath]
212217

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,12 @@ public class InterModuleDependencyOracle {
178178
return try swiftScan.store(data:data)
179179
}
180180

181-
public func computeCacheKeyForOutput(kind: FileType, commandLine: [Job.ArgTemplate], input: VirtualPath.Handle) throws -> String {
181+
public func computeCacheKeyForOutput(kind: FileType, commandLine: [Job.ArgTemplate], input: VirtualPath.Handle?) throws -> String {
182182
guard let swiftScan = swiftScanLibInstance else {
183183
fatalError("Attempting to reset scanner cache with no scanner instance.")
184184
}
185-
return try swiftScan.computeCacheKeyForOutput(kind: kind, commandLine: commandLine.stringArray, input: input.description)
185+
let inputPath = input?.description ?? ""
186+
return try swiftScan.computeCacheKeyForOutput(kind: kind, commandLine: commandLine.stringArray, input: inputPath)
186187
}
187188

188189
private var hasScannerInstance: Bool { self.swiftScanLibInstance != nil }

Sources/SwiftDriver/Jobs/CompileJob.swift

+3
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ extension Driver {
394394
displayInputs = primaryInputs
395395
}
396396

397+
// Assume swiftinterface file is always the supplementary output for first input file.
398+
try computeCacheKeyForInterface(mainInput: displayInputs[0], outputs: outputs, commandLine: commandLine)
399+
397400
return Job(
398401
moduleName: moduleOutputInfo.name,
399402
kind: .compile,

Sources/SwiftDriver/Jobs/EmitModuleJob.swift

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ extension Driver {
118118
commandLine.appendPath(abiPath.file)
119119
outputs.append(abiPath)
120120
}
121+
// Assume swiftinterface file is always the supplementary output for first input file.
122+
try computeCacheKeyForInterface(mainInput: inputs[0], outputs: outputs, commandLine: commandLine)
121123
return Job(
122124
moduleName: moduleOutputInfo.name,
123125
kind: .emitModule,

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

+18-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extension Driver {
8383
switch kind {
8484
case .generatePCH:
8585
try addExplicitPCHBuildArguments(inputs: &inputs, commandLine: &commandLine)
86-
case .compile, .emitModule, .interpret:
86+
case .compile, .emitModule, .interpret, .verifyModuleInterface:
8787
try addExplicitModuleBuildArguments(inputs: &inputs, commandLine: &commandLine)
8888
default:
8989
break
@@ -671,6 +671,23 @@ extension Driver {
671671
try dependencyPlanner.resolveBridgingHeaderDependencies(inputs: &inputs, commandLine: &commandLine)
672672
}
673673

674+
/// Compute the cache key for swift interface outputs.
675+
mutating func computeCacheKeyForInterface(mainInput: TypedVirtualPath,
676+
outputs: [TypedVirtualPath],
677+
commandLine: [Job.ArgTemplate]) throws {
678+
if enableCaching {
679+
func computeKeyForInterface(forPrivate: Bool) throws -> String? {
680+
let outputType: FileType =
681+
forPrivate ? .privateSwiftInterface : .swiftInterface
682+
let isNeeded = outputs.contains { $0.type == outputType }
683+
guard isNeeded else { return nil }
684+
return try interModuleDependencyOracle.computeCacheKeyForOutput(kind: outputType, commandLine: commandLine, input: mainInput.fileHandle)
685+
}
686+
swiftInterfaceCacheKey = try computeKeyForInterface(forPrivate: false)
687+
privateSwiftInterfaceCacheKey = try computeKeyForInterface(forPrivate: true)
688+
}
689+
}
690+
674691
/// In Explicit Module Build mode, distinguish between main module jobs and intermediate dependency build jobs,
675692
/// such as Swift modules built from .swiftmodule files and Clang PCMs.
676693
public func isExplicitMainModuleJob(job: Job) -> Bool {

Sources/SwiftDriver/Jobs/VerifyModuleInterfaceJob.swift

+15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ extension Driver {
2626
outputs.append(TypedVirtualPath(file: outputPath, type: .diagnostics))
2727
}
2828

29+
if parsedOptions.contains(.driverExplicitModuleBuild) {
30+
commandLine.appendFlag("-explicit-interface-module-build")
31+
if let key = swiftInterfaceCacheKey, interfaceInput.type == .swiftInterface {
32+
commandLine.appendFlag("-input-file-key")
33+
commandLine.appendFlag(key)
34+
}
35+
if let key = privateSwiftInterfaceCacheKey, interfaceInput.type == .privateSwiftInterface {
36+
commandLine.appendFlag("-input-file-key")
37+
commandLine.appendFlag(key)
38+
}
39+
// Need to create an output file for swiftmodule output. Currently put it next to the swift interface.
40+
let moduleOutPath = try interfaceInput.file.appendingToBaseName(".verified.swiftmodule")
41+
commandLine.appendFlags("-o", moduleOutPath.name)
42+
}
43+
2944
// TODO: remove this because we'd like module interface errors to fail the build.
3045
if !optIn && isFrontendArgSupported(.downgradeTypecheckInterfaceError) {
3146
commandLine.appendFlag(.downgradeTypecheckInterfaceError)

0 commit comments

Comments
 (0)