Swift on Linux: SPM

The Swift Package Manager (SPM) is a tool for creating Swift applications and managing their dependencies. SPM supports Executable and Library projects and is included as part of the Swift installation.

Prerequisites
1. You’ll need Swift and Git installed before using SPM.

To make a new Swift application, setup a folder for the project.
$ mkdir -p ~/swift/hello
$ cd ~/swift/hello

We can create a CLI (Command Line Interface) application with SPM using the executable option.
$ swift package init --type executable

View the applications folder structure with tree*.

$ tree
 .
 -- Package.swift
 -- README.md
 -- Sources
     -- hello
        -- main.swift
 -- Tests
    -- LinuxMain.swift
    -- helloTests
        -- XCTestManifests.swift
        -- helloTests.swift
 4 directories, 6 files

Run the compiled application.
$ swift build
$ swift run
Hello, World!

The compiled binary is located in a hidden folder under .build and can be executed directly.
$ ./.build/x86_64-unknown-linux-gnu/debug/hello
Hello, World!

To finish up, create a git repository and make the initial commit.
$ git init
$ git add .
$ git commit -am "Initial commit"

That is an introduction to Swift Package Manager, though there is still more to learn about dependency management.


* Install Tree
$ sudo apt install tree


References
Swift Package Manager Documentation