Getting started is as simple as running a command from your shell:
$ docker run --rm --publish 127.0.0.1:8080:8080 --volume $HOME/projects/myproject:/SourceCache/myproject --volume $HOME/projects/bin/myproject:/BinaryCache/myproject compnerd/swift:latest
- The docker image doesn't require persistent state, so we use
--rm
to automatically clean up and remove the container when it exits. - Visual Studio Code is exposed over a web interface on port 8080. We publish this port via
--publish 127.0.0.1:8080:8080
*. --volume $HOME/projects/myproject:/SourceCache/myproject
and--volume $HOME/projects/bin/myproject:/BinaryCache/myproject
mount your source tree for "myproject" into the docker image as a subdirectory of/SourceCache
and the directory for compiled output into it as/BinaryCache
.compnerd/swift
references the latest tag on Docker Hub.
* If you'd like to access this from anywhere other than localhost, you can replace this with --publish 0.0.0.0:8080:8080
, but no authentication or HTTPS are configured, so doing this with no additional configuration will be insecure.
First, clone the examples repository:
$ git clone https://github.com/compnerd/swift-windows-examples.git
Next, make a directory for the binary output (remember to substitute your own path!):
$ mkdir -p $HOME/bin/HelloMinimal-CMake
Next start up the build environment:
$ docker run --rm --publish 127.0.0.1:8080:8080 --volume /path/to/swift-windows-examples/HelloMinimal-CMake:/SourceCache/HelloMinimal-CMake --volume $HOME/bin/HelloMinimal-CMake:/BinaryCache/HelloMinimal-CMake compnerd/swift:latest
Navigate to localhost in your browser: http://127.0.0.1:8080/. Or, if you want to open a workspace directly, you can provide a path: http://localhost:8080/?folder=/SourceCache/HelloMinimal-CMake
Visual Studio Code will prompt you to configure your project with CMake - choose "Yes".
You will be offered a selection of CMake Kits. This dictates the target system that this session will build. For this example, select "Linux x86_64".
You may be asked whether Visual Studio Code should always configure CMake projects upon opening. You can choose either "Yes" or "For this Workspace"; all this does is add a setting to .vscode/settings.json
. Because we run a fresh image on each run of the docker container, You will need to click "Yes" on each new run of the container, or "For this Workspace" to do so automatically your current workspace. Note that you will still have to select your desired CMake Kit on each startup.
If you did not open Visual Studio Code with the "folder" URL parameter, click File -> Open... to do so and choose /SourceCache/HelloMinimal-CMake
. By default, /SourceCache
will be opened, but this will not necessarily set up a working CMake project in a subdirectory. Hit "Enter".
Once you do so, you should see CMakeLists.txt
, hello.swift
, hikit.swift
, and, if you chose "For this Workspace", a .vscode
directory.
At the bottom of the screen, your toolbar will have CMake information. Ensure that the "Linux x86_64" kit is selected, and click the "Build:" button (in the future, if you want to rebuild only specific CMake targets, you can click "[all]" and select them specifically).
Your program is now compiled; now let's test it out. Open a shell with "Ctrl-`" (Ctrl-Backtick), and run it with:
$ /BinaryCache/HelloMinimal-CMake/Debug/hello
Congratulations! You've built and run your first Swift program with swift-build-configuration!
See documentation here
Windows Toolchains
Provider | Build | Status |
---|---|---|
x64 (VS2017) | ||
Microsoft | x64 (VS2017) | |
Microsoft | x64 (VS2019) | |
Microsoft | ARM64 (VS2019) |
Linux Toolchains
Provider | Build | Status |
---|---|---|
FlowKey | x64 (Ubuntu 18.04) |
macOS Toolchains
Provider | Build | Status |
---|---|---|
Microsoft | x64 (mojave) |
SDKs
Build | Status |
---|---|
Windows SDK (ARM/ARM64/X64/X86) | |
Android SDK (ARM/ARM64/X64/X86) | |
Linux SDK (X64) |
Developer Tools
Build | Status |
---|---|
Linux (llbuild, tools-support-core) (X64) |
Dependencies
Build | Status |
---|---|
ICU | |
XML2 | |
CURL | |
SQLite3 | |
ZLIB |
MSIs
Build | Status |
---|---|
Windows x64 (VS2017) Toolchain | |
Windows x64 (VS2019) Toolchain |
deb Packages
Build | Status |
---|---|
Linux x64 (Ubuntu 18.04) Toolchain | |
Linux Swift SDK (Ubuntu 18.04) | |
Android Swift SDK (Ubuntu 18.04) | |
Windows Swift SDK (Ubuntu 18.04) |
docker images
Build | Status |
---|---|
Ubuntu 18.04 VSCode |