@@ -357,11 +357,30 @@ extension SwiftPMBuildSystem: SKCore.BuildSystem {
357
357
358
358
public var indexPrefixMappings : [ PathPrefixMapping ] { return [ ] }
359
359
360
+ /// Return the compiler arguments for the given source file within a target, making any necessary adjustments to
361
+ /// account for differences in the SwiftPM versions being linked into SwiftPM and being installed in the toolchain.
362
+ private func compilerArguments( for file: URL , in buildTarget: any SwiftBuildTarget ) async throws -> [ String ] {
363
+ let compileArguments = try buildTarget. compileArguments ( for: file)
364
+
365
+ // Fix up compiler arguments that point to a `/Modules` subdirectory if the Swift version in the toolchain is less
366
+ // than 6.0 because it places the modules one level higher up.
367
+ let toolchainVersion = await orLog ( " Getting Swift version " ) { try await toolchainRegistry. default? . swiftVersion }
368
+ guard let toolchainVersion, toolchainVersion < SwiftVersion ( 6 , 0 ) else {
369
+ return compileArguments
370
+ }
371
+ return compileArguments. map { argument in
372
+ if argument. hasSuffix ( " /Modules " ) , argument. contains ( self . workspace. location. scratchDirectory. pathString) {
373
+ return String ( argument. dropLast ( 8 ) )
374
+ }
375
+ return argument
376
+ }
377
+ }
378
+
360
379
public func buildSettings(
361
380
for uri: DocumentURI ,
362
381
in configuredTarget: ConfiguredTarget ,
363
382
language: Language
364
- ) throws -> FileBuildSettings ? {
383
+ ) async throws -> FileBuildSettings ? {
365
384
guard let url = uri. fileURL, let path = try ? AbsolutePath ( validating: url. path) else {
366
385
// We can't determine build settings for non-file URIs.
367
386
return nil
@@ -387,13 +406,13 @@ extension SwiftPMBuildSystem: SKCore.BuildSystem {
387
406
// getting its compiler arguments and then patching up the compiler arguments by replacing the substitute file
388
407
// with the `.cpp` file.
389
408
return FileBuildSettings (
390
- compilerArguments: try buildTarget . compileArguments ( for: substituteFile) ,
409
+ compilerArguments: try await compilerArguments ( for: substituteFile, in : buildTarget ) ,
391
410
workingDirectory: workspacePath. pathString
392
411
) . patching ( newFile: try resolveSymlinks ( path) . pathString, originalFile: substituteFile. absoluteString)
393
412
}
394
413
395
414
return FileBuildSettings (
396
- compilerArguments: try buildTarget . compileArguments ( for: url) ,
415
+ compilerArguments: try await compilerArguments ( for: url, in : buildTarget ) ,
397
416
workingDirectory: workspacePath. pathString
398
417
)
399
418
}
0 commit comments