@@ -337,6 +337,7 @@ public struct SwiftDriverPayload: Serializable, TaskPayload, Encodable {
337
337
public let uniqueID : String
338
338
public let compilerLocation : LibSwiftDriver . CompilerLocation
339
339
public let moduleName : String
340
+ public let outputPrefix : String
340
341
public let tempDirPath : Path
341
342
public let explicitModulesTempDirPath : Path
342
343
public let variant : String
@@ -352,10 +353,11 @@ public struct SwiftDriverPayload: Serializable, TaskPayload, Encodable {
352
353
public let dependencyFilteringRootPath : Path ?
353
354
public let verifyScannerDependencies : Bool
354
355
355
- internal init ( uniqueID: String , compilerLocation: LibSwiftDriver . CompilerLocation , moduleName: String , tempDirPath: Path , explicitModulesTempDirPath: Path , variant: String , architecture: String , eagerCompilationEnabled: Bool , explicitModulesEnabled: Bool , commandLine: [ String ] , ruleInfo: [ String ] , isUsingWholeModuleOptimization: Bool , casOptions: CASOptions ? , reportRequiredTargetDependencies: BooleanWarningLevel , linkerResponseFilePath: Path ? , dependencyFilteringRootPath: Path ? , verifyScannerDependencies: Bool ) {
356
+ internal init ( uniqueID: String , compilerLocation: LibSwiftDriver . CompilerLocation , moduleName: String , outputPrefix : String , tempDirPath: Path , explicitModulesTempDirPath: Path , variant: String , architecture: String , eagerCompilationEnabled: Bool , explicitModulesEnabled: Bool , commandLine: [ String ] , ruleInfo: [ String ] , isUsingWholeModuleOptimization: Bool , casOptions: CASOptions ? , reportRequiredTargetDependencies: BooleanWarningLevel , linkerResponseFilePath: Path ? , dependencyFilteringRootPath: Path ? , verifyScannerDependencies: Bool ) {
356
357
self . uniqueID = uniqueID
357
358
self . compilerLocation = compilerLocation
358
359
self . moduleName = moduleName
360
+ self . outputPrefix = outputPrefix
359
361
self . tempDirPath = tempDirPath
360
362
self . explicitModulesTempDirPath = explicitModulesTempDirPath
361
363
self . variant = variant
@@ -373,10 +375,11 @@ public struct SwiftDriverPayload: Serializable, TaskPayload, Encodable {
373
375
}
374
376
375
377
public init ( from deserializer: any Deserializer ) throws {
376
- try deserializer. beginAggregate ( 17 )
378
+ try deserializer. beginAggregate ( 18 )
377
379
self . uniqueID = try deserializer. deserialize ( )
378
380
self . compilerLocation = try deserializer. deserialize ( )
379
381
self . moduleName = try deserializer. deserialize ( )
382
+ self . outputPrefix = try deserializer. deserialize ( )
380
383
self . tempDirPath = try deserializer. deserialize ( )
381
384
self . explicitModulesTempDirPath = try deserializer. deserialize ( )
382
385
self . variant = try deserializer. deserialize ( )
@@ -394,10 +397,11 @@ public struct SwiftDriverPayload: Serializable, TaskPayload, Encodable {
394
397
}
395
398
396
399
public func serialize< T> ( to serializer: T ) where T : Serializer {
397
- serializer. serializeAggregate ( 17 ) {
400
+ serializer. serializeAggregate ( 18 ) {
398
401
serializer. serialize ( self . uniqueID)
399
402
serializer. serialize ( self . compilerLocation)
400
403
serializer. serialize ( self . moduleName)
404
+ serializer. serialize ( self . outputPrefix)
401
405
serializer. serialize ( self . tempDirPath)
402
406
serializer. serialize ( self . explicitModulesTempDirPath)
403
407
serializer. serialize ( self . variant)
@@ -2502,7 +2506,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
2502
2506
let explicitModuleBuildEnabled = await swiftExplicitModuleBuildEnabled ( cbc. producer, cbc. scope, delegate)
2503
2507
let verifyScannerDependencies = explicitModuleBuildEnabled && cbc. scope. evaluate ( BuiltinMacros . SWIFT_DEPENDENCY_REGISTRATION_MODE) == . verifySwiftDependencyScanner
2504
2508
2505
- return SwiftDriverPayload ( uniqueID: uniqueID, compilerLocation: compilerLocation, moduleName: scope. evaluate ( BuiltinMacros . SWIFT_MODULE_NAME) , tempDirPath: tempDirPath, explicitModulesTempDirPath: explicitModulesTempDirPath, variant: variant, architecture: arch, eagerCompilationEnabled: eagerCompilationEnabled ( args: args, scope: scope, compilationMode: compilationMode, isUsingWholeModuleOptimization: isUsingWholeModuleOptimization) , explicitModulesEnabled: explicitModuleBuildEnabled, commandLine: commandLine, ruleInfo: ruleInfo, isUsingWholeModuleOptimization: isUsingWholeModuleOptimization, casOptions: casOptions, reportRequiredTargetDependencies: scope. evaluate ( BuiltinMacros . DIAGNOSE_MISSING_TARGET_DEPENDENCIES) , linkerResponseFilePath: linkerResponseFilePath, dependencyFilteringRootPath: cbc. producer. sdk? . path, verifyScannerDependencies: verifyScannerDependencies)
2509
+ return SwiftDriverPayload ( uniqueID: uniqueID, compilerLocation: compilerLocation, moduleName: scope. evaluate ( BuiltinMacros . SWIFT_MODULE_NAME) , outputPrefix : scope . evaluate ( BuiltinMacros . TARGET_NAME ) + compilationMode . moduleBaseNameSuffix , tempDirPath: tempDirPath, explicitModulesTempDirPath: explicitModulesTempDirPath, variant: variant, architecture: arch, eagerCompilationEnabled: eagerCompilationEnabled ( args: args, scope: scope, compilationMode: compilationMode, isUsingWholeModuleOptimization: isUsingWholeModuleOptimization) , explicitModulesEnabled: explicitModuleBuildEnabled, commandLine: commandLine, ruleInfo: ruleInfo, isUsingWholeModuleOptimization: isUsingWholeModuleOptimization, casOptions: casOptions, reportRequiredTargetDependencies: scope. evaluate ( BuiltinMacros . DIAGNOSE_MISSING_TARGET_DEPENDENCIES) , linkerResponseFilePath: linkerResponseFilePath, dependencyFilteringRootPath: cbc. producer. sdk? . path, verifyScannerDependencies: verifyScannerDependencies)
2506
2510
}
2507
2511
2508
2512
func constructSwiftResponseFileTask( path: Path ) {
@@ -3397,10 +3401,12 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
3397
3401
removeWithParameter ( arg)
3398
3402
}
3399
3403
3400
- // We need to ignore precompiled headers due to:
3404
+ // For some old version of swift driver, the output path for bridging header pch is not stable,
3405
+ // we need to disable bridging header pch when caching or bridging header chaining is not enabled as a workaround:
3401
3406
// rdar://126212044 ([JIT] iOS test Failures: Thunk build failure, unable to read PCH file)
3402
- removeWithPrefix ( " -cache-compile-job " )
3403
- commandLine. append ( " -disable-bridging-pch " )
3407
+ if !commandLine. contains ( " -cache-compile-job " ) || !commandLine. contains ( " -auto-bridging-header-chaining " ) {
3408
+ commandLine. append ( " -disable-bridging-pch " )
3409
+ }
3404
3410
3405
3411
if payload. previewStyle == . dynamicReplacement {
3406
3412
for (arg, newValue) in [
@@ -3440,6 +3446,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
3440
3446
}
3441
3447
3442
3448
let selectedInputPath : Path
3449
+ let newVFSOverlayPath : Path ?
3443
3450
if payload. previewStyle == . xojit {
3444
3451
// Also pass the auxiliary Swift files.
3445
3452
commandLine. append ( contentsOf: originalInputs. map ( \. str) )
@@ -3448,7 +3455,8 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
3448
3455
if let driverPayload = payload. driverPayload {
3449
3456
do {
3450
3457
// Inject the thunk source into the output file map
3451
- let map = SwiftOutputFileMap ( files: [ sourceFile. str: . init( object: outputPath. str) ] )
3458
+ let pchPath = driverPayload. tempDirPath. join ( driverPayload. outputPrefix + " -primary-Bridging-header.pch " )
3459
+ let map = SwiftOutputFileMap ( files: [ sourceFile. str: . init( object: outputPath. str) , " " : . init( pch: pchPath. str) ] )
3452
3460
let newOutputFileMap = driverPayload. tempDirPath. join ( UUID ( ) . uuidString)
3453
3461
try fs. createDirectory ( newOutputFileMap. dirname, recursive: true )
3454
3462
try fs. write ( newOutputFileMap, contents: ByteString ( JSONEncoder ( outputFormatting: [ . prettyPrinted, . sortedKeys, . withoutEscapingSlashes] ) . encode ( map) ) )
@@ -3457,19 +3465,20 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
3457
3465
// rdar://127735418 ([JIT] Emit a vfsoverlay for JIT preview thunk compiler arguments so clients can specify the original file path when substituting contents)
3458
3466
let vfs = VFS ( )
3459
3467
vfs. addMapping ( sourceFile, externalContents: inputPath)
3460
- let newVFSOverlayPath = driverPayload. tempDirPath. join ( " vfsoverlay- \( inputPath. basename) .json " )
3468
+ newVFSOverlayPath = driverPayload. tempDirPath. join ( " vfsoverlay- \( inputPath. basename) .json " )
3461
3469
try fs. createDirectory ( newOutputFileMap. dirname, recursive: true )
3462
3470
let overlay = try vfs. toVFSOverlay ( ) . propertyListItem. asJSONFragment ( ) . asString
3463
- try fs. write ( newVFSOverlayPath, contents: ByteString ( encodingAsUTF8: overlay) )
3464
-
3465
- commandLine. append ( contentsOf: [ " -vfsoverlay " , newVFSOverlayPath. str] )
3471
+ try fs. write ( newVFSOverlayPath!, contents: ByteString ( encodingAsUTF8: overlay) )
3466
3472
} catch {
3467
3473
return [ ]
3468
3474
}
3475
+ } else {
3476
+ newVFSOverlayPath = nil
3469
3477
}
3470
3478
}
3471
3479
else {
3472
3480
selectedInputPath = inputPath
3481
+ newVFSOverlayPath = nil
3473
3482
commandLine. append ( contentsOf: [ inputPath. str] )
3474
3483
}
3475
3484
@@ -3516,6 +3525,21 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
3516
3525
casOptions: driverPayload. casOptions
3517
3526
) {
3518
3527
commandLine = newCommandLine
3528
+ // For swift caching jobs, add extra flags.
3529
+ if commandLine. contains ( " -cache-compile-job " ) {
3530
+ // Ideally, we should ask if swift-frontend supports the flag but we can only ask driver for an approximation.
3531
+ if LibSwiftDriver . supportsDriverFlag ( spelled: " -module-import-from-cas " ) {
3532
+ commandLine. append ( " -module-import-from-cas " )
3533
+ }
3534
+ // Then drop the cache build flag to do uncached preview compilation.
3535
+ commandLine. removeAll {
3536
+ $0 == " -cache-compile-job "
3537
+ }
3538
+ }
3539
+ // Add vfsoverlay after the driver invocation as it can affect the module dependencies, causing modules from regular builds not being reused here.
3540
+ if let vfsOverlay = newVFSOverlayPath {
3541
+ commandLine. append ( contentsOf: [ " -vfsoverlay " , vfsOverlay. str] )
3542
+ }
3519
3543
} else {
3520
3544
commandLine = [ ]
3521
3545
}
0 commit comments