@@ -164,7 +164,8 @@ struct DepsPackage {
164164 * - Starting w/ Swift 6, the arguments given by the REPL invocation give an incorrect include search path: we must add `/Modules` to the include path.
165165 * We check whether the `Modules` folder exists and add it to the command-line if it does.
166166 * Previously we added it the modified version unconditionally for each -I arguments,
167- * but if both versions are present we get compilation errors for some dependencies (for ArgumentParser for instance). */
167+ * but if both versions are present we get compilation errors for some dependencies (for ArgumentParser for instance).
168+ * - For some dependencies that have a system library target, the path to the module.modulemap of the target should be added. */
168169 /* Add `/Modules` variants import options for Swift 6. */
169170 var idx = 0
170171 while idx < ret. count {
@@ -211,6 +212,21 @@ struct DepsPackage {
211212 }
212213 }
213214 }
215+ /* Add module.modulemap in the source code checkouts that are “[system]”.
216+ * Note there is probably a much better way of doing this, but I don’t know it. */
217+ let checkoutFolder = packageFolder. appending ( " .build/checkouts " )
218+ if let directoryEnumerator = fm. enumerator ( at: checkoutFolder. url, includingPropertiesForKeys: nil ) {
219+ while let url = directoryEnumerator. nextObject ( ) as! URL ? {
220+ /* These rules are ad-hoc and work in the case I tested (an XcodeTools dependency).
221+ * There are probably many cases where they won’t work. */
222+ if url. lastPathComponent. lowercased ( ) == " module.modulemap " ,
223+ try String ( contentsOf: url) . contains ( " [system] " )
224+ {
225+ ret. append ( " -I \( url. deletingLastPathComponent ( ) . absoluteURL. path) " )
226+ directoryEnumerator. skipDescendants ( )
227+ }
228+ }
229+ }
214230 return ret
215231 }
216232
0 commit comments