Note that all compiled Swift binaries are only executable within Bash on Windows and are Ubunutu, not Windows, executables.
Make sure to run all commands from Bash, or the project won't compile.
If you have any comments, feedback or questions, tweet me @bellamy_hugh.
Setup your box
- Install Windows Subsystem for Linux here and restart your PC.
- Follow the instructions for setting up Bash on Windows.
- Install the developer dependencies needed to compile the Swift project.
sudo apt-get install git 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
- Install a version of clang with C++ 14 support - the default version of clang on WSL results in linker errors during compilation.
sudo apt-get install clang-3.6
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
- Install the latest version of CMake - the version of CMake on WSL is too old and cannot compile the Swift project. This may take up to 30 minutes.
tar xf cmake-3.5.2.tar.gz
sudo make install
sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force
cmake --version # This should print 3.5.2
Get the code
- Open a command prompt in the directory where you want to contain the swift project.
- Create a directory to contain the swift project and its dependencies. This may take up to 5 minutes.
- Clone the Swift source code. This may take up to 15 minutes.
git clone https://github.com/apple/swift.git
Build the code
- Compile the Swift compiler and standard library - this takes between 30 minutes and 2 hours depending on your PC.
Compile some Swift code!
- Navigate to the built Swift binaries. This may depend on your build configuration.
- Create a file with some Swift code. This can be done from the command line in WSL or from Explorer in Windows.
- Compile the Swift code from WSL.
- Run the Swift binary!