Skip to content

Commit 3003b08

Browse files
committed
[WindowsBuild] Update installation guide
1 parent 54d3391 commit 3003b08

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

docs/WindowsBuild.md

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -705,22 +705,24 @@ cmake -B S:\b\11 ^
705705
cmake --build S:\b\11
706706
```
707707

708-
## Gather the toolchain and SDK
708+
## Use the toolchain and SDK
709709

710-
If you want a toolchain for real-world testing, you can use CMake to perform the install step.
710+
If you want a toolchain for real-world testing, you can use CMake to perform the install step. However, the built toolchain is not expected to be distributed, mainly because there're plenty of unnecessary or local files that need to be stripped.
711711

712-
### Swift compiler and standard libraries
712+
### Swift compiler
713713

714714
```cmd
715715
cmake --build S:\b\1 --target install
716716
```
717717

718-
For testing, add the target to path:
718+
For testing, add the toolchain to path:
719719

720720
```cmd
721-
path S:\b\toolchain\usr\bin:%PATH%
721+
path S:\b\toolchain\usr\bin;%PATH%
722722
```
723723

724+
> **NOTE**: The built compiler cannot actually compile Swift files without a compatible SDK. You may need to specify `-sdk <sdk>` explicitly.
725+
724726
### Swift Windows SDK (with core libraries)
725727

726728
```cmd
@@ -730,17 +732,51 @@ cmake --build S:\b\4 --target install
730732
cmake --build S:\b\5 --target install
731733
```
732734

733-
For testing, set `%SDKROOT%` and the default runtime:
735+
Usually, you also need to bundle external libraries required by `Foundation`:
736+
737+
```cmd
738+
copy /Y S:\b\4\bin\*.dll S:\b\sdk\usr\bin
739+
```
740+
741+
For testing, set `%SDKROOT%` and add runtime libraries to path:
734742

735743
```cmd
736744
set SDKROOT=S:\b\sdk
737-
python -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'DEFAULT_USE_RUNTIME': 'MD' } }), encoding='utf-8'))" > S:\b\sdk\SDKSettings.plist
745+
path S:\b\sdk\usr\bin;%PATH%
738746
```
739747

740-
### Swift toolchain with developer tools
748+
#### Fix SDK layout
749+
750+
You may notice that the SDK is not functioning correctly. This is caused by the mismatch of expected SDK layout and the build output. Before these issues get addressed, we may need some extra workaround.
751+
752+
1. Compiler expects Swift libraries to live in `\usr\lib\swift\windows\x86_64`, but the build output is `\usr\lib\swift\windows`. This is likely to trigger `unable to load standard library for target 'x86_64-unknown-windows-msvc'` error. Fix by:
753+
754+
```cmd
755+
for /D %m in (S:\b\sdk\usr\lib\swift\windows\*.swiftmodule) do ^
756+
move /Y %m S:\b\sdk\usr\lib\swift\windows\x86_64
757+
```
758+
759+
> **NOTE(stevapple)**: The compiler convention shall be wrong here — Swift libraries can be bundled with multiple architectures, so there's no need to place them in arch-specific directory.
760+
761+
2. Compiler expects underlying modules to be imported from `\usr\include`, but the build output is `\usr\lib\swift`. This is likely to trigger `cannot load underlying module for '<Module>'` error. Fix by:
762+
763+
```cmd
764+
move /Y S:\b\sdk\usr\lib\swift\Block S:\b\sdk\usr\include
765+
move /Y S:\b\sdk\usr\lib\swift\dispatch S:\b\sdk\usr\include
766+
move /Y S:\b\sdk\usr\lib\swift\os S:\b\sdk\usr\include
767+
```
768+
769+
3. Compiler expects Swift runtime import libraries to live in `\usr\lib\swift\windows\x86_64`, but the build output is `\usr\lib\swift\windows`. This is likely to trigger `fatal error LNK1104: cannot open file '<Module>.lib'` error. Fix by:
770+
771+
```cmd
772+
move /Y S:\b\sdk\usr\lib\swift\windows\*.lib S:\b\sdk\usr\lib\swift\windows\x86_64
773+
```
774+
775+
> **NOTE(stevapple)**: The build script shall be wrong here — Swift shared libraries are closely tied to target architecture, so we should place them in arch-specific directory if Universal binary is not available.
776+
777+
### Swift developer tools
741778

742779
```cmd
743-
cmake --build S:\b\1 --target install
744780
cmake --build S:\b\6 --target install
745781
cmake --build S:\b\7\Yams --target install
746782
cmake --build S:\b\7\ArgumentParser --target install
@@ -752,18 +788,14 @@ cmake --build S:\b\8 --target install
752788
cmake --build S:\b\9 --target install
753789
cmake --build S:\b\10 --target install
754790
cmake --build S:\b\11 --target install
791+
copy /Y S:\b\8\bin\sqlite3.dll S:\b\toolchain\usr\bin
755792
```
756793

757-
To use Swift Driver in place of the old driver:
794+
To use Swift Driver in place of the old driver (default since Swift 5.7):
758795

759796
```cmd
760797
copy /Y S:\b\toolchain\usr\bin\swift-driver.exe S:\b\toolchain\usr\bin\swift.exe
761798
copy /Y S:\b\toolchain\usr\bin\swift-driver.exe S:\b\toolchain\usr\bin\swiftc.exe
762799
```
763800

764-
Add the built toolchain to `%Path%` to use directly:
765-
766-
```cmd
767-
path S:\b\toolchain\usr\bin;%Path%
768-
swift --version
769-
```
801+
You should be able to compile Swift packages without any additional steps.

0 commit comments

Comments
 (0)