Search code examples
swiftkitura

Can't compile Swift package with Kitura on Xcode 8


Trying Kitura from IBM. I made swift package using

swift package init --type executable

then I made xcode proj with

swift package generate-xcodeproj

My Packages.swift file is like this

import PackageDescription

let package = Package(
    name: "testSwiftServer",
    dependencies: [
        .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 31)
    ]
)

and my main.swift file:

import Kitura

let router = Router()

router.get("/") {
    request, response, next in
    response.send("la la la")
    next()
}

Kitura.addHTTPServer(onPort: 8090, with: router)
Kitura.run()

I'm using new XCode8. swift --version giving me this

Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)

This works fine when I'm lunching it from command line with swift build

But when I'm trying to Run this from XCode I get error: missing required module 'CCurl'


Solution

  • It seems to be working for me. I followed the steps in a slightly different order, but was able to build and then run. I could see the expected la la la output in the browser.

    • Generate the SPM structure with the init command
    • Update Package.swift with your code above
    • Run the generate-xcodeproj command to create the Xcode project
    • Open the Xcode project
    • Updated main.swift with your code above
    • New step: Update scheme to set the Executable (Product > Scheme > Edit Scheme...)
    • Run the project
    • View http://localhost:8090 in browser

    Swift version: Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)

    Xcode version: 8.0 (8A218a)