JPMartha's Pancake

This blog is the way to brush up my poor English.

Getting Started the Swift Package Manager ? #swiftlang


f:id:JPMartha:20160522153525j:plain


I have an interest in the Swift Package Manager. And, I tried contributing it by sending pull requests.

But, I feel it is NOT known many developers. The reason might be that it's still in early design and development.

So, I will write stories about it in detail dividing several times.

? INFORMATION: It’s often shortened to "SwiftPM" or "SPM". Also, it seems that projects and libraries are called "package". So, I use "SwiftPM" and "package" in my stories.


SPM-0001: Let's Try the Swift Package Manager

SwiftPM will be released by Swift 3.0. For now, it's available via Development Snapshots or cloning from the Apple's repository on GitHub.

I recommend the former because I think it's easier.

By the way, it's liable to be realized the same dependency manager as CocoaPods and Carthage because the name has the word "Package Manager".

But, it seems that it's different from them. We can BUILD our package via SwiftPM WITHOUT Xcode.

Let's try SwiftPM! ?


Downloading and Installing

First, it's necessary to download Development Snapshots from Swift.org. Then, you can get a package file.

(e.g. swift-DEVELOPMENT-SNAPSHOT-2016–05–09-a-osx.pkg)

Next, install the package file according to the direction on your screen.

By default, it's located in /Library/Developer/Toolchains directory.


For your information, please try using tryswiftdev if you feel it is TIRESOME. It might make EASY for you to download and install new Development Snapshots. ?


Initializing

Create an empty directory for a new package in advance.

If using a Terminal.app, type the following command in an optional directory.

$ mkdir NewPackageName

Type the following command in a Terminal.app to change directory into the new package directory.

$ cd path/to/NewPackageName

Select an initializing mode and type the following command in a Terminal.app to initialize a new package.

Modes

  • executable (default)
  • library

Executable:

$ swift build --init

Creating executable package: PackageName
Creating Package.swift
Creating .gitignore
Creating Sources/
Creating Sources/main.swift
Creating Tests/

Library:

$ swift build --init=library

Creating library package: PackageName
Creating Package.swift
Creating .gitignore
Creating Sources/
Creating Sources/PackageName.swift
Creating Tests/
Creating Tests/LinuxMain.swift
Creating Tests/PackageName/
Creating Tests/PackageName/PackageNameTests.swift


Building

Let's try building a package. 

For now, SwiftPM supports the following configurations.

Configurations

  • debug (default)
  • release

executable - debug:

$ swift build

Compile Swift Module ‘PackageName’ (1 sources)
Linking .build/debug/PackageName

library - debug:

$ swift build

Compile Swift Module ‘PackageName’ (1 sources)

executable - release:

$ swift build -c release

Compile Swift Module ‘PackageName’ (1 sources)
Linking .build/release/PackageName

library - release:

$ swift build -c release

Compile Swift Module ‘PackageName’ (1 sources)


That’s all for this story.

I will publish a continuation of the story later! ?