Use Xcode for Server Side Development

Following along with the session, I have a Server which compiles and builds but won't run, has no target. What should the Run Target be?

Ok... The issue was I had the following as my config, and hadn't replaced the products.library with products.executable

Incorrect Config

import PackageDescription



let package = Package(

    name: "MyServer",

    products: [

        // Products define the executables and libraries a package produces, and make them visible to other packages.

        .library(

            name: "MyServer",

            targets: ["MyServer"]),

    ],

    dependencies: [

        // Dependencies declare other packages that this package depends on.

        // .package(url: /* package url */, from: "1.0.0"),

        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),

    ],

    targets: [

        // Targets are the basic building blocks of a package. A target can define a module or a test suite.

        // Targets can depend on other targets in this package, and on products in packages this package depends on.

        .target(

            name: "MyServer",

            dependencies: [dependencies: [

                .product(name: "Vapor", package: "vapor")

            ]),]),

        .testTarget(

            name: "MyServerTests",

            dependencies: ["MyLibrary1"]),

    ]

)

The Correct Config is shown here but is the same as that in the WWDC Session

import PackageDescription

let package = Package(
    name: "MyServer",
    platforms: [.macOS("12.0")],
    products: [
        .executable(
            name: "MyServer",
            targets: ["MyServer"]),
    ],
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.0.0")),
    ],
    targets: [
        .executableTarget(
            name: "MyServer",
            dependencies: [
                .product(name: "Vapor", package: "vapor")
            ]),
        .testTarget(
            name: "MyServerTests",
            dependencies: ["MyServer"]),
    ]
)

Resolved Issue

I had the same problem, i solved it like this:

First, change the package.swift like this: (In fact, this is the same as WWDC Session)

// swift-tools-version: 5.7
import PackageDescription

let package = Package(
  name: "MyServer",
  platforms: [.macOS("12.0")],
  products: [
    .executable(
      name: "MyServer",
      targets: ["MyServer"]),
  ],
  dependencies: [
    .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.0.0")),
  ],
  targets: [
    .executableTarget(
      name: "MyServer",
      dependencies: [
        .product(name: "Vapor", package: "vapor")
      ]),
    .testTarget(
      name: "MyServerTests",
      dependencies: ["MyServer"]),
  ]
)

Second, Find Executable menu with action Edit Scheme -> Run -> info, open the menu, you will find the target you added in Package.swift.

Hope this helps !

Use Xcode for Server Side Development
 
 
Q