Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push Vapor 2 Swift 4 project to Heroku

Using Xcode 9 and Swift 4 as well as vapor heroku push / vapor heroku init, I receive:

-----> Swift app detected
Cloning into 'swiftenv'...
Swift 3 Heroku Installer
šŸ”¢  Version: 3.1.1
šŸ–„  Operating System: ubuntu1404
šŸ“¦ Installing Swiftenv
Cloning into '/app/.swiftenv'...
šŸ¦ Installing Swift
Downloading https://swift.org/builds/swift-3.1.1-release/ubuntu1604/swift-3.1.1-RELEASE/swift-3.1.1-RELEASE-ubuntu16.04.tar.gz
/tmp/swiftenv-3.1.1- /tmp/build_d
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
/tmp/build_d
3.1.1 has been installed.
āœ…  Done
-----> Installing clang-3.7.0
precompile
-----> Building Package ... this will take a while
swift-build: error: Package requires minimum Swift tools version 4.0.0. Current Swift tools version is 3.1.0
 !     Push rejected, failed to compile Swift app.
 !     Push failed

In the Package.swift file it says:

// swift-tools-version:4.0

import PackageDescription

let package = Package(
    name: "name",
    products: [
        .library(name: "App", targets: ["App"]),
        .executable(name: "Run", targets: ["Run"])
    ],
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.1.0")),
        .package(url: "https://github.com/vapor/fluent-provider.git", .upToNextMajor(from: "1.2.0")),
    ],
    targets: [
        .target(name: "App", dependencies: ["Vapor", "FluentProvider"],
                exclude: [
                    "Config",
                    "Public",
                    "Resources",
                ]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App", "Testing"])
    ]
)

Other than that it is literally the initial api template project. What am I missing? Help is very appreciated.

like image 847
David Seek Avatar asked Oct 05 '17 00:10

David Seek


1 Answers

The project template was recently updated to require Swift 4, but the Heroku buildpack still installs Swift 3.1.1 by default. Until the template is updated to resolve this situation, do this:

  1. Create a file called .swift-version in your project root with 4.0 inside.
  2. Commit and push to Heroku.

The buildpack will now install Swift 4 and your project will compile.

Update (2017-11-13)

I have updated the buildpack, therefore the steps above are no longer necessary.
New applications and pushes without a pinned version will use Swift 4.0.2.

like image 154
vzsg Avatar answered Sep 28 '22 01:09

vzsg