Vapor Toolbox Broken After Upgrading Swift

vapor toolbox broken after upgrading swift

Swift ABI is not yet stable. Thus, Swift programs (like Vapor Toolbox) must be recompiled to work with new versions of the language.

Reinstall with Brew

Simply re-installing the toolbox should fix this issue.

brew reinstall vapor/tap/vapor

Replace Old Installation With Brew

You may need to delete the existing executable if you did not originally install with Homebrew

rm /usr/local/bin/vapor

Then ensure the executable is gone

which vapor

You can now install with brew

brew install vapor/tap/vapor

Vapor doesn't work with xcode 9 and swift 4

Xcode 12 / Swift 5.3 Update

vapor is now part of homebrew/core. Source: github homebrew-core/Formula/vapor.rb.

##### If applicable, remove the obsolete 'vapor/tap' #####
## List current taps:
brew tap
# homebrew/core
# vapor/tap
## Remove tap:
brew untap vapor/tap

#### Install current version of vapor #####
brew install vapor
brew upgrade vapor

Xcode 9 / Swift 4

Check that everything is up to date. The following builds and runs for me at this time:

Use latest vapor toolbox.

Currently:

vapor new test --template=api
cd test
swift package tools-version
# 4.0.0
# use `swift package tools-version --set-current` if needed
rm Package.resolved
vapor update
vapor --version
# Vapor Toolbox: 3.1.2
# Vapor Framework: 2.3.0

Note, Vapor Framework:__ only shows when the terminal working directory pwd is pointing to a vapor project directory.

If needed ...

brew tap --full  vapor/homebrew-tap
brew update
brew upgrade

In some cases the vapor toolbox may need to be deleted and reinstalled. (see "vapor toolbox broken after upgrading swift")

Use latest Xcode release.

Currently: Xcode: 9.1, Swift: 4.0.2

swift --version
# Apple Swift version 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)

Use vapor update or swift package update

vapor new test --template=api
cd test
rm Package.resolved
vapor update

alternately,

vapor new test --template=api
cd test
rm Package.resolved
swift package update
swift package generate-xcodeproj

The above updates, compiles and runs OK for me in Xcode 9.1.

Note: However, there are about 44 new deprecation warnings of the same type. I first became aware of the characters deprecation with Xcode9.1/Swift4.0.2.

'characters' is deprecated: Please use String or Substring directly"

So, new deprecation warnings, but 0 errors ... and, more importantly, the project runs as Vapor 2 + Swift 4.

Also, check Packages.resolved versions versus what is available in each respective source repository. On github, the Vapor Examples Lab: TemplateApiTest repository contains the Packages.resolved which was generated and works with the tool chain scenario above.

Finally, double check that the target is Run on macOS and not an ARM-based iOS for this build.

Xcode schema Run > My Mac

terminal vapor update is using Swift tools version 3.1.0 which is no longer supported; use 4.0.0 or newer instead\n, output:

A somewhat detailed checklist would be …

  1. Check Swift version. Then, if needed, update Xcode for a recent released Swift version on macOS. In Xcode > Preferences > Locations > Command Line Tools, confirm that the Command Line Tools: is pointing to current toolchain version. Xcode 11.3 (11C29) provides Swift 5.1.
swift --version
# Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
# Target: x86_64-apple-darwin18.7.0

  1. If needed, update and upgrade brew to the most recent version. (Or, see https://brew.sh/ if the Homebrew package manager is not yet installed.)
brew --version
# Homebrew 2.2.2
# Homebrew/homebrew-core (git revision dc049; last commit 2019-12-28)

brew update
brew upgrade # Note: upgrade all brew installed formulas.
#brew upgrade FORMULA # use only update one formula

  1. Check the vapor/tap tap. Optionally, the tap can be removed and installed again.
brew tap  # list existing taps
# homebrew/core
# vapor/tap

brew untap vapor/tap
# Untapping vapor/tap...
# Untapped 7 formulae (148 files, 69.8KB).

brew tap --full vapor/tap

  1. Now, with the prerequisites in place, install (or reinstall) Vapor 3 vapor via brew. Vapor 4 beta vapor-beta has a github issue.
# if vapor has not been installed, then `install`
brew install vapor # Vapor 3
brew install vapor/tap/vapor # same as above. path specified formula.
#brew install vapor-beta # Vapor 4 Beta

# if vapor is already installed, the `reinstall`
brew reinstall vapor

  1. Verify.
swift --version
# Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
# Target: x86_64-apple-darwin18.7.0

vapor --version
# Vapor Toolbox: 3.1.10 .... wait, what?

brew info vapor
# vapor/tap/vapor: stable 3.1.12
# https://vapor.codes
# /usr/local/Cellar/vapor/3.1.12 (6 files, 17.8MB) *
# Built from source on 2019-12-28 at 12:46:27
# From: https://github.com/vapor/homebrew-tap/blob/master/vapor.rb

# try
vapor new SomeProjectName --template=api # or, --template=web
cd SomeProjectName
vapor build
# No .build folder, fetch may take a while...
# Fetching Dependencies [Done]
# Building Project [Done]

Oh, Vapor Toolbox 3.1.12 claims to be "3.1.10". See GitHub issue https://github.com/vapor/toolbox/issues/292.


  1. Generate Xcode Project
# still in SomeProjectName terminal working directory
vapor xcode

Swift Vapor 3 build error

Updating the version is a good solution for this issue if you are using this old version ..

Running NSApplication.shared alongside Vapor?

Vapor does not use Dispatch so I suspect you'll always need to wrap any calls that deal with UI in the DispatchQueue.main.async.

One option would be to replace the DefaultResponder with something that puts request handling on the main loop. You'd need to work out how to make Dispatch and NIO play nice however. Another option is to call out to an app delegate in your route handlers that can then do what it likes on the main thread.



Related Topics



Leave a reply



Submit