I was going to try out Vapor 4 and followed the instructions here: https://docs.vapor.codes/4.0/install/macos/ .
However, it seems that Homebrew is required when installing Vapor 4 on the Mac. Since I am a long time MacPorts user and Homebrew and MacPorts don't go well with each other (concurrent installation is not recommended), I am currently out of the loop.
So my question is: are there any plans to support MacPorts in the future? Or is there an alternate way to install Vapor 4 without using Homebrew?
Thanks in advance!
If you feel comfortable learning the Swift Package Manager commands and executing those instead, then you can completely ignore the Vapor CLI for working with Vapor.
Much of it is shorthand for underlying SPM commands or speeding up project bootstrapping.
You're going to have problems unfortunately. MacPorts screws up the path of various things that SwiftPM uses when building dependencies, causing weird errors with NSCurses. I would love to say it's all good, but every time sometime tries to get going with Vapor having installed MacPorts it doesn't end well. You may be able to get it to work though, be interested to hear how you get along!
What are those commands? Are they somewhere documented, ideally as step by step instructions?
vapor run ->
vapor update ->
swift package update
vapor xcode -> Don't use this anymore with Xcode 11, just do
https://docs.vapor.codes/4.0/install/macos/ also says that Swift 5.2 is needed for Vapor 4. So I just downloaded https://swift.org/builds/swift-5.2-branch/xcode/swift-5.2-DEVELOPMENT-SNAPSHOT-2020-03-05-a/swift-5.2-DEVELOPMENT-SNAPSHOT-2020-03-05-a-osx.pkg and installed it. So far so good, I can now choose in Xcode > Toolchains which toolchain to use.
However when I type
swift --version at the command line I still get:
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1188.8.131.52)
I tried a subsequent
xcode-select --install but that didn't help either (said:
error: command line tools are already installed, use "Software Update" to install updates).
Nevermind, found a solution here: https://medium.com/xcblog/switching-swift-versions-inside-xcode-using-toolchains-755b28831c43
I just had to issue the following command:
now I get:
Apple Swift version 5.2-dev (Swift 33150e32b4)
Another way is
xcrun --toolchain "Swift Development Snapshot" --run swift (replace “Swift Development Snapshot” with the name of the toolchain you want to use) if you want to use a specific toolchain.
After looking at https://github.com/vapor/homebrew-tap/blob/master/vapor-beta.rb I did the following:
- downloaded https://github.com/vapor/toolbox/archive/18.0.0-beta.27.tar.gz then
openssl dgst -sha256 /Users/lars/Downloads/toolbox-18.0.0-beta.27.tar.gz
- checksum was fine
tar -xvf /Users/lars/Downloads/toolbox-18.0.0-beta.27.tar.gz
- install the dependency openssl:
sudo port -v install openssl
swift build --disable-sandbox
- this went fine besides some warnings about UnsafeMutablePointers
mv .build/debug/vapor vapor-beta
which resulted in:
Usage: ./vapor-beta <command>
Vapor Toolbox (Server-side Swift web framework)
supervisor Commands for working with Supervisord
xcode Opens an app in Xcode.
new Generates a new app.
heroku Commands for working with Heroku
build Builds an app in the console.
run Runs an app from the console.
clean Cleans temporary files.
Use `./vapor-beta <command> [--help,-h]` for more information on a command.
next: see if the whole thing works!
SLPN-NB-LSH:toolbox-18.0.0-beta.27 lars$ cd ../Documents/Projects/
SLPN-NB-LSH:Projects lars$ mkdir vapor-test
SLPN-NB-LSH:Projects lars$ cd vapor-test/
SLPN-NB-LSH:vapor-test lars$ ~/toolbox-18.0.0-beta.27/vapor-beta new hello -n
Would you like to use Fluent?
Generating project files
Creating git repository
Adding first commit
_ __ ___ ___ ___
\ \ / / /\ | |_) / / \ | |_)
\_\/ /_/--\ |_| \_\_/ |_| \
a web framework for Swift
Project hello has been created!
Use cd hello to enter the project directory
Use vapor xcode to open the project in Xcode
SLPN-NB-LSH:vapor-test lars$ cd hello/
SLPN-NB-LSH:hello lars$ open Package.swift
everything went fine so far, Xcode opened and the project was there.
But I could not run it. I've got the following error:
/Users/lars/Documents/Projects/vapor-test/hello/Package.swift: package at '/Users/lars/Documents/Projects/vapor-test/hello' is using Swift tools version 5.2.0 but the installed version is 5.1.0
despite having the new 5.2 toolchain selected in Xcode > Toolchains
How can I convince Xcode to use the selected 5..2 toolchain?
swift run in the Terminal brought some success:
Resolving https://github.com/vapor/async-kit.git at 1.0.0-rc.1
Resolving https://github.com/swift-server/async-http-client.git at 1.1.0
Resolving https://github.com/vapor/websocket-kit.git at 2.0.0-rc.1
Resolving https://github.com/apple/swift-nio-ssl.git at 2.6.2
Resolving https://github.com/vapor/console-kit.git at 4.0.0-rc.1
Resolving https://github.com/vapor/routing-kit.git at 4.0.0-rc.1
Resolving https://github.com/vapor/vapor.git at 4.0.0-rc.3.1
Resolving https://github.com/apple/swift-metrics.git at 2.0.0
Resolving https://github.com/apple/swift-nio-extras.git at 1.4.0
Resolving https://github.com/apple/swift-crypto.git at 1.0.0
Resolving https://github.com/apple/swift-log.git at 1.2.0
Resolving https://github.com/apple/swift-nio-http2.git at 1.9.1
Resolving https://github.com/swift-server/swift-backtrace.git at 1.1.1
Resolving https://github.com/apple/swift-nio.git at 2.14.0
[1349/1349] Linking Run
[ NOTICE ] Server starting on http://127.0.0.1:8080
[ INFO ] GET /
[ INFO ] GET /favicon.ico
[ ERROR ] Abort 404: Not Found
opening http://127.0.0.1:8080 resulted in a page displaying "It works!"
For future reference, SPM has this usage doc for providing more details about individual commands
Nice! Glad it's working, I wonder how much of that is the removal of OpenSSL/LibreSSL as a dependency! Great that MacPorts is now an option
I did indeed install openssl using macports before building Vapor 4 … it was listed as dependency in the brew formula.
Yeah the PR to fix that for brew is waiting on APNS fixes, but previously linking to OpenSSL has been broken with MacPorts. Great that it's fixed!