Component/s: Package Manager
I'm trying to use SwiftSyntax from a SPM project generated by Package.swift.
It's possible to open Package.swift as a project in Xcode (double clicking on it, not by generating an xcodeproj). You can use SwiftSyntax in your package and the build succeeds. However the built product will immediately crash because SwiftSyntax dynamically links some libraries from your swift toolchain, and SPM doesn't automatically add this as a search path (unlike the xcode proj you can generated with `swift package --generate-xcodeproj` apparently).
I can work around this by manually hard coding my toolchain path into my Package.swift file. However this isn't a great solution, because it requires that everyone have their Xcode in the exact same place.
linkerSettings: [.unsafeFlags(["-rpath", "/Applications/Xcode.22.214.171.124E708.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/"])]),
My next thought was to use xcode-select to find the path to Xcode. This appears to work, however, it's difficult to set up because mistakes can actually cause Xcode to get stuck parsing the Package.swift file until you force-quit, and errors are in an out of the way place (build logs).
let xcodeSelect = Process()
xcodeSelect.launchPath = "/usr/bin/xcode-select"
xcodeSelect.arguments = ["-p"]
let output = Pipe()
xcodeSelect.standardOutput = output
let path = String(data: output.fileHandleForReading.readDataToEndOfFile(),
let searchPath = "(path)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/"
It seems like it could be useful if the ability to get the path to various external files was built into SPM as API for Package.swift to use, so this was easier and more resiliant.