Vapor 4 and MacPorts

Hi everybody,

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!

Lars

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.

3 Likes

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!

1 Like

What are those commands? Are they somewhere documented, ideally as step by step instructions?

vapor build.-> swift build
vapor run -> swift run
vapor update -> swift package update
vapor xcode -> Don't use this anymore with Xcode 11, just do open Package.swift

1 Like

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-1100.0.33.15)

Target: x86_64-apple-darwin19.3.0

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

Any idea?

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:

export TOOLCHAINS=swift

now I get:

swift --version

Apple Swift version 5.2-dev (Swift 33150e32b4)

Target: x86_64-apple-darwin19.3.0

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
  • cd toolbox-18.0.0-beta.27/
  • export TOOLCHAINS=swift
  • swift build --disable-sandbox
  • this went fine besides some warnings about UnsafeMutablePointers
  • mv .build/debug/vapor vapor-beta
  • ./vapor-beta --help

which resulted in:

Usage: ./vapor-beta <command> 

Vapor Toolbox (Server-side Swift web framework)

Commands:
  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
Cloning template...
name: hello
Would you like to use Fluent?
y/n> no
fluent: No
Generating project files
+ Package.swift
+ main.swift
+ configure.swift
+ routes.swift
+ .gitkeep
+ AppTests.swift
+ Dockerfile
+ docker-compose.yml
+ .gitignore
+ .dockerignore
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?

regards,

Lars

typing swift run in the Terminal brought some success:

Fetching https://github.com/vapor/vapor.git
Fetching https://github.com/vapor/console-kit.git
Fetching https://github.com/apple/swift-crypto.git
Fetching https://github.com/vapor/websocket-kit.git
Fetching https://github.com/apple/swift-metrics.git
Fetching https://github.com/apple/swift-nio-extras.git
Fetching https://github.com/swift-server/swift-backtrace.git
Fetching https://github.com/vapor/async-kit.git
Fetching https://github.com/apple/swift-nio-http2.git
Fetching https://github.com/vapor/routing-kit.git
Fetching https://github.com/apple/swift-log.git
Fetching https://github.com/apple/swift-nio-ssl.git
Fetching https://github.com/swift-server/async-http-client.git
Fetching https://github.com/apple/swift-nio.git
Cloning https://github.com/vapor/async-kit.git
Resolving https://github.com/vapor/async-kit.git at 1.0.0-rc.1
Cloning https://github.com/swift-server/async-http-client.git
Resolving https://github.com/swift-server/async-http-client.git at 1.1.0
Cloning https://github.com/vapor/websocket-kit.git
Resolving https://github.com/vapor/websocket-kit.git at 2.0.0-rc.1
Cloning https://github.com/apple/swift-nio-ssl.git
Resolving https://github.com/apple/swift-nio-ssl.git at 2.6.2
Cloning https://github.com/vapor/console-kit.git
Resolving https://github.com/vapor/console-kit.git at 4.0.0-rc.1
Cloning https://github.com/vapor/routing-kit.git
Resolving https://github.com/vapor/routing-kit.git at 4.0.0-rc.1
Cloning https://github.com/vapor/vapor.git
Resolving https://github.com/vapor/vapor.git at 4.0.0-rc.3.1
Cloning https://github.com/apple/swift-metrics.git
Resolving https://github.com/apple/swift-metrics.git at 2.0.0
Cloning https://github.com/apple/swift-nio-extras.git
Resolving https://github.com/apple/swift-nio-extras.git at 1.4.0
Cloning https://github.com/apple/swift-crypto.git
Resolving https://github.com/apple/swift-crypto.git at 1.0.0
Cloning https://github.com/apple/swift-log.git
Resolving https://github.com/apple/swift-log.git at 1.2.0
Cloning https://github.com/apple/swift-nio-http2.git
Resolving https://github.com/apple/swift-nio-http2.git at 1.9.1
Cloning https://github.com/swift-server/swift-backtrace.git
Resolving https://github.com/swift-server/swift-backtrace.git at 1.1.1
Cloning https://github.com/apple/swift-nio.git
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!"

Yay!

For future reference, SPM has this usage doc for providing more details about individual commands

1 Like

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 :tada:

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!

1 Like
Terms of Service

Privacy Policy

Cookie Policy