Uploaded image for project: 'Swift'
  1. Swift
  2. SR-13833

It should be possible to get the swift toolchain path in a Package.swift file

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Package Manager
    • Labels:
      None
    • Environment:

      Xcode 11.6.01.

      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.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            benpious Ben Pious
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: