How to install Swift package via package manager? - swift

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 command from terminal.
git clone https://github.com/apple/example-package-dealer.git
cd example-package-dealer
swift build
.build/debug/Dealer
While I run swift build, error arise.
<unknown>:0: error: no such file or directory: 'build'
Any idea?

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.

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

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.

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.

Related

vapor build command not working with Swift 3.0

I am currently following the small and brief introduction to Swift Vapor by following their "Hello World" tutorial on their website. However I keep getting an error from swift-package when I try to build the project where it shows the following.
$ vapor build
No .build folder, fetch may take a while...
Fetching Dependencies [Failed]
Error: swift-package: error: unknown command: --enable-prefetching
I cannot seem to find out how to resolve this online. Anybody have any idea?
you have not mentioned your environment, so i'm giving solution for macOS.
I had the same issue, my swift version is 3.0.2 and vapor toolbox version is 1.0.9,
I tried the following thing to make it work
get into your project directory
create xcode project with command
swift package generate-xcodeproj
open xcode project
Select your scheme as App like this
and then build and run app
hope this helps!!
Make sure that you're using the correct command line tools for the Swift Version that you're using.
You can check from Xcode > Preferences > Locations > Command Line Tools
For me, using swift 3.0.2, vapor build command doesn't work neither.
However using swift 3.1.0, vapor build command works well.
My Vapor toolbox version is v1.1.0
I had the same problem, and I had Swift 3.1 installed. I deleted old version completely and installed new one and now it's building fine.
Try
rm -rf /usr/local/bin/vapor
brew tap vapor/homebrew-tap

than
brew install vapor
or
brew link vapor
if you have installed a new version previously.

Cannot build any Swift project at all due to strange error about MacOSX10.11.sdk

I'm running macOS 10.12.3 with Xcode 8.3.
I cannot build any macOS Swift projects with it.
If I create a new Cocoa application Xcode project and set it to use Swift, when I try to compile it, I immediately get the following error in the "check dependencies" phase:
error: There is no SDK with the name or path '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk'
I have no idea what's going wrong!
The only clue I have is that earlier I created a symlink with the path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk that pointed to MacOSX.sdk in order to fix an issue where an older build of Qt that required an SDK with that path. However, deleting the symlink has no effect.
I can build Swift projects that targeting other platforms like iOS. Just not macOS.
Help!
try running this command then reopening the project
(Xcode uses xtools in the command line to build its projects)
sudo xcode-select -switch /path/to/file/
(by default the path is)/Applications/Xcode.app/
look at this pic
saw it here yesterday

Command Line Tool - Error - xcrun: error: unable to find utility "xcodebuild", not a developer tool or in PATH

I am getting this error while building the SwiftJSON framework to the Some Xcode project through Carthage Dependency Manager.
Sivaramaiahs-Mac-mini:GZipDemoApp vsoftMacmini5$ carthage update
--platform iOS
*** Fetching GzipSwift
*** Fetching SwiftyJSON
*** Checking out GzipSwift at "3.1.1"
*** Downloading SwiftyJSON.framework binary at "3.1.3"
*** xcodebuild output can be found in /var/folders/7m/y0r2mdhn0f16zz1nlt34ypzr0000gn/T/carthage-xcodebuild.apLXCc.log
A shell task (/usr/bin/xcrun xcodebuild -project
/Users/vsoftMacmini5/Desktop/GZipDemoApp/Carthage/Checkouts/GzipSwift/Gzip.xcodeproj
CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES -list)
failed with exit code 72:
xcrun: error: unable to find utility "xcodebuild", not a developer
tool or in PATH
I solved that problem by setting the Command Line Tools in Xcode. Go to:
Xcode > Preferences > Locations
And select the command line tool from the dropdown. If you have only one version of Xcode installed, there should be only one option. If you have several versions of Xcode, then you must choose the one you need.
Update (added image for reference)
The simplest fix is from CLI:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
(this should be path to your Xcode.app)
By the way this can happen even if you have only one version of Xcode . It happens when you instal homebrew before the first Xcode installation (which makes sense because you may want to install Xcode through mas install 497799835 and mas needs homebrew).
Following command worked for me
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Module compiled with swift 3.0 cannot be imported in Swift 3.0.1

I upgraded Xcode to 8.1 GM and am now getting the below error for SwiftyJSON. Other imported frameworks seem to work. Is there a way to force this to work in Swift 3 until SwiftyJSON upgrades their framework? I used Carthage to import/update frameworks. I also tried changing Use Legacy Swift language version On and Off to no avail.
Module compiled with Swift 3.0 cannot be imported in Swift 3.0.1:
Modules/SwiftyJSON.swiftmodule/arm64.swiftmodule
SwiftyJson is being downloaded precompiled by carthage. The precompiled download is with Swift Version 3.0. That makes the compiler complain that the version is not correct. Using the following command:
carthage update --platform iOS --no-use-binaries
SwiftyJson (and all other frameworks within Carthage) will be compiled locally using the local version of Swift (3.0.1) and the compiler will not complain anymore.
Remove the app chache from DerivedData, and rebuild. the error may be fixed.
The DerivedData path like this:
~/Library/Developer/Xcode/DerivedData/
Make sure you've placed the new XCode 8.1 GM package in your Applications folder. We ran into this issue when one of us was running Carthage to update our dependencies, but had not replaced the XCode old 8.0 application in the applications folder (8.1 GM was running off the Desktop).
You want to make sure that when you run the following in terminal: xcrun swift -version that it returns Apple Swift version 3.0.1.
Updating default Xcode to new one on terminal worked for me.
Step 1 : Use following command to update Xcode version to latest on Terminal. Ref
sudo xcode-select -switch <path/to/>Xcode.app
Step 2 : Now try carthage update command
carthage update --platform iOS
Just to give the latest updates:
Carthage has released version 0.20 on Feb 27, 2017.
Carthage now only uses the pre-build binary if available pre-build binary is compatible.
That is being said, you no longer have to use: --no-use-binaries to avoid incompatible pre-build framework.
So make sure that you have carthage version greater than 0.20 and simply do:
carthage update --platform iOS
Just like #zirinisp said:
You can Using the following command:carthage update --platform iOS --no-use-binaries
Using the following command:xcrun swift -version to see the Swift version
Do this: Xcode->preferences->locations to clear the derived data and archives data, the most important to change the command line tools to "Xcode 8.1"
Using the following command:xcrun swift -version,you can see the swift version is 3.0.1
Set Use Legacy Swift Language Version = NO
I hope it will help you
Move the beta/GM version if the Xcode to /Applications folder and name it Xcode-beta
Check the output of:
xcrun swift --version
by running this command in terminal, its output should match with the swift version you want the app to compile, because Carthage uses output of this command, to determine the local Swift version.
Update Xcode version to latest on Terminal by running following command:
sudo xcode-select -s /Applications/Xcode-beta.app/
Build the libraries for iOS and prevents Carthage from downloading existing (yet incompatible) precompiled binaries, by running following command:
carthage update --platform iOS --no-use-binaries
Clean & Build
I had exactly the same issue with the library XCTest_Gherkin, what it worked for me was:
Product -> Scheme -> XCTest-Gherkin
Product -> Build
Hope it helps. I am using Cocoapods.
In Xcode Build Settings make sure your Framework Search Paths contain the appropriate Carthage Build folder:
$(inherited)
$(PROJECT_DIR)/Carthage/Build/iOS

swift build doesn't work

I'm trying to run Kitura project on XCode. I tried to follow instructions on this page ([https://github.com/IBM-Swift/Kitura/wiki/Building-your-Kitura-application-on-XCode]), however I failed with step 3 – run swift build -X. I get this error:
error: unable to invoke subcommand: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build (No such file or directory)
Looks like I have latest toolchain installed (see the screenshot below).
I also have both XCode 7.3.1 and XCode 8 beta. What would you suggest to solve that problem?
As Daniel mentioned above, Kitura right now requires use of the June 6 drop of the Swift Development toolchain. This toolchain can only be used with Xcode v7.3.1. The toolchain format changed between Xcode 7.x and newer Xcode 8 beta. When using the Xcode 8 beta with the new June 20 toolchain, there's another step that you need to do before you can run swift build from the command line.
From the command line, enter the following command:
$ sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer/
This command is necessary to inform Xcode where to find the required binaries and frameworks.
To switch it back, just use the same command but point it at non-beta version of Xcode:
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
Using these commands will eliminate the error <unknown>:0: error: Swift does not support the SDK 'MacOSX10.11.sdk' error: exit(1): that you ran into.
The Xcode 8 beta will be required to be used for all future Swift.org toolchains unless otherwise specified.
As of this writing, Kitura only compiles with the 06-06 Swift Development toolchain so make sure you have that installed.
In addition the wiki was out of date, the generate Xcode project command got renamed to swift package generate-xcodeproj. I updated the wiki to reflect this change.
Try:
export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"