The Manifest File of The Swift Package Manager #swiftlang


I have a strong interest in the Swift Package Manager (SwiftPM). ๐Ÿ˜

Because I enjoy watching a process building something. ๐Ÿ‘€


By the way, I tried to understand the settings of the manifest file called Package.swift.

I don't have the best solution yet, but I have some instances and failures.


Please note!

The Swift Package Manager is still in early design and development
https://github.com/apple/swift-package-manager/blob/master/README.md

So this way will be out of date. ๐Ÿ™ƒ


Instances


  1. My project name is MyProject.
  2. MyProject depends on Pokemon Package.

The manifest file of MyProject

import PackageDescription

let package = Package(
name: "MyProject",
dependencies: [
.Package(url: "โ€ฆ/Pokemon/Pokemon.git",
versions: Version(1, 0, 0)..<Version(2, 0, 0))
],
targets: [
Target(name: "MyProject")
]
)

The manifest file ofย Pokemon

import PackageDescription

let package = Package(
name: "Pokemon"
)

or

import PackageDescription

let package = Package(
name: "Pokemon",
targets: [
Target(name: "Pokemon")
]
)

Xcode project

This is one Xcode project after running `$ swift buid` and `$ swift build -X`.

We can see the following generated things:

  • Each of Package Modules in Sources
  • Each of Packages Targets
  • Target Dependencies
  • Link Binary With Libraries

Failures


Case 1:

import PackageDescription

let package = Package(
name: "MyProject",
dependencies: [
.Package(url: โ€œโ€ฆ/Pokemon/Pokemon.git",
versions: Version(1, 0, 0)..<Version(2, 0, 0))
],
targets: [
Target(
name: "Myproject",
dependencies: ["Pokemon"]
),
Target(name: "Pokemon")
]
)

This way, it's necessary to make Pokemon directory including a Swift file in Sources/ directory to generate Pokemon target.

But in fact, itโ€™s unnecessary. ๐Ÿ™„


Case 2:

Remove Target(name: โ€œPokemonโ€) from Case 1.

import PackageDescription

let package = Package(
name: "MyProject",
dependencies: [
.Package(url: "โ€ฆ/Pokemon/Pokemon.git",
versions: Version(1, 0, 0)..<Version(2, 0, 0))
],
targets: [
Target(
name: "Myproject",
dependencies: ["Pokemon"]
)
]
)

This way, an error has occured. ๐Ÿšจ

error: ModuleNotFound("Pokemon")

Itโ€™s necessary to have some modules in the Sources/ directory.

Remove dependencies: [โ€œPokemonโ€]. ๐Ÿ’


Case 3:

If Documentation/ directory has no Swift file, we need to set exclude.

import PackageDescription

let package = Package(
name: "MyProject",
dependencies: [
.Package(url: "โ€ฆ/Pokemon/Pokemon.git",
versions: Version(1, 0, 0)..<Version(2, 0, 0))
],
targets: [
Target(name: "MyProject")
],
exclude: ["Documentation"]
)

Otherwise, an error has occured. ๐Ÿšจ

error: NoSources("/.../Documentation")

Thank you for reading it to the end. ๐Ÿ˜Š