Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13833] It should be possible to get the swift toolchain path in a Package.swift file #4475

Open
swift-ci opened this issue Nov 6, 2020 · 1 comment
Labels

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Nov 6, 2020

Previous ID SR-13833
Radar None
Original Reporter benpious (JIRA User)
Type Bug
Environment

Xcode 11.6.01.

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

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.

        linkerSettings: \[.unsafeFlags(\["-rpath", "/Applications/Xcode.11.6.0.11E708.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

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.

@swift-ci
Copy link
Contributor Author

swift-ci commented Nov 6, 2020

Comment by Ben Pious (JIRA)

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...

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants