Skip to content

Commit 295025b

Browse files
Support ExplicitModule build for verifyModuleInterface Jobs
1 parent 28c6b1c commit 295025b

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 5 additions & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,23 @@ extension Driver {
394394
displayInputs = primaryInputs
395395
}
396396

397+
if enableCaching {
398+
func computeKeyForInterface(forPrivate: Bool) throws -> String? {
399+
let isNeeded =
400+
forPrivate
401+
? parsedOptions.hasArgument(.emitPrivateModuleInterfacePath)
402+
: parsedOptions.hasArgument(.emitModuleInterface, .emitModuleInterfacePath)
403+
guard isNeeded else { return nil }
404+
let outputType: FileType =
405+
forPrivate ? .privateSwiftInterface : .swiftInterface
406+
// Assume swiftinterface file is always the supplementary output for first input file.
407+
let inputPath = displayInputs[0].fileHandle
408+
return try interModuleDependencyOracle.computeCacheKeyForOutput(kind: outputType, commandLine: commandLine, input: inputPath)
409+
}
410+
swiftInterfaceCacheKey = try computeKeyForInterface(forPrivate: false)
411+
privateSwiftInterfaceCacheKey = try computeKeyForInterface(forPrivate: true)
412+
}
413+
397414
return Job(
398415
moduleName: moduleOutputInfo.name,
399416
kind: .compile,

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 2 additions & 1 deletion
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
@@ -343,6 +343,7 @@ extension Driver {
343343
commandLine.appendFlag(.casPath)
344344
commandLine.appendFlag(casPath)
345345
}
346+
try commandLine.appendLast(.cacheRemarks, from: &parsedOptions)
346347
try commandLine.appendLast(.casPluginPath, from: &parsedOptions)
347348
try commandLine.appendAll(.casPluginOption, from: &parsedOptions)
348349
}

Sources/SwiftDriver/Jobs/VerifyModuleInterfaceJob.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import struct TSCBasic.RelativePath
14+
1315
extension Driver {
1416
mutating func verifyModuleInterfaceJob(interfaceInput: TypedVirtualPath, optIn: Bool) throws -> Job {
1517
var commandLine: [Job.ArgTemplate] = swiftCompilerPrefixArgs.map { Job.ArgTemplate.flag($0) }
@@ -26,6 +28,21 @@ extension Driver {
2628
outputs.append(TypedVirtualPath(file: outputPath, type: .diagnostics))
2729
}
2830

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

Sources/SwiftDriver/SwiftScan/SwiftScan.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ internal extension swiftscan_diagnostic_severity_t {
403403
return SWIFTSCAN_OUTPUT_TYPE_SWIFTMODULE
404404
case .swiftInterface:
405405
return SWIFTSCAN_OUTPUT_TYPE_SWIFTINTERFACE
406+
case .privateSwiftInterface:
407+
return SWIFTSCAN_OUTPUT_TYPE_SWIFTPRIAVEINTERFACE
406408
case .pcm:
407409
return SWIFTSCAN_OUTPUT_TYPE_CLANG_MODULE
408410
case .pch:

0 commit comments

Comments
 (0)