IBMがSwift WebフレームワークKituraを公開したので、さっそくUbuntuにインストールしてみました。
現在Swift.orgで対応しているLinuxは、Ubuntu 15.10 と 14.04だけですが、14.04は↓と同様の問題が出ていてビルドが通らなかったため、15.10にて確認しました。
https://lists.swift.org/pipermail/swift-corelibs-dev/Week-of-Mon-20160111/000331.html
両方とも問題ありませんね。(2/8リリース版のSwiftで確認。)
2/26 追記
Kituraがv0.2.0からv0.3.0になって、手順が少しかわりました。
Installation (Linux)
手順に従ってインストールしていきます。
0. クリーンナップ
v0.2.0環境を構築していたら、古いライブラリとインクルードを削除しておきます。
$ sudo rm /usr/local/lib/libdispatch.*
$ sudo rm -r /usr/local/include/dispatch
$ sudo rm -r /usr/local/include/os
1. 必須ライブラリインストール
$ sudo apt-get install libhttp-parser-dev libcurl4-openssl-dev libhiredis-dev
2. Swift compiler for Linux
最新版をインストールします。PATHも通しておきます。以下は編集時点での最新バージョンです。
$ export PATH=/path/to/usr/bin:"${PATH}"
$ swift --version
Swift version 3.0-dev (LLVM a7663bb722, Clang 4ca3c7fa28, Swift 1c2f40e246)
Target: x86_64-unknown-linux-gnu
3. libdispatchライブラリ取得
パッチライブラリではなく、appleアカウントから取得するように変更になりました。
$ git clone -b opaque-pointer https://github.com/seabaylea/swift-corelibs-libdispatch
$ git clone https://github.com/apple/swift-corelibs-libdispatch.git
4. libdispatchライブラリのビルド&インストール
こちらを参考にしてビルド&インストールします。
$ sudo apt-get install clang
$ sudo apt-get install autoconf libtool pkg-config
$ sudo apt-get install systemtap-sdt-dev
$ sudo apt-get install libblocksruntime-dev libkqueue-dev libbsd-dev
$ cd swift-corelibs-libdispatch && git submodule init && git submodule update && sh ./autogen.sh && ./configure --with-swift-toolchain=<path-to-swift>/usr --prefix=<path-to-swift>/usr && make && sudo make install
ビルドしたライブラリは<path-to-swift>/usr/lib/swift/linuxの下に落ちるようになります。
6 5. PCRE2コンパイル&インストール
ここからダウンロード&解凍後、makeします。
pcre2-10.20$ ./configure && make && sudo make install
7 6. Kitura依存パッケージのダウンロード KituraとKituraSampleのビルド
Kituraのリポジトリ直下でmakeすると、swift buildも実行されます。旧環境で実施していた場合は、適宜gitをpullしたり、swift build --cleanでクリーンナップしてから実行します。
$ git clone https://github.com/IBM-Swift/Kitura
$ cd Kitura
Kitura$ make
swift build
Cloning https://github.com/IBM-Swift/Kitura-router.git
Using version 0.2.0 of package Kitura-router
Cloning https://github.com/IBM-Swift/Kitura-net.git
Using version 0.2.0 of package Kitura-net
Cloning https://github.com/IBM-Swift/Kitura-sys.git
Using version 0.2.1 of package Kitura-sys
Cloning https://github.com/IBM-Swift/LoggerAPI.git
Using version 0.2.0 of package LoggerAPI
Cloning https://github.com/IBM-Swift/BlueSocket.git
Using version 0.0.4 of package BlueSocket
Cloning https://github.com/IBM-Swift/Kitura-CurlHelpers.git
Using version 0.2.0 of package Kitura-CurlHelpers
Cloning https://github.com/IBM-Swift/Kitura-HttpParserHelper.git
Using version 0.2.0 of package Kitura-HttpParserHelper
Cloning https://github.com/IBM-Swift/Kitura-Pcre2.git
Using version 0.2.0 of package Kitura-Pcre2
Cloning https://github.com/IBM-Swift/SwiftyJSON.git
Using version 3.1.0 of package SwiftyJSON
Cloning https://github.com/IBM-Swift/HeliumLogger.git
Using version 0.2.0 of package HeliumLogger
Cloning https://github.com/IBM-Swift/Kitura-TestFramework.git
Using version 0.2.0 of package Kitura-TestFramework
...
Compiling Swift Module 'KituraSys' (4 sources)
<unknown>:0: error: module 'Dispatch' requires feature 'blocks'
<unknown>:0: error: could not build Objective-C module 'Dispatch'
<unknown>:0: error: module 'Dispatch' requires feature 'blocks'
<unknown>:0: error: could not build Objective-C module 'Dispatch'
<unknown>:0: error: module 'Dispatch' requires feature 'blocks'
<unknown>:0: error: could not build Objective-C module 'Dispatch'
<unknown>:0: error: module 'Dispatch' requires feature 'blocks'
<unknown>:0: error: could not build Objective-C module 'Dispatch'
<unknown>:0: error: build had 1 command failures
error: exit(1): ["/home/tatsu/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a-ubuntu15.10/usr/bin/swift-build-tool", "-f", "/home/tatsu/Projects/Kitura/Kitura/.build/debug/Kitura-Sys.o/llbuild.yaml"]
Makefile:21: recipe for target 'make' failed
make: [make] Error 1 (ignored)
...
Linking Library: .build/debug/XCTest.a
Compiling Swift Module 'KituraSample' (1 sources)
Linking Executable: .build/debug/KituraSample
make[1]: Leaving directory '/home/tatsu/Projects/Kitura/Kitura'
ビルドプロセスは失敗に終わって構わないようです。 途中KituraSysモジュールのコンパイルでerrorを吐き出しますが、ビルドは最後まで通ります。
9 7. ダイナミックライブラリのパス設定
$ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
PCRE2ライブラリは依然としてこちらに落ちてますので、パス設定は要です。
10 8. サンプルプログラム実行
Kituraプロジェクト内のサンプルサーバーを起動します。
Kitura$ ./.build/debug/KituraSample
http://localhost:8090/ を開いて、"You're running Kitura"と表示されれば成功です。
Build End-to-End Cloud Apps using Swift with Kitura
続いて、こちらのチュートリアルにでてくるKitura-TodoListもインストールしてみました。
$ git clone https://github.com/IBM-Swift/Kitura-TodoList.git
$ cd Kitura-TodoList/
Kitura-TodoList$ swift build
Cloning https://github.com/IBM-Swift/Kitura-router.git
Using version 0.3.2 of package Kitura-router
Cloning https://github.com/IBM-Swift/Kitura-net.git
Using version 0.3.1 of package Kitura-net
Cloning https://github.com/IBM-Swift/Kitura-sys.git
Using version 0.3.0 of package Kitura-sys
Cloning https://github.com/IBM-Swift/LoggerAPI.git
Using version 0.2.0 of package LoggerAPI
Cloning https://github.com/IBM-Swift/BlueSocket.git
Using version 0.0.4 of package BlueSocket
Cloning https://github.com/IBM-Swift/Kitura-CurlHelpers.git
Using version 0.2.0 of package Kitura-CurlHelpers
Cloning https://github.com/IBM-Swift/Kitura-HttpParserHelper.git
Using version 0.2.0 of package Kitura-HttpParserHelper
Cloning https://github.com/IBM-Swift/Kitura-Pcre2.git
Using version 0.2.0 of package Kitura-Pcre2
Cloning https://github.com/IBM-Swift/SwiftyJSON.git
Using version 3.1.0 of package SwiftyJSON
Cloning https://github.com/IBM-Swift/HeliumLogger.git
Using version 0.0.4 of package HeliumLogger
...
Compiling Swift Module 'KituraSys' (4 sources)
<unknown>:0: error: module 'Dispatch' requires feature 'blocks'
<unknown>:0: error: could not build Objective-C module 'Dispatch'
<unknown>:0: error: module 'Dispatch' requires feature 'blocks'
<unknown>:0: error: could not build Objective-C module 'Dispatch'
<unknown>:0: error: module 'Dispatch' requires feature 'blocks'
<unknown>:0: error: could not build Objective-C module 'Dispatch'
<unknown>:0: error: module 'Dispatch' requires feature 'blocks'
<unknown>:0: error: could not build Objective-C module 'Dispatch'
<unknown>:0: error: build had 1 command failures
error: exit(1): ["/home/tatsu/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a-ubuntu15.10/usr/bin/swift-build-tool", "-f", "/home/tatsu/Projects/Kitura/Kitura-TodoList/.build/debug/Kitura-Sys.o/llbuild.yaml"]
Kitura-TodoList$ make
...
Linking Library: .build/debug/KituraRouter.a
Compiling Swift Module 'HeliumLogger' (1 sources)
Linking Library: .build/debug/HeliumLogger.a
Compiling Swift Module 'LoggerSample' (1 sources)
Linking Executable: .build/debug/LoggerSample
Compiling Swift Module 'TodoList' (5 sources)
Linking Executable: .build/debug/TodoList
make[1]: Leaving directory '/home/tatsu/Projects/Kitura/Kitura-TodoList'
こちらもswift buildコマンドは失敗に終わってますが、とりあえず問題ありません。途中KituraSysモジュールのコンパイルでerrorを吐き出しますが、ビルドは最後まで通ります。
TodoListサーバーを起動します。
Kitura-TodoList$ ./.build/debug/TodoList
http://localhost:8090/ にアクセスするとJSONが返ってきます。
[
{
"id": "0",
"url": "http://localhost:8090/todos/0",
"order": 0,
"title": "Reticulate splines",
"completed": false
},
{
"id": "1",
"url": "http://localhost:8090/todos/1",
"order": 1,
"title": "Herd llamas",
"completed": false
}
]
このデータをTodoBackendウェブページに食わせてやるときれいに表示してくれます。
http://www.todobackend.com/client/index.html?http://localhost:8090
追加・更新・削除も実装済みのようですね。