Skip to content

Latest commit

 

History

History
67 lines (48 loc) · 1.96 KB

Package.swift.md

File metadata and controls

67 lines (48 loc) · 1.96 KB

Package.swift — The Manifest File

Instructions for how to build a package are provided by a manifest file, called Package.swift. You can customize this file to declare build targets or dependencies, include or exclude source files, and specify build configurations for the module or individual files.

Here's an example of a Package.swift file:

import PackageDescription

let package = Package(
    name: "Hello",
    dependencies: [
        .Package(url: "ssh://git@example.com/Greeter.git", versions: "1.0.0"),
    ]
)

A Package.swift file a Swift file that declaratively configures a Package using types defined in the PackageDescription module. This manifest declares a dependency on an external package: Greeter.

If your package contains multiple targets that depend on each other you will need to specify their interdependencies. Here is an example:

import PackageDescription

let package = Package(
    name: "Example",
    targets: [
        Target(
            name: "top",
            dependencies: [.Target(name: "bottom")]),
        Target(
            name: "bottom")

The targets are named how your subdirectories are named.

Customizing Builds

That the manifest is Swift allows for powerful customization, for example:

import PackageDescription

var package = Package()

#if os(Linux)
let target = Target(name: "LinuxSources/foo")
package.targets.append(target)
#endif

With a standard configuration file format like JSON such a feature would result in a dictionary structure with increasing complexity for every such feature.

Depending on Apple Modules (eg. Foundation)

At this time there is no explicit support for depending on Foundation, AppKit, etc, though importing these modules should work if they are present in the proper system location. We will add explicit support for system dependencies in the future. Note that at this time the Package Manager has no support for iOS, watchOS, or AppleTV platforms.