How to install Swift package via package manager?

后端 未结 4 744
清酒与你
清酒与你 2021-02-12 22:39

I am currently following the document from swift.org to play around with the new Swift Package Manager.

I cloned the demo project from Github and run the following comma

相关标签:
4条回答
  • 2021-02-12 22:52

    I was facing the same issue and in my case, I recently updated my Xcode to 8.2.1 and swift 3.0 comes with it. I was getting this log.

    Ranvijay-Mac-mini:PerfectTemplate ranaranvijaysingh$ swift build
    error: unable to invoke subcommand: /Library/Developer/CommandLineTools/usr/bin/swift-build (No such file or directory)
    

    The path it was taking was incorrect. It was suppose to be:

    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    


    To change the path, run this command.

    export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH
    

    And DONE.
    Run : swift build again on your project and if you get this error.

    xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
    xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
    error: Invalid platform path
    

    then you need to change the SDK path as well.
    In my case, I had two .sdk at path

    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ 
    
    MacOSX.sdk  MacOSX10.12.sdk
    

    To know what is your SDK path, run this command.

    xcrun --sdk macosx --show-sdk-path
    

    My case i got this.

    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
    

    To change it run this command.

    sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
    

    and NOW DONE. Try running swift build now.

    0 讨论(0)
  • 2021-02-12 22:54

    You did not add the newly installed swift to your PATH. The instructions for doing that are here.

    On OS X:

    export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"
    

    On Linux:

    export PATH=/path/to/Swift/usr/bin:"${PATH}"
    

    Then to test it works:

    swift build --version
    
    0 讨论(0)
  • 2021-02-12 23:02

    I stuck for an hour. Sadly, it's just an epic fail that downloading the wrong swift package. If you want to use swift build, MAKE SURE you download the development version.

    0 讨论(0)
  • 2021-02-12 23:05

    I think it is a problem with the latest snapshot:

    • Ubuntu 14.04 Swift 2.2 Snapshot of January 11 contains swift-build in usr/bin
    • Ubuntu 14.04 Swift 2.2 Snapshot of January 25 doesn't contain swift-build in usr/bin

    Besides, the January 25 release also seems to miss other files (libFoundation.so and libXCTest.so in usr/lib/swift/linux for instances).

    Either there has been a structure change....or, simply, the latest snapshot had a problem ;) While they fix the snapshot, simply take the older (January 11th) snapshot, and you should be fine.

    0 讨论(0)
提交回复
热议问题