|
| 1 | +# Getting Started with Swift on Windows |
| 2 | + |
| 3 | +## MSVC |
| 4 | +To be filled in. |
| 5 | + |
| 6 | +## Windows Subsystem for Linux (WSL) |
| 7 | +- Note that all compiled Swift binaries are only executable within Bash on Windows and are Ubunutu, not Windows, executables. |
| 8 | +- Make sure to run all commands from Bash, or the project won't compile. |
| 9 | + |
| 10 | +### 1. Install WSL |
| 11 | +Install and run the latest version of [Bash on Ubuntu on Windows](https://msdn.microsoft.com/en-gb/commandline/wsl/about) installed on your PC. |
| 12 | +``` |
| 13 | +bash |
| 14 | +``` |
| 15 | + |
| 16 | +### 2. Install dependencies |
| 17 | +Install the developer dependencies needed to compile the Swift project. These are identical to the Ubuntu dependencies, with the addition of `make`. |
| 18 | +```bash |
| 19 | +sudo apt-get install git make cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev |
| 20 | +``` |
| 21 | + |
| 22 | +### 3. Upgrade clang |
| 23 | +Install a version of clang with C++ 14 support - the default version of clang on WSL results in linker errors during compilation. |
| 24 | +```bash |
| 25 | +sudo apt-get install clang-3.6 |
| 26 | +sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 |
| 27 | +sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 |
| 28 | +``` |
| 29 | + |
| 30 | +### 4. Upgrade CMake |
| 31 | +Install the latest version of CMake - Swift uses new CMake features such as `IN_LIST` and won't build without these features. |
| 32 | +```bash |
| 33 | +wget http://www.cmake.org/files/v3.5/cmake-3.6.2.tar.gz |
| 34 | +tar xf cmake-3.6.2.tar.gz |
| 35 | +cd cmake-3.6.2 |
| 36 | +./configure |
| 37 | +make |
| 38 | +sudo make install |
| 39 | +sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force |
| 40 | +cmake --version # This should print 3.6.2 |
| 41 | +``` |
| 42 | + |
| 43 | +### 6. Clone and build the Swift project |
| 44 | +```bash |
| 45 | +mkdir swift-source |
| 46 | +cd swift-source |
| 47 | +git clone https://github.com/apple/swift.git |
| 48 | +./swift/utils/update-checkout --clone |
| 49 | +./swift/utils/build-script -r |
| 50 | +``` |
| 51 | +### 7. Hello, Windows (Subsystem for Linux) |
| 52 | +```bash |
| 53 | +cd ./build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bin # This path may depend on your build configuration |
| 54 | +echo 'print("Hello, Windows")' >> test.swift |
| 55 | +swiftc test.swift |
| 56 | +./test # Hello, Windows |
| 57 | +``` |
0 commit comments