@@ -48,7 +48,10 @@ struct Plugin: CommandPlugin {
4848 " --package-name " , context. package . displayName,
4949 " --wit-output-path " , witOutputPath. string,
5050 " --swift-output-path " , swiftOutputPath. string,
51- " -I " , buildPath. string
51+ " -I " , buildPath. string,
52+ // SwiftPM 6.0 and later emits swiftmodule files into a separate directory
53+ // https://github.com/swiftlang/swift-package-manager/pull/7212
54+ " -I " , buildPath. appending ( [ " Modules " ] ) . string,
5255 ]
5356 if let sdk {
5457 arguments += [ " -sdk " , sdk]
@@ -74,12 +77,28 @@ struct Plugin: CommandPlugin {
7477 return nil
7578 }
7679 for line in contents. split ( separator: " \n " ) {
77- let prefix = " executable: \" "
78- if line. hasPrefix ( prefix) , line. hasSuffix ( " /swiftc \" " ) {
79- let pathStart = line. index ( line. startIndex, offsetBy: prefix. count)
80- let pathEnd = line. index ( before: line. endIndex)
81- let executablePath = line [ pathStart..< pathEnd]
82- return String ( executablePath)
80+ do {
81+ let prefix = " executable: \" "
82+ if line. hasPrefix ( prefix) , line. hasSuffix ( " /swiftc \" " ) {
83+ let pathStart = line. index ( line. startIndex, offsetBy: prefix. count)
84+ let pathEnd = line. index ( before: line. endIndex)
85+ let executablePath = line [ pathStart..< pathEnd]
86+ return String ( executablePath)
87+ }
88+ }
89+ do {
90+ // Swift 6.0 no longer uses llbuild's built-in swift tool. Instead,
91+ // it uses the generic shell tool with full arguments.
92+ // https://github.com/swiftlang/swift-package-manager/pull/6585
93+ let prefix = " args: "
94+ if line. hasPrefix ( prefix) {
95+ let argsString = line [ line. index ( line. startIndex, offsetBy: prefix. count) ... ]
96+ guard let args = try ? JSONDecoder ( ) . decode ( [ String ] . self, from: Data ( argsString. utf8) ) ,
97+ let swiftc = args. first ( where: { $0. hasSuffix ( " /swiftc " ) } ) else {
98+ continue
99+ }
100+ return swiftc
101+ }
83102 }
84103 }
85104 return nil
0 commit comments