A helper utility to manage the development environment on Windows.
Using Swift on Windows requires some additional environment variables and files to be deployed. This tool helps automate those tasks to make it easier to develop using Swift on Windows. With this tool, you no longer need worry about getting the correct shell or environment variable
Using this tool to deploy the module maps is far more convenient since it uses the Windows Shell infrastructure to copy the files into the correct location. It uses the standard Windows security mechanisms for requesting elevated privileges via UAC and ensuring that file replacement is done correctly.
One time setup:
:: Copy the module maps for using the Windows SDK and UCRT, in case they haven't been deployed yet.
> swift devenv --deployNormal usage:
:: Setup the environment variables
> swift devenv
:: Build the project
> swift buildThe Windows SDK and the Microsoft C library (UCRT) require modulemaps to be able to use the libraries from Swift. These files indicate how the headers map to Swift. The operation needs to be done each time the toolchain is updated. This requires copying a few files into the Windows SDK installation. swift-devenv can identify the Windows SDK installation and copy the files into the correct location in an automated fashion.
:: Identify the Windows SDK location that the files will be copied to
> swift devenv --list-sdks
Detected Windows 10 SDK: C:\Program Files (x86)\Windows Kits\10\
Detected Windows 10 SDK Versions:
- 10.0.19041.0The --deploy option to devenv will deploy the necessary files from the toolchain installation. It uses the SDKROOT environment variable to determine the location of the module maps and copies the winsdk.modulemap and ucrt.modulemap to their respective locations.
> swift devenv --deployThe Swift compiler uses the INCLUDE and LIB environment variables to identify the default header (include) search path and the linker library search paths for interoperability with the system. These environment variables are ;-delimited lists of paths where the headers are. The tool will identify the Windows SDK installation and construct the approriate values for these variables.
:: Setup the development environment
> swift devenvThe default action of devenv is to set the environment variables as that is the most common operation.
NOTE devenv will launch a new shell, identified by %COMSPEC%. This is required as the process cannot modify the environment of the parent process.
The default include path contains, in order, the following components:
ucrt- the C library headersshared- the shared user mode and kernel mode headers from the Windows SDKum- the user mode only headers from the Windows SDKwinrt- the Windows Runtime headerscppwinrt- the Windows Runtime C++ Projection headers
The default library search path contains, in order, the following components:
ucrt- the C libraryum- the user mode libraries
Multiple versions of the SDK can be installed in parallel. However, only a single version of the SDK can be used at a time. You can inspect the detected versions of the SDKs and the install root that swift-devenv sees.
> swift devenv --list-sdks
Detected Windows 10 SDK: C:\Program Files (x86)\Windows Kits\10\
Detected Windows 10 SDK Versions:
- 10.0.19041.0swift-devenv is written in Swift and uses the Swift package manager to build.
- The latest Swift Snapshot build (for swift-package-manager)
- Windows SDK 10.0.107763 or newer
:: build using swift package manager
> swift buildInstallation of swift-devenv simply involves copying the generated binary to your toolchain root.
> copy .build\x86_64-unknown-windows-msvc\*\swift-devenv.exe %DEVELOPER_DIR%\Toolchains\*.xctoolchain\usr\bin