環境構築のメモがてら書いていきます。
実際に作業してみる
https://swift.org/download/#using-downloads の手順を踏んでいきます。
ツールのインストール
$ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install clang libicu-dev $ sudo apt-get install libpython2.7 $ sudo apt-get install libxml2 $ sudo apt-get install libcurl3
Swiftをダウンロード
Ubuntu16.04向けSwift4.0.3をダウンロードしていきます。
$ wget https://swift.org/builds/swift-4.0.3-release/ubuntu1604/swift-4.0.3-RELEASE/swift-4.0.3-RELEASE-ubuntu16.04.tar.gz $ wget https://swift.org/builds/swift-4.0.3-release/ubuntu1604/swift-4.0.3-RELEASE/swift-4.0.3-RELEASE-ubuntu16.04.tar.gz.sig $ wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - $ gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift $ gpg --verify swift-4.0.3-RELEASE-ubuntu16.04.tar.gz.sig
Swiftをインストール
UbuntuにSwiftとPerfectLibをインストールする · GitHubの記事を参考にインストールします。
$ tar xzf swift-4.0.3-RELEASE-ubuntu16.04.tar.gz $ cd swift-4.0.3-RELEASE-ubuntu16.04 $ sudo chown -R root:root usr/ $ cd usr $ sudo cp -fR ./* /usr/ $ sudo chmod a+r /usr/lib/swift/CoreFoundation/
Swiftの実行
$ swift -version
これでSwiftのバージョンが表示されればインストール完了です。
詰まったところ
上記までのコードで以下のエラーの解決策は含まれています。
そもそも動かん
$ swift /usr/bin/lldb: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
libpython2.7をインストールすることで解決
$ sudo apt-get install libpython2.7
と思ったらまたしてもエラー
$ swift /usr/bin/lldb: error while loading shared libraries: libxml2.so.2: cannot open shared object file: No such file or directory
こちらもlibxml2をインストールすることで解決
$ sudo apt-get install libxml2
実行時にエラーが発生する
https://bugs.swift.org/browse/SR-2783で解決
コンパイルの時に必要なヘッダーファイルへのアクセス権がないことが原因の模様
$ sudo chmod a+r /usr/lib/swift/CoreFoundation/
Swift Packageでエラー
$ swift package init --type executable /usr/bin/swift-package: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory
Electron apps can't find libcurl.so.4 · Issue #8853 · electron/electron · GitHubで解決
libcurlをインストール
$ sudo apt-get install libcurl3
おわりに
まだまだわからないことも多いオープンソース版Swiftですが、せっかくなのでPerfectやVaporなどのサーバーサイドSwiftをやっていこうかなと思っています。