CentOS-Linux-7にSwift-4をインストールしてみた（Vagrantユーザー）

<!-- CentOS-Linux-7にSwift-4をインストールしてみた（Vagrantユーザー） -->
# 環境
```shell-session
$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core) 
$ arch
x86_64
```
# 準備
## メモリ及びスワップ
ビルドの失敗要因の一つにメモリ不足がある。現在のメモリ及びスワップの上限値は`free`コマンド又はGUIのシステムモニタ等で確認できる。メモリ増設が困難である場合はスワップ領域を確保する。（目安は4GB程度）

- [Swap領域を追加する3つの方法(VirtualBox上のTiny Core Linux)](https://www.markn.org/blog/2015/02/add-swapspace.html)

## 環境変数
```shell-session
$ vim -c 'start|:set number|:$' ~/.bash_profile
```
```shell:~/.bash_profile
export SWIFT_SOURCE_ROOT=/usr/local/src/swift-4
```
を追記して[ESC]キー→`:wq`で保存・終了。
### 設定の反映
```shell-session
$ . ~/.bash_profile
```

# 第1段階 -- Swiftコンパイラ本体
## 作業ディレクトリ
```shell-session
$ cd /usr/local/src/
```
## $SWIFT_SOURCE_ROOT/ ディレクトリを生成
```shell-session
$ sudo mkdir swift-4
```
## 必須ツールのインストール
```shell-session
$ sudo yum update
$ sudo yum install libbsd-devel re2c
$ sudo yum --disablerepo=\* --enablerepo=base install wget git gcc-c++ libtool automake autoconf uuid-devel libicu-devel icu libedit-devel libxml2-devel sqlite-devel swig python-devel ncurses-libs ncurses-devel pkgconfig libuuid-devel libbsd-devel systemtap-sdt-devel epel-release
$ sudo wget --no-check-certificate -O /etc/yum.repos.d/libatomic-4.8.5-11.el7.x86_64.rpm ftp://ftp.pbone.net/mirror/ftp.centos.org/7.6.1810/os/x86_64/Packages/libatomic-4.8.5-36.el7.x86_64.rpm
$ sudo yum --disablerepo=\* --enablerepo=base install libatomic
```
### Clang-3.4.2
```shell-session
$ sudo yum --disablerepo=\* --enablerepo=epel,base install clang
$ clang --version
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: x86_64-redhat-linux-gnu
Thread model: posix
```
### CMake-3.9.0
```shell-session
$ sudo wget https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz
$ sudo tar -zxvf cmake-3.9.0.tar.gz
$ cd cmake-3.9.0
$ sudo ./bootstrap --prefix=/usr
$ sudo make
$ sudo make install
$ cmake --version
cmake version 3.9.0
$ cd ..
```
### その他
```shell-session
$ sudo vim -c 'start|:set number|:1147' /usr/include/unistd.h
```
```diff:/usr/include/unistd.h
- extern void encrypt (char *__block, int __edflag) __THROW __nonnull ((1));
+ extern void encrypt (char *__libc_block, int __edflag) __THROW __nonnull ((1));
```
1147行目を+行の通りに書き換えて、[ESC]キー→`:wq`で保存・終了。

Python3系が存在する場合、

```shell-session
$ ll /usr/local/lib/ | grep libpython3
```
でヒットしたファイル名を一旦別名に変える。
## $SWIFT_SOURCE_ROOT/ ディレクトリにアーカイブファイルをダウンロードして展開及びNinjaのインストール
```shell-session
$ cd $SWIFT_SOURCE_ROOT/
$ sudo wget https://github.com/apple/swift/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz  -P swift
$ sudo wget https://github.com/apple/swift-cmark/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz  -P cmark
$ sudo wget https://github.com/apple/swift-clang/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz -P clang
$ sudo wget https://github.com/apple/swift-llvm/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz -P llvm
$ sudo wget https://github.com/apple/swift-compiler-rt/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz -P compiler-rt
$ sudo wget https://github.com/ninja-build/ninja/archive/v1.7.2.tar.gz -P ninja
$ cd swift
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz --strip-components=1
$ cd ..
$ cd cmark
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz --strip-components=1
$ cd ..
$ cd clang
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz --strip-components=1
$ cd ..
$ cd llvm
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz --strip-components=1
$ cd ..
$ cd compiler-rt
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz --strip-components=1
$ cd ..
$ cd ninja
$ sudo tar -zxvf v1.7.2.tar.gz --strip-components=1
$ sudo ./configure.py --bootstrap
$ sudo cp ninja /usr/bin/
$ ninja --version
1.7.2
$ cd ..
```
## バージョンの確認
```shell-session
$ python --version | head -n1
Python 2.7.5
$ sqlite3 --version | head -n1
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
$ gcc --version | head -n1
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
$ clang --version | head -n1
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
$ cmake --version | head -n1
cmake version 3.9.0
$ ninja --version | head -n1
1.7.2
```
## Swiftコンパイラ等のビルド及びインストール
ビルド及びインストールには`$SWIFT_SOURCE_ROOT/swift/utils/build-script`というスクリプトファイルを用いるが、こちらは実はラッパーであり、`$SWIFT_SOURCE_ROOT/swift/utils/build-script-impl`がスクリプトの本体である。
オプション指定の際、`-- \`の前段でラッパー自身が受け取るオプションを、後段で本体に渡されるオプションを指定できる。前段（ラッパー）側のオプション詳細は`$SWIFT_SOURCE_ROOT/swift/utils/build-script -h`、後段（本体）側のオプション詳細は`$SWIFT_SOURCE_ROOT/swift/utils/build-script-impl -h`で各々確認できる。
ビルドされたファイル群の保存先は、`$SWIFT_SOURCE_ROOT/build/Ninja-ReleaseAssert/`ディレクトリである。（`-R`オプション指定及びデフォルトのNinjaの場合）

```shell-session
$ sudo $SWIFT_SOURCE_ROOT/swift/utils/build-script -R -i \
-- \
--install-destdir=/ --install-cmark --install-swift \
'--swift-install-components=compiler;clang-builtin-headers;stdlib;sdk-overlay;license'
```
`--swift-install-components`オプションに関する言及は、`$SWIFT_SOURCE_ROOT/swift/utils/build-presets.ini`にある。
## インストールの確認
```shell-session
$ cmark --version | head -n1
cmark 0.22.0 - CommonMark converter
$ swiftc --version | head -n1
Swift version 4.0-dev
$ cd
$ echo 'print("Hello, World!")' > hello-1.swift
$ swiftc ./hello-1.swift -o ./hello-1
$ ./hello-1
Hello, World!
```
# 第2段階 -- Foundation等関連ツール
## 必須ツールのインストール
### BlocksRuntime
```shell-session
$ cd $SWIFT_SOURCE_ROOT/../
$ sudo rpm -ivh http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/x86_64/RPMS.classic/libBlocksRuntime-0.3-alt3.x86_64.rpm
$ sudo rpm -ivh http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/x86_64/RPMS.classic/libBlocksRuntime-devel-0.3-alt3.x86_64.rpm
$ sudo yum update
```
- 詳細: [libBlocksRuntime-devel-0.3-alt3.x86_64.rpm](
https://altlinux.pkgs.org/sisyphus/classic-x86_64/libBlocksRuntime-devel-0.3-alt3.x86_64.rpm.html)（英語）

### SQLite-3.26.0
```shell-session
$ cd $SWIFT_SOURCE_ROOT/../
$ sudo wget 'https://www.sqlite.org/2018/sqlite-autoconf-3260000.tar.gz'
$ sudo tar -zxvf sqlite-autoconf-3260000.tar.gz
$ cd sqlite-autoconf-3260000/
$ sudo ./configure --prefix=/usr/local/sqlite/3.26.0/
$ sudo make
$ sudo make install
$ /usr/local/sqlite/3.26.0/bin/sqlite3 --version
3.26.0 2018-12-01 12:34:55 bf8c1b2b7a5960c282e543b9c293686dccff272512d08865f4600fb58238b4f9
$ sudo sh -c "echo /usr/local/sqlite/3.26.0/lib > /etc/ld.so.conf.d/sqlite.conf"
```
### cURL-7.63.0
```shell-session
$ cd $SWIFT_SOURCE_ROOT/../
$ sudo wget https://curl.haxx.se/download/curl-7.63.0.tar.gz
$ sudo tar -zxvf curl-7.63.0.tar.gz
$ cd curl-7.63.0
$ sudo ./configure --enable-libcuswsrl-option
$ sudo make
$ sudo make install
$ curl --version
curl 7.63.0 (x86_64-pc-linux-gnu) libcurl/7.63.0 zlib/1.2.7
Release-Date: 2018-12-12
Protocols: dict file ftp gopher http imap pop3 rtsp smtp telnet tftp 
Features: AsynchDNS IPv6 Largefile libz UnixSockets
```
### Clang-4.0.0
```shell-session
$ cd $SWIFT_SOURCE_ROOT/build/Ninja-ReleaseAssert/llvm-linux-x86_64/
$ sudo ninja install
$ clang --version
clang version 4.0.0 
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
## $SWIFT_SOURCE_ROOT/ ディレクトリにアーカイブファイルをダウンロードして展開
```shell-session
$ cd $SWIFT_SOURCE_ROOT/
$ sudo wget https://github.com/unicode-org/icu/archive/release-59-1.tar.gz -P icu
$ sudo wget https://github.com/apple/swift-lldb/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz -P lldb
$ sudo wget https://github.com/apple/swift-corelibs-foundation/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz -P swift-corelibs-foundation
$ sudo wget https://github.com/apple/swift-corelibs-xctest/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz -P swift-corelibs-xctest
$ sudo wget https://github.com/apple/swift-package-manager/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz -P swiftpm
$ sudo wget https://github.com/apple/swift-llbuild/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz -P llbuild
$ sudo wget https://github.com/apvaple/swift-corelibs-libdispatch/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz -P swift-corelibs-libdispatch
$ cd icu
$ sudo tar -zxvf release-59-1.tar.gz icu-release-59-1/icu4c/* --strip-components=2
$ cd ..
$ cd lldb
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-29-a.tar.gz --strip-components=1
$ cd ..
$ cd swift-corelibs-foundation
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz --strip-components=1
$ cd ..
$ cd swift-corelibs-xctest
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz --strip-components=1
$ cd ..
$ cd swiftpm
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz --strip-components=1
$ cd ..
$ cd llbuild
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz --strip-components=1
$ cd ..
$ cd swift-corelibs-libdispatch
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz --strip-components=1
$ cd ..
```
## バージョンの確認
```shell-session
$ /usr/local/sqlite/3.26.0/bin/sqlite3 --version | head -n1
3.26.0 2018-12-01 12:34:55 bf8c1b2b7a5960c282e543b9c293686dccff272512d08865f4600fb58238b4f9
$ curl --version | head -n1
curl 7.63.0 (x86_64-pc-linux-gnu) libcurl/7.63.0 zlib/1.2.7
$ clang --version | head -n1
clang version 4.0.0
```
## コンパイラ本体附属ツールのビルド及びインストール
```shell-session
$ sudo $SWIFT_SOURCE_ROOT/swift/utils/build-script -R -i \
--llbuild --libdispatch \
-- \
--skip-build-cmark --skip-build-llvm --skip-build-swift \
--install-destdir=/ --install-llbuild --install-libdispatch
$ sudo $SWIFT_SOURCE_ROOT/swift/utils/build-script -R -i \
--libicu --lldb \
-- \
--skip-build-cmark --skip-build-llvm --skip-build-swift \
--install-destdir=/ --install-libicu
$ sudo $SWIFT_SOURCE_ROOT/swift/utils/build-script -R -i \
--foundation --xctest \
-- \
--skip-build-cmark --skip-build-llvm --skip-build-swift \
--install-destdir=/ --install-foundation --install-xctest
$ sudo $SWIFT_SOURCE_ROOT/swift/utils/build-script -R -i \
--xctest --llbuild --swiftpm \
-- \
--skip-build-cmark --skip-build-llvm \
--install-destdir=/ --install-swiftpm
```
- lldb: 今回はビルドのみ。インストールは後で行う。
- swiftpm: `--xctest`と`--llbuild`は既にビルド・インストール済みであるが、
`--swiftpm`のビルドの際はこれらを添えないといけない。同時に、コンパイラのビルド回避（`--skip-build-swift`）はしてはいけない。

## コンパイラ本体直属ツールのビルド及びインストール
```shell-session
$ sudo rm -rf $SWIFT_SOURCE_ROOT/build/Ninja-ReleaseAssert/swift-linux-x86_64/
$ sudo $SWIFT_SOURCE_ROOT/swift/utils/build-script -R -i \
--build-swift-dynamic-stdlib --build-swift-static-stdlib \
--build-swift-dynamic-sdk-overlay --build-swift-static-sdk-overlay \
--build-swift-stdlib-unittest-extra \
'--extra-cmake-options=-DSWIFT_BUILD_SOURCEKIT:BOOL=TRUE' \
-- \
--skip-build-cmark --skip-build-llvm \
--install-destdir=/ --install-swift \
'--swift-install-components=autolink-driver;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;sdk-overlay;editor-integration;tools;testsuite-tools;toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers'
```
- ビルド及びインストール前に予め`$SWIFT_SOURCE_ROOT/build/Ninja-ReleaseAssert/swift-linux-x86_64/`ディレクトリの削除を要する。

## LLDBのインストール
別窓（タブ又はウィンドウ）を開き、

```shell-session
$ sudo vim -c 'start|:set number|:36' $SWIFT_SOURCE_ROOT/build/Ninja-ReleaseAssert/lldb-linux-x86_64/scripts/cmake_install.cmake
```
```diff:$SWIFT_SOURCE_ROOT/build/Ninja-ReleaseAssert/lldb-linux-x86_64/scripts/cmake_install.cmake
- file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" TYPE DIRECTORY FILES "/usr/local/src/swift-4/build/Ninja-ReleaseAssert/lldb-linux-x86_64/lib/python2.7")
+ file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/lib64" TYPE DIRECTORY FILES "/usr/local/src/swift-4/build/Ninja-ReleaseAssert/lldb-linux-x86_64/lib64/python2.7")
```
36行目を+行の通りに書き換え、[ESC]キー→`:w`で保存（終了はしない）。

本窓に戻り、

```shell-session
$ cd $SWIFT_SOURCE_ROOT/build/Ninja-ReleaseAssert/lldb-linux-x86_64/
$ sudo ninja install
```
別窓に行き、もう一度、[ESC]キー→`:w`で保存（終了はしない）。本窓の様子を見て、インストール完了を確認したら[ESC]キー→`:q`で終了。別窓を閉じる。
## インストールの確認
```shell-session
$ cd
$ vim -c 'start|:set number' ./hello-2.swift
```
```swift:~/hello-2.swift
import Foundation
let s1: NSString = "Hello, World!"
let s2: String = String(describing: s1)
print(s2)
```
上記の様に書き込み、[ESC]キー→`:wq`で保存・終了。

```shell-session
$ swiftc ./hello-2.swift -o ./hello-2
$ ./hello-2
Hello, World!
```
- [VimでSwiftのSyntax Highlight](https://qiita.com/shotat/items/7302f937ae623ccc154a)

#第3段階 -- PlaygroundLogger
## 必須ツールのインストール
```shell-session
$ sudo yum install python2-pip.noarch
$ sudo pip install --upgrade pip
$ pip2 --version
pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
$ sudo pip2 install colorama
$ pip2 list | grep colorama
colorama                         0.4.1
```
## $SWIFT_SOURCE_ROOT/ ディレクトリにアーカイブファイルをダウンロードして展開
```shell-session
$ cd $SWIFT_SOURCE_ROOT/
$ sudo wget https://github.com/apple/swift-xcode-playground-support/archive/swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz -P swift-xcode-playground-support
$ cd swift-xcode-playground-support
$ sudo tar -zxvf swift-DEVELOPMENT-SNAPSHOT-2017-07-30-a.tar.gz --strip-components=1
```
## ファイルの書き換え
-行を+行に書き換えて行く。`vim`は[ESC]キー→`:wq`で保存・終了。

```shell-session
$ sudo vim -c 'start|:set number|:22' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/Woodchuck.swift
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/Woodchuck.swift
- return f.string(from: self as Date)
+ return f.string(from: Date.init(timeIntervalSinceReferenceDate: self.timeIntervalSinceReferenceDate))
```
```shell-session
$ sudo vim -c 'start|:set number|:32' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/PlaygroundLogPrint.swift
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/PlaygroundLogPrint.swift
- let logdata = playground_log_impl(string.bridge(), "", range)
+ let logdata = playground_log_impl(String(describing: string), "", range)
```
```shell-session
$ sudo vim -c 'start|:set number|:111' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/KeyedArchiver.swift
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/KeyedArchiver.swift
- return .Buffer(data as Data)
+ return .Buffer(Data(referencing: data))
```
```shell-session
$ sudo vim -c 'start|:set number|:69' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/QuickLookEncodedObject.swift
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/QuickLookEncodedObject.swift
- self = .Success(QuickLookEncodedObject(r,.Buffer(d as Data)))
+ self = .Success(QuickLookEncodedObject(r,.Buffer(Data(referencing: d))))
```
```shell-session
$ sudo vim -c 'start|:set number|:21' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/KeyedUnarchiver.swift
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/KeyedUnarchiver.swift
- unarchiver = NSKeyedUnarchiver(forReadingWith: NSData(bytes: storage.bytes + storage.index, length: storage.count - storage.index) as Data)
+ unarchiver = NSKeyedUnarchiver(forReadingWithData: Data(referencing: NSData(bytes: storage.bytes + storage.index, length: storage.count - storage.index)))
```
```shell-session
$ sudo vim -c 'start|:set number|:28' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/ThreadLocalStorage.swift
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/ThreadLocalStorage.swift
- if let index = dict.indexForKey(key) {
+ if let index = dict.index(forKey: String(describing: key)) {
```
```shell-session
$ sudo vim -c 'start|:set number|:35' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/ThreadLocalStorage.swift
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/ThreadLocalStorage.swift
- Thread.current.threadDictionary[key] = value
+ Thread.current.threadDictionary[String(describing: key)] = value
```
```shell-session
$ sudo vim -c 'start|:set number|:57' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/BytesStream.swift
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/PlaygroundLogger/BytesStream.swift
- return write(d as Data)
+ return write(Data(referencing: d))
```
```shell-session
$ sudo vim -c 'start|:set number|:436' $SWIFT_SOURCE_ROOT/swift/utils/build-script-impl
```
```diff:$SWIFT_SOURCE_ROOT/swift/utils/build-script-impl
- playgroundlogger_build_options=(
-     --swiftc "$(build_directory_bin ${host} swift)"
+ playgroundlogger_build_options=("--module-install-path "$(get_host_install_destdir ${host})$(get_host_install_prefix ${host})"/lib/swift/${SWIFT_HOST_VARIANT}/${SWIFT_HOST_VARIANT_ARCH} --library-install-path "$(get_host_install_destdir ${host})$(get_host_install_prefix ${host})"/lib/swift/${SWIFT_HOST_VARIANT}
+     --swiftc "$(which swiftc)"
```
```shell-session
$ sudo vim -c 'start|:set number|:442' $SWIFT_SOURCE_ROOT/swift/utils/build-script-impl
```
```diff:$SWIFT_SOURCE_ROOT/swift/utils/build-script-impl
- )
+ ")
```
```shell-session
$ sudo vim -c 'start|:set number|:2541' $SWIFT_SOURCE_ROOT/swift/utils/build-script-impl
```
```diff:$SWIFT_SOURCE_ROOT/swift/utils/build-script-impl
- "${playgroundlogger_build_cmd}" -configuration "${PLAYGROUNDLOGGER_BUILD_TYPE}" -target "${playgroundlogger_build_target}" install SWIFT_EXEC="${SWIFTC_BIN}" DSTROOT=${build_dir} INSTALL_PATH="/" SKIP_INSTALL=NO
+ "${playgroundlogger_build_cmd}" $(echo "${playgroundlogger_build_options}" | xargs)
```
```shell-session
$ sudo vim -c 'start|:set number|:2867' $SWIFT_SOURCE_ROOT/swift/utils/build-script-impl
```
```diff:$SWIFT_SOURCE_ROOT/swift/utils/build-script-impl
- SWIFT_DYLIB_PATH=$(build_directory ${host} swift)/lib/swift/macosx/
+ if [[ "${SKIP_TEST_PLAYGROUNDLOGGER}" ]]; then continue; fi; SWIFT_DYLIB_PATH=$(build_directory ${host} swift)/lib/swift/macosx/
```
```shell-session
$ sudo vim -c 'start|:set number|:264' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/build.py
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/build.py
- command = 'clang "%s" "%s" -shared @"%s" -o "%s" -L "%s" -Wl,--no-undefined -Wl-soname,lib%s.so -L "%s" -lswiftCore -lFoundation -lswiftStdlibUnittest -lswiftGlibc -Xlinker -T "%s"' % \
+ command = '/usr/bin/clang++ -fPIC -DPIC -nostdlib -lbsd -lpthread -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtendS.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o -momit-leaf-frame-pointer -O2 -fuse-ld=gold "%s" "%s" -shared @"%s" -o "%s" -L "%s" -Wl,--no-undefined -Wl-soname,lib%s.so -L "%s" -lswiftCore -lFoundation -lswiftStdlibUnittest -lswiftGlibc' % \
```
```shell-session
$ sudo vim -c 'start|:set number|:269' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/build.py
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/build.py
-  self.settings.foundation,
-  PROJECT_NAME,
-  os.path.join(self.settings.swiftBuildDir,'lib','swift','linux'),
-  os.path.join(self.settings.swiftBuildDir,'lib','swift','linux','x86_64','swift.ld'))
+  os.path.join(self.settings.foundation,'Foundation'),
+  PROJECT_NAME,
+  os.path.join(self.settings.swiftBuildDir,'lib','swift','linux')
+ )
```
```shell-session
sudo vim -c 'start|:set number|:396' $SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/build.py
```
```diff:$SWIFT_SOURCE_ROOT/swift-xcode-playground-support/PlaygroundLogger/build.py
- TARGETS.append(BuildTestDriver)
- TARGETS.append(RunTestDriver)
+ # TARGETS.append(BuildTestDriver)
+ # TARGETS.append(RunTestDriver)
```
##バージョンの確認
```shell-session
$ pip2 list | grep colorama
colorama                         0.4.1
```
## PlaygroundLoggerのビルド及びインストール
```shell-session
$ sudo $SWIFT_SOURCE_ROOT/swift/utils/build-script -R -i \
--playgroundlogger \
-- \
--skip-build-cmark --skip-build-llvm --skip-build-swift \
--install-destdir=/ --install-playgroundlogger \
--playgroundlogger-build-type=Release
```
## インストールの確認
```shell-session
$ swift
1> import PlaygroundLogger
2> :quit
```
# 参考リンク
- [CentOS 7.2でSwift 4.0 をコンパイルしてインストールしてみてください](https://codingjp.com/ios/2861/): プログラマーのフロントライン
- [Compile Swift 4.0-dev on CentOS7.2](https://blog.csdn.net/XiaoAiWhc/article/details/77865148): XiaoAiWhc的专栏 - CSDN博客（中国語）
- [CentOS 7.2 に swift 2.2 を install してみた](http://tsome.blog69.fc2.com/blog-entry-15.html): 煮えるプログラマの腸
- [centos-release-7-2.1511.el7.centos.2.10.x86_64でswift-3.0-preview-1をビルドする](https://shiroikagami.blogspot.com/2016/06/centos-release-7-21511el7centos210x8664.html): 白い鏡