LoginSignup
199
197

More than 5 years have passed since last update.

オープンソースになったSwiftをビルドしてみる

Last updated at Posted at 2015-12-04

Swiftがついにオープンソース化されました!自分も何か pull request 送って「Swiftコントリビュータ」を名乗りたいところですが、言語のソースコードを前にしたところでいったい何からはじめてよいものかわからない、けど気分だけでもこの祭りに乗っかりたい、ということでとりあえずビルドしてみることにしました。

README をみると Getting Started のところに色々書いてあります。が、Ubuntuだけで必要な手順とかも混じっているので、OS X でビルドするための最短距離 を探ってみました。

色々試してみて、Swift をビルドするにあたって clone が必須なのは以下のリポジトリ。

$ git clone git@github.com:apple/swift.git swift
$ git clone git@github.com:apple/swift-clang.git clang
$ git clone git@github.com:apple/swift-llvm.git llvm
$ git clone git@github.com:martine/ninja.git

(clang, llvm, ninja は入れてないとビルドスクリプト実行時におこられる)

Ninja というのはビルドシステムの一種のようです。

Ninja is the current recommended build system for building Swift and is the default configuration generated by CMake

clone してきたら、あとは swift リポジトリにあるビルドスクリプトを実行するだけ。

$ swift/utils/build-script

だいたい30分弱(MBP Retina, 15-inch, Mid2014)でビルドが完了しました。お昼休みとかに走らせておくとちょうどいいかもしれません。

完了すると以下に各種 libswift{フレームワーク名}.dylib ファイルが生成されてました。

build/Ninja-DebugAssert/swift-macosx-x86_64/lib/swift/macosx

build/Ninja-DebugAssert/swift-macosx-x86_64/lib/swift/iphoneos フォルダとかもできてたのですが空だったので、iOS向けにビルドするにはスクリプトのオプションを指定しないといけないのかもしれません。

$ swift/utils/build-script -h

でビルドスクリプトのヘルプが見れるのですが、

usage: build-script [-h] [-l] [-b] [-p] [--xctest] [--foundation] [-c]
                    [-d | -r | -R] [--debug-llvm] [--debug-swift]
                    [--debug-swift-stdlib] [--debug-lldb] [--debug-cmark]
                    [--debug-foundation] [--assertions | --no-assertions]
                    [--cmark-assertions] [--llvm-assertions]
                    [--no-llvm-assertions] [--swift-assertions]
                    [--no-swift-assertions] [--swift-stdlib-assertions]
                    [--no-swift-stdlib-assertions] [--lldb-assertions]
                    [--no-lldb-assertions] [-x] [-X] [-m] [-e] [-t] [-T] [-o]
                    [-S] [-i] [--tvos] [--watchos] [--build-subdir PATH]
                    [--extra-swift-args EXTRA_SWIFT_ARGS]
                    [build_script_impl_args [build_script_impl_args ...]]

と、 --tvos--watchos といったオプションもあります。

iOS はどこかなーとヘルプを読み進めると、

  -i, --ios             also build for iOS, but disallow tests that require an
                        iOS device

ということで -i もしくは --ios でいけるようです。

上記の通り簡単なのでぜひお試しあれ!

199
197
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
199
197