Skip to content

toulouse/windows-swift

 
 

Repository files navigation

Swift on Windows (& more)

Table of Contents

Getting Started

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.

Minimal Hello World (CMake)

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".

"Configure this Project" dialog

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".

CMake Kit selection

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.

"Always Configure" dialog

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".

"Open" dialog "Open" dialog 2

Once you do so, you should see CMakeLists.txt, hello.swift, hikit.swift, and, if you chose "For this Workspace", a .vscode directory.

File listing

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).

CMake toolbar

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

Hello World program

Congratulations! You've built and run your first Swift program with swift-build-configuration!

Windows

See documentation here

Status

Windows Toolchains

Provider Build Status
Facebook x64 (VS2017) Build Status
Microsoft x64 (VS2017) Build Status
Microsoft x64 (VS2019) Build Status
Microsoft ARM64 (VS2019) Build Status

Linux Toolchains

Provider Build Status
FlowKey x64 (Ubuntu 18.04) Build Status

macOS Toolchains

Provider Build Status
Microsoft x64 (mojave) Build Status

SDKs

Build Status
Windows SDK (ARM/ARM64/X64/X86) Build Status
Android SDK (ARM/ARM64/X64/X86) Build Status
Linux SDK (X64) Build Status

Developer Tools

Build Status
Linux (llbuild, tools-support-core) (X64) Build Status

Dependencies

Build Status
ICU Build Status
XML2 Build Status
CURL Build Status
SQLite3 Build Status
ZLIB Build Status

MSIs

Build Status
Windows x64 (VS2017) Toolchain Build Status
Windows x64 (VS2019) Toolchain Build Status

deb Packages

Build Status
Linux x64 (Ubuntu 18.04) Toolchain Build Status
Linux Swift SDK (Ubuntu 18.04) Build Status
Android Swift SDK (Ubuntu 18.04) Build Status
Windows Swift SDK (Ubuntu 18.04) Build Status

docker images

Build Status
Ubuntu 18.04 VSCode Build Status

Releases

No releases published

Packages

No packages published

Languages

  • CMake 79.0%
  • Makefile 6.3%
  • PowerShell 5.8%
  • Dockerfile 5.0%
  • Python 3.5%
  • Shell 0.4%