Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vapor project not building/running with Swift 4 and Xcode 9

Tags:

swift

vapor

I have the most recent version of Xcode 9 installed and have reinstalled vapor with brew a couple times now, but I'm still getting the following error whenever I try to build/run/update the project.

Here's what I'm working with

1.) Vapor Toolbox: 3.1.2

2.) Apple Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)
    Target: x86_64-apple-macosx10.9

3.) Xcode 9.0
    Build version 9M136h
Error: Could not generate Xcode project: error: manifest parse error(s):
/var/folder/60/n3ldjzgs5vsg06v17_1yy44h0000gn/T/TemporaryFile.VwrbJo.swift:41:5
: error: argument 'targets' must preceed argument 'dependencies'
    targets" [
    ^
error: The product dependency 'Vapor' was not found.
error: The product dependency 'FluentProvider' was not found.
error: The product dependency 'Testing' was not found.

Here is my Package.swift file. Looking at my original error, I did try switching the 'targets' and 'dependencies' order in which they appear in the file. This didn't solve anything and produced the following error message: error: argument 'dependencies' must precede argument 'targets'

Package.swift

let package = Package(
    name: "test",
    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"])
    ]
)
like image 351
Nathan Ortega Avatar asked Nov 11 '17 23:11

Nathan Ortega


1 Answers

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

  1. Double Check Versions: "the most recent releases" would be at least Xcode 9.1 (9B55) and Apple Swift 4.0.2 (swiftlang-900.0.69.1 clang-900.0.38)

  2. Verify that the first line in Packages.swift is // swift-tools-version:4.0. Without swift-tools-version line, Packages.swift could be processed as swift-tools-version 3. which will cause an error.*

cd _PROJECT_PATH_
swift package tools-version
# if not 4.0.0, then …
swift package tools-version --set-current

An example, Package.swift is shown below. See Swift Package Manager Manifest API Redesign and swift-package-manager Usage Documentation for additional information.

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift
// required to build this package. 
// Syntax: '// swift-tools-version:<specifier>' on the 1st line

import PackageDescription

let package = Package(
    name: "test",
    products: [
        .library(name: "App", targets: ["App"]),
        .executable(name: "Run", targets: ["Run"])
    ],
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.3.0")),
        .package(url: "https://github.com/vapor/fluent-provider.git", .upToNextMajor(from: "1.3.0")),
    ],
    targets: [
        .target(
            name: "App",
            dependencies: ["Vapor", "FluentProvider"],
            exclude: [
                    "Config",
                    "Public",
                    "Resources",
                    ]
        ),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App", "Testing"])
    ]
)
  1. Recheck
cd _PROJECT_PATH_
swift package tools-version
# should be 4.0.0

vapor clean
vapor update
vapor --version

# Vapor Toolbox: 3.1.2
# Vapor Framework: 2.3.0
  1. Try to build again.

More notes are posted on StackOverflow here for using Xcode 9 and Swift 4 with Vapor 2.

The GitHub repository Vapor Examples Lab has several example projects which have been migrated to Vapor 2 and Swift 4.

like image 155
l --marc l Avatar answered Sep 19 '22 13:09

l --marc l