Package.swift - manual

Datetime:2016-08-23 04:14:31          Topic: Swift           Share

Here is documentation for SPM manifest file Package.swift . I couldn't find a list of possible configuration values for Package.swift , so I created one, for future reference. I put here all available settings, with examples of use.

Please find examples at the end of the post.

Preamble

Package.swift is manifest file for Swift Package Manager . It is regular Swift file that is interpreted by Swift Package Manager , therefore whatever is possible in Swift, it is possible in Package.swift.

Manifest file

One thing is required in manifest file, it is instance of class Package . This instance may be configured with these properties:

name

The name of the package. String.

let package = Package(name: "alice")

Caution: Not name of the target. see:

pkgConfig

The name to use for C Modules . If defined, SPM will try to search for <name>.pc metadata file to get the additional flags needed to build the module. String.

package.pkgConfig: "libpng"

This file is used by pkg-config .

providers

An array of providers for System module. [SystemPackageProvider]. Currently, SPM supports two package providers:

  • Brew (available on macOS)
  • Apt (available on Linux)
package.providers = [.Brew("openssl")]

in this example, it will result in suggesting run command brew install openssl at some point.

targets

An array of targets. If your package contains multiple targets that depend on each other you will need to specify their interdependencies.[Target].

Target describe an individual target.

let targetFirst  = Target(name: "first", dependencies: [dep1, dep2])  
let targetSecond = Target(name: "second", dependencies: [dep2, dep3])

package.targets.append(targetFirst)  
package.targets.append(targetSecond)
package.targets = [  
    Target(name: "first", dependencies: [
        .Package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", majorVersion: 0)
    ])
]

Caution: list of available targets depends on directory layout. "first" and "second" in this example refers to directories Sources/first , Sources/second

dependencies

An array of dependencies. List of packages that our package depends on.

package.dependencies = [  
    Package.Dependency.Package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", majorVersion: 0)
]

// or

package.dependencies = [  
    .Package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", majorVersion: 0)
]

Caution: if our URL can't point to branch, let's say, a branch of GitHub repository, we can't clone that branch. In this case it is advised clone branch locally and point to local directory, for example:

package.dependencies = [  
    .Package(url: "../CryptoSwift-swift3", majorVersion: 0)
]

TODO Version

testDependencies

The list of test dependencies. Not exposed to a parent Package

package.testDependencies = [  
    .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 3)
]

exclude

The list of directories to exclude. If you want to exclude some files and directories from Package, you can list them here

package.exclude = ["Sources/natalie/resources", "scripts"]

Package.swift

all together

let package = Package(name: "alice")

package.providers = [.Brew("openssl")]  
package.targets = [  
    Target(name: "first", dependencies: [
        .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 3)
    ])
]
package.dependencies = [  
    Package.Dependency.Package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", majorVersion: 0)
]
package.exclude = ["Sources/natalie/resources", "scripts"]

typically

let package = Package(  
    name: "alice",
    dependencies: [
        .Package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", majorVersion: 0),
        .Package(url: "../Alamofire-beta", majorVersion: 0)
    ]
)

More





About List