swift-toolchain.github.io

Swift toolchain

Swift toolchain for Debian-based Linux distros.

version: 5.7

archs: aarch64, amd64

Debian: 11 (bullseye), 10 (buster)

Ubuntu: 22.04 (jammy), 20.04 (focal), 18.04 (bionic)

Automatic installation script

swift-toolchain will be installed at: /opt/swift-toolchain

Install dependencies:

sudo apt-get install -y lsb-release

Install swift-toolchain using shell script:

curl:

bash -c "$(curl -fsSL https://swift-toolchain.com/install.sh)"

wget:

bash -c "$(wget -qO - https://swift-toolchain.com/install.sh)"

wget2:

bash -c "$(wget2 -qO - https://swift-toolchain.com/install.sh)"

How to debugging within VSCode

Install extension: CodeLLDB

Install extension: Swift

Configurate Swift Extension:

How to use Swift-DocC

Require Swift 5.6.

To use the Swift-DocC plugin with your package, first add it as a dependency:

let package = Package(
    // name, platforms, products, etc.
    dependencies: [
        // other dependencies
        .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
    ],
    targets: [
        // targets
    ]
)

You can then invoke the plugin from the root of your repository like so:

swift package generate-documentation

Or Generating Documentation for Hosting Online:

swift package --allow-writing-to-directory doc-html \
      generate-documentation --disable-indexing \
                             --transform-for-static-hosting \
                             --output-path doc-html

doc-html is output directory path and now ready to be published online.

Transforming for Static Hosting: --transform-for-static-hosting

Host your documentation at a sub-path: --hosting-base-path [hosting-base-path]

How to Run Swift-DocC’s CLI tool (docc)

swift doc

Example:

git clone https://github.com/cntrump/slothkit.git
cd slothkit

Local preview:

swift doc preview Sources/SlothCreator/SlothCreator.docc \
                  --fallback-display-name SwiftDocC \
                  --fallback-bundle-identifier org.swift.SwiftDocC \
                  --fallback-bundle-version 1.0.0 \
                  --transform-for-static-hosting \
                  --port 8080

You should now see the following in your terminal:

Input: ~/slothkit/Sources/SlothCreator/SlothCreator.docc
Template: /opt/swift-toolchain/usr/share/docc/render
~/slothkit/Sources/SlothCreator/SlothCreator.docc/Tutorials/Creating Custom Sloths.tutorial:71:26: warning: Topic reference 'SlothCreator/Sloth' couldn't be resolved. No local documentation matches this reference.
========================================
Starting Local Preview Server
	 Address: http://localhost:8080/tutorials/slothcreator
========================================

Static hosting:

swift doc convert Sources/SlothCreator/SlothCreator.docc \
                  --fallback-display-name SwiftDocC \
                  --fallback-bundle-identifier org.swift.SwiftDocC \
                  --fallback-bundle-version 1.0.0 \
                  --transform-for-static-hosting \
                  --output-dir doc-html

Run a local http server:

$ cd doc-html
$ python3 -m http.server 8080

Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/)

Visit: http://10.211.55.32:8080/tutorials/slothcreator

More Information: Distributing Documentation to Other Developers

How to Install

sudo apt-get update
sudo apt-get install swift-toolchain

If you don’t want to install recommends: git, pkg-config, tzdata, gnupg2:

swift package manager required dependencies: git, pkg-config.

sudo apt-get --no-install-recommends install swift-toolchain

How to upgrade to latest version

Update swift-toolchain to latest version:

sudo apt-get update
sudo apt-get upgrade swift-toolchain