You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
xcodeSelect.launch()
xcodeSelect.waitUntilExit()
let path = String(data: output.fileHandleForReading.readDataToEndOfFile(),
encoding: .utf8)!
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.
The text was updated successfully, but these errors were encountered:
Immediately after creating this I realized that there are errors in the build log from xcode-select that indicated that I'd made a mistake. This still seems like a massive hack though...
Environment
Xcode 11.6.01.
Additional Detail from JIRA
md5: d875183549a98d3e9f0ae59f9f2c026b
Issue Description:
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.
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).
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.
The text was updated successfully, but these errors were encountered: