How to run Swift on Windows

Hi,

I'm interested in running Swift on Windows.

I found the document to build the Swift compiler for Windows (
https://github.com/apple/swift/blob/master/docs/Windows.md) and tried it.
I managed to build it with MSVC, but the resulting compiler could not
generate executables run properly.
(The executables seem to crash during initializing Swift's runtime systems.)

Are there someone who can build the compiler works properly on Windows with
master branch or at least 4.x branches?
I found https://github.com/tinysun212/swift-windows, but this seems to be
on 3.x branch.

Thank you,
Kazuki Ohara

Do you mind elaborating on how you got it built with MSVC? I posted
like a month ago to the Swift list that I was unable to even get past
building the LLVM stage due to compile errors.

Thanks,
Eric

···

On 12/14/17, Kazuki Ohara via swift-dev <swift-dev@swift.org> wrote:

Hi,

I'm interested in running Swift on Windows.

I found the document to build the Swift compiler for Windows (
https://github.com/apple/swift/blob/master/docs/Windows.md) and tried it.
I managed to build it with MSVC, but the resulting compiler could not
generate executables run properly.
(The executables seem to crash during initializing Swift's runtime
systems.)

Are there someone who can build the compiler works properly on Windows with
master branch or at least 4.x branches?
I found https://github.com/tinysun212/swift-windows, but this seems to be
on 3.x branch.

Thank you,
Kazuki Ohara

Hi, Phil

I will look into the project.

Thank you,
Kazuki

···

2017-12-18 3:38 GMT+09:00 Phil J. Łaszkowicz <noreply@forums.swift.org>:

siilime <http://forums.swift.org/u/siilime> Phil J. Łaszkowicz
<http://forums.swift.org/u/siilime>
December 17

That project has now included support for Swift 4.

Officially you’re simply not going to get anything useful at this stage
regarding comments on Windows support. Without official support from the
project, the likely end-result of the product will be non-optimal, which is
often regarded as worse than non-existent.

Currently, even though Swift 4 has now been added for Windows, and there’s
continuous updates on that project, it still lacks the support to keep it
in closer sync to the official trunk, (it’s currently 11692 commits behind).

But as far as experimenting with it, you have your Swift 4 support!

For the MinGW-w64 system, swift-4.0-branch (up to 4.0.3-RELEASE) is merged
into
https://github.com/tinysun212/swift-windows/commits/swift-windows-4.0-branch
and
it is successfully compiled.

If I make the Foundation module work to some extent, I will share the
binary and submit a PR for the compiler.

···

2017-12-18 10:18 GMT+09:00 Eric Wing via swift-dev <swift-dev@swift.org>:

On 12/14/17, Kazuki Ohara via swift-dev <swift-dev@swift.org> wrote:
> Hi,
>
> I'm interested in running Swift on Windows.
>
> I found the document to build the Swift compiler for Windows (
> https://github.com/apple/swift/blob/master/docs/Windows.md) and tried
it.
> I managed to build it with MSVC, but the resulting compiler could not
> generate executables run properly.
> (The executables seem to crash during initializing Swift's runtime
> systems.)
>
> Are there someone who can build the compiler works properly on Windows
with
> master branch or at least 4.x branches?
> I found https://github.com/tinysun212/swift-windows, but this seems to
be
> on 3.x branch.
>
> Thank you,
> Kazuki Ohara
>

Do you mind elaborating on how you got it built with MSVC? I posted
like a month ago to the Swift list that I was unable to even get past
building the LLVM stage due to compile errors.

Thanks,
Eric
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Hi Eric,

Do you mind elaborating on how you got it built with MSVC?

Sure. I succeeded to build LLVM, clang and Swift compiler with the tag of
swift-4.0.2-RELEASE.
LLVM and clang seem to work okay and Swift compiler can compile swift
sources but the generated exectables crash.
Here's my procedure. This is based on
https://github.com/apple/swift/blob/master/docs/Windows.md.

# Prerequisite

* Visaul Stduio 2017
* CMake
* ninja
* Python 2.7 (not Python 3)
* Git for Windows
Append Cmake, ninja, Python 2.7 and git to your PATH.

I assume your working direcotry is C:\swift.

# ICU

Download http://download.icu-project.org/files/icu4c/60.2/icu4c-60_2-src.zip
and extract to C:\swift\icu.
Open C:\swift\icu\source\allinone.sln with Visual Studio.
This file is for Visaul Stduio 2015, so we need convert the project files
to use Visual Studio 2017's toolchian.
Right click 'allinone' solution in Solution Explorer and select 'Re-target
the solution'.
(I'm not using the English version of Visual Stduio, so the actual
representation may differ.)
Then change the configuration to Release, x64 and build it.

# Checkout sources

Open x64 Native Tools Command Prompt of Visual Studio 2017, checkout the
repositories and apply the attached patches with this mail.

VsDevCmd -arch=amd64
set swift_source_dir=c:\swift
cd \
mkdir swift
cd swift

git clone https://github.com/apple/swift-cmark.git
mv swift-cmark cmark
git checkout swift-4.0.2-RELEASE
cd ..

git clone https://github.com/apple/swift.git
cd swift
git checkout swift-4.0.2-RELEASE
patch -p1 < swift.patch
cd ..

git clone https://github.com/apple/swift-clang.git
move swift-clang clang
cd clang
git checkout swift-4.0.2-RELEASE
patch -p1 < clang.patch
cd ..

git clone https://github.com/apple/swift-compiler-rt.git
move swift-compiler-rt compiler-rt
cd compiler-rt
git checkout swift-4.0.2-RELEASE
patch -p1 < compiler-rt.patch
cd ..

git clone https://github.com/apple/swift-llvm.git
move swift-llvm llvm
cd llvm
git checkout swift-4.0.2-RELEASE
patch -p1 < llvm.patch
cd ..

mklink /J "%swift_source_dir%/llvm/tools/clang" "%swift_source_dir%/clang"
mklink /J "%swift_source_dir%/llvm/tools/compiler-rt"
"%swift_source_dir%/compiler-rt"

# Build cmark

mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64"
pushd "%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64"
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=RelWithDebInfo
"%swift_source_dir%/cmark"
popd
cmake --build
"%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64/" -- -v

# Build LLVM/clang/compiler-rt

mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"
pushd "%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"
cmake -G "Ninja"^
-DCMAKE_BUILD_TYPE=RelWithDebInfo^
-DLLVM_ENABLE_ASSERTIONS=TRUE^
-DLLVM_TOOL_COMPILER_RT_BUILD=TRUE^
-DLLVM_BUILD_EXTERNAL_COMPILER_RT=TRUE^
-DCMAKE_C_FLAGS="/bigobj /DCRT_HAS_128BIT"^
-DCMAKE_CXX_FLAGS="/bigobj /DCRT_HAS_128BIT" ^
"%swift_source_dir%/llvm"
popd
cmake --build
"%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64" -- -v

# Build swift

xcopy /s /i "%VCToolsInstallDir%\include"
"%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\visualc"
copy "%swift_source_dir%\swift\stdlib\public\Platform\visualc.modulemap"
"%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\visualc\module.modulemap"
xcopy /s /i "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt"
"%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\ucrt"
copy "%swift_source_dir%\swift\stdlib\public\Platform\ucrt.modulemap"
"%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\ucrt\module.modulemap"

mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfo/swift-windows-amd64"
pushd "%swift_source_dir%/build/Ninja-RelWithDebInfo/swift-windows-amd64"
cmake -G "Ninja"^
-DCMAKE_BUILD_TYPE=RelWithDebInfo^
-DCMAKE_C_COMPILER="%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64/bin/clang-cl.exe"^
-DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 /Z7"^
-DCMAKE_CXX_COMPILER="%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64/bin/clang-cl.exe"^
-DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 /Z7"^
-DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER=FALSE^
-DSWIFT_INCLUDE_DOCS=FALSE^
-DSWIFT_INCLUDE_TESTS=FALSE^
-DSWIFT_PATH_TO_CMARK_SOURCE="%swift_source_dir%/cmark"^
-DSWIFT_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64"^
-DSWIFT_CMARK_LIBRARY_DIR="%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64/src"^
-DSWIFT_PATH_TO_LLVM_SOURCE="%swift_source_dir%/llvm"^
-DSWIFT_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"^
-DSWIFT_PATH_TO_CLANG_SOURCE="%swift_source_dir%/llvm/tools/clang"^
-DSWIFT_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"^
-DSWIFT_RUNTIME_SWIFT_LINK_FLAGS="%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64/lib/clang/4.0.0/lib/windows/clang_rt.builtins-x86_64.lib"^
-DSWIFT_EXPERIMENTAL_EXTRA_REGEXP_FLAGS="(MSVCRT|SwiftPrivateLibcExtras);-I%swift_source_dir%/build/Ninja-RelWithDebInfo/modules/visualc;(MSVCRT|SwiftPrivateLibcExtras);-I%swift_source_dir%/build/Ninja-RelWithDebInfo/modules/ucrt"^
-DICU_UC_LIB_NAME="icuuc"^
-DICU_UC_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
-DICU_UC_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
-DICU_I18N_LIB_NAME="icuin"^
-DICU_I18N_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
-DICU_I18N_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
"%swift_source_dir%/swift"
popd
cmake --build
"%swift_source_dir%/build/Ninja-RelWithDebInfo/swift-windows-amd64" -- -v

I hope your success!

Kazuki

llvm.patch (4 KB)

swift.patch (14.6 KB)

clang.patch (1.86 KB)

compiler-rt.patch (9.2 KB)

···

2017-12-18 10:18 GMT+09:00 Eric Wing <ewmailing@gmail.com>:

On 12/14/17, Kazuki Ohara via swift-dev <swift-dev@swift.org> wrote:
> Hi,
>
> I'm interested in running Swift on Windows.
>
> I found the document to build the Swift compiler for Windows (
> https://github.com/apple/swift/blob/master/docs/Windows.md) and tried
it.
> I managed to build it with MSVC, but the resulting compiler could not
> generate executables run properly.
> (The executables seem to crash during initializing Swift's runtime
> systems.)
>
> Are there someone who can build the compiler works properly on Windows
with
> master branch or at least 4.x branches?
> I found https://github.com/tinysun212/swift-windows, but this seems to
be
> on 3.x branch.
>
> Thank you,
> Kazuki Ohara
>

Do you mind elaborating on how you got it built with MSVC? I posted
like a month ago to the Swift list that I was unable to even get past
building the LLVM stage due to compile errors.

Thanks,
Eric

Hi Sangjin,

Thank you!
I will check https://github.com/tinysun212/swift-windows/commits/swift-
windows-4.0-branch

···

2017-12-18 14:18 GMT+09:00 Sangjin Han via swift-dev <swift-dev@swift.org>:

For the MinGW-w64 system, swift-4.0-branch (up to 4.0.3-RELEASE) is merged
into https://github.com/tinysun212/swift-windows/commits/swift-
windows-4.0-branch and it is successfully compiled.

If I make the Foundation module work to some extent, I will share the
binary and submit a PR for the compiler.

2017-12-18 10:18 GMT+09:00 Eric Wing via swift-dev <swift-dev@swift.org>:

On 12/14/17, Kazuki Ohara via swift-dev <swift-dev@swift.org> wrote:
> Hi,
>
> I'm interested in running Swift on Windows.
>
> I found the document to build the Swift compiler for Windows (
> https://github.com/apple/swift/blob/master/docs/Windows.md) and tried
it.
> I managed to build it with MSVC, but the resulting compiler could not
> generate executables run properly.
> (The executables seem to crash during initializing Swift's runtime
> systems.)
>
> Are there someone who can build the compiler works properly on Windows
with
> master branch or at least 4.x branches?
> I found https://github.com/tinysun212/swift-windows, but this seems to
be
> on 3.x branch.
>
> Thank you,
> Kazuki Ohara
>

Do you mind elaborating on how you got it built with MSVC? I posted
like a month ago to the Swift list that I was unable to even get past
building the LLVM stage due to compile errors.

Thanks,
Eric
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

There was small mistake.
Wrong: set swift_source_dir=c:\swift
Correct: set swift_source_dir=c:/swift

Thanks,
Kazuki

···

2017-12-19 2:00 GMT+09:00 Kazuki Ohara via swift-dev <swift-dev@swift.org>:

Hi Eric,

> Do you mind elaborating on how you got it built with MSVC?

Sure. I succeeded to build LLVM, clang and Swift compiler with the tag of
swift-4.0.2-RELEASE.
LLVM and clang seem to work okay and Swift compiler can compile swift
sources but the generated exectables crash.
Here's my procedure. This is based on https://github.com/apple/
swift/blob/master/docs/Windows.md.

# Prerequisite

* Visaul Stduio 2017
* CMake
* ninja
* Python 2.7 (not Python 3)
* Git for Windows
Append Cmake, ninja, Python 2.7 and git to your PATH.

I assume your working direcotry is C:\swift.

# ICU

Download http://download.icu-project.org/files/icu4c/60.2/icu4c-60_
2-src.zip and extract to C:\swift\icu.
Open C:\swift\icu\source\allinone.sln with Visual Studio.
This file is for Visaul Stduio 2015, so we need convert the project files
to use Visual Studio 2017's toolchian.
Right click 'allinone' solution in Solution Explorer and select 'Re-target
the solution'.
(I'm not using the English version of Visual Stduio, so the actual
representation may differ.)
Then change the configuration to Release, x64 and build it.

# Checkout sources

Open x64 Native Tools Command Prompt of Visual Studio 2017, checkout the
repositories and apply the attached patches with this mail.

VsDevCmd -arch=amd64
set swift_source_dir=c:\swift
cd \
mkdir swift
cd swift

git clone https://github.com/apple/swift-cmark.git
mv swift-cmark cmark
git checkout swift-4.0.2-RELEASE
cd ..

git clone https://github.com/apple/swift.git
cd swift
git checkout swift-4.0.2-RELEASE
patch -p1 < swift.patch
cd ..

git clone https://github.com/apple/swift-clang.git
move swift-clang clang
cd clang
git checkout swift-4.0.2-RELEASE
patch -p1 < clang.patch
cd ..

git clone https://github.com/apple/swift-compiler-rt.git
move swift-compiler-rt compiler-rt
cd compiler-rt
git checkout swift-4.0.2-RELEASE
patch -p1 < compiler-rt.patch
cd ..

git clone https://github.com/apple/swift-llvm.git
move swift-llvm llvm
cd llvm
git checkout swift-4.0.2-RELEASE
patch -p1 < llvm.patch
cd ..

mklink /J "%swift_source_dir%/llvm/tools/clang" "%swift_source_dir%/clang"
mklink /J "%swift_source_dir%/llvm/tools/compiler-rt"
"%swift_source_dir%/compiler-rt"

# Build cmark

mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64"
pushd "%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64"
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=RelWithDebInfo
"%swift_source_dir%/cmark"
popd
cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64/"
-- -v

# Build LLVM/clang/compiler-rt

mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"
pushd "%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"
cmake -G "Ninja"^
-DCMAKE_BUILD_TYPE=RelWithDebInfo^
-DLLVM_ENABLE_ASSERTIONS=TRUE^
-DLLVM_TOOL_COMPILER_RT_BUILD=TRUE^
-DLLVM_BUILD_EXTERNAL_COMPILER_RT=TRUE^
-DCMAKE_C_FLAGS="/bigobj /DCRT_HAS_128BIT"^
-DCMAKE_CXX_FLAGS="/bigobj /DCRT_HAS_128BIT" ^
"%swift_source_dir%/llvm"
popd
cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"
-- -v

# Build swift

xcopy /s /i "%VCToolsInstallDir%\include" "%swift_source_dir%\build\
Ninja-RelWithDebInfo\modules\visualc"
copy "%swift_source_dir%\swift\stdlib\public\Platform\visualc.modulemap"
"%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\
visualc\module.modulemap"
xcopy /s /i "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt"
"%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\ucrt"
copy "%swift_source_dir%\swift\stdlib\public\Platform\ucrt.modulemap"
"%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\
ucrt\module.modulemap"

mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfo/swift-windows-amd64"
pushd "%swift_source_dir%/build/Ninja-RelWithDebInfo/swift-windows-amd64"
cmake -G "Ninja"^
-DCMAKE_BUILD_TYPE=RelWithDebInfo^
-DCMAKE_C_COMPILER="%swift_source_dir%/build/Ninja-
RelWithDebInfo/llvm-windows-amd64/bin/clang-cl.exe"^
-DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 /Z7"^
-DCMAKE_CXX_COMPILER="%swift_source_dir%/build/Ninja-
RelWithDebInfo/llvm-windows-amd64/bin/clang-cl.exe"^
-DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 /Z7"^
-DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER=FALSE^
-DSWIFT_INCLUDE_DOCS=FALSE^
-DSWIFT_INCLUDE_TESTS=FALSE^
-DSWIFT_PATH_TO_CMARK_SOURCE="%swift_source_dir%/cmark"^
-DSWIFT_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/
Ninja-RelWithDebInfo/cmark-windows-amd64"^
-DSWIFT_CMARK_LIBRARY_DIR="%swift_source_dir%/build/Ninja-
RelWithDebInfo/cmark-windows-amd64/src"^
-DSWIFT_PATH_TO_LLVM_SOURCE="%swift_source_dir%/llvm"^
-DSWIFT_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-
RelWithDebInfo/llvm-windows-amd64"^
-DSWIFT_PATH_TO_CLANG_SOURCE="%swift_source_dir%/llvm/tools/clang"^
-DSWIFT_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/
Ninja-RelWithDebInfo/llvm-windows-amd64"^
-DSWIFT_RUNTIME_SWIFT_LINK_FLAGS="%swift_source_dir%/
build/Ninja-RelWithDebInfo/llvm-windows-amd64/lib/clang/
4.0.0/lib/windows/clang_rt.builtins-x86_64.lib"^
-DSWIFT_EXPERIMENTAL_EXTRA_REGEXP_FLAGS="(MSVCRT|
SwiftPrivateLibcExtras);-I%swift_source_dir%/build/Ninja-
RelWithDebInfo/modules/visualc;(MSVCRT|SwiftPrivateLibcExtras);-I%
swift_source_dir%/build/Ninja-RelWithDebInfo/modules/ucrt"^
-DICU_UC_LIB_NAME="icuuc"^
-DICU_UC_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
-DICU_UC_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
-DICU_I18N_LIB_NAME="icuin"^
-DICU_I18N_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
-DICU_I18N_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
"%swift_source_dir%/swift"
popd
cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfo/swift-windows-amd64"
-- -v

I hope your success!

Kazuki

2017-12-18 10:18 GMT+09:00 Eric Wing <ewmailing@gmail.com>:

On 12/14/17, Kazuki Ohara via swift-dev <swift-dev@swift.org> wrote:
> Hi,
>
> I'm interested in running Swift on Windows.
>
> I found the document to build the Swift compiler for Windows (
> https://github.com/apple/swift/blob/master/docs/Windows.md) and tried
it.
> I managed to build it with MSVC, but the resulting compiler could not
> generate executables run properly.
> (The executables seem to crash during initializing Swift's runtime
> systems.)
>
> Are there someone who can build the compiler works properly on Windows
with
> master branch or at least 4.x branches?
> I found https://github.com/tinysun212/swift-windows, but this seems to
be
> on 3.x branch.
>
> Thank you,
> Kazuki Ohara
>

Do you mind elaborating on how you got it built with MSVC? I posted
like a month ago to the Swift list that I was unable to even get past
building the LLVM stage due to compile errors.

Thanks,
Eric

_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

git clone https://github.com/apple/swift.git
cd swift
git checkout swift-4.0.2-RELEASE
patch -p1 < swift.patch
cd ..

I'm having trouble applying the patches. I think it is due to the
Windows line endings. Is there an easy way to work around this to
apply the patches?

Hi Eric,

Did you try git config --global core.autocrlf true ?
https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

It appends CR+LF to end of all lines when you checkout source files.

···

2017-12-21 9:06 GMT+09:00 Eric Wing <ewmailing@gmail.com>:

>
> git clone https://github.com/apple/swift.git
> cd swift
> git checkout swift-4.0.2-RELEASE
> patch -p1 < swift.patch
> cd ..

I'm having trouble applying the patches. I think it is due to the
Windows line endings. Is there an easy way to work around this to
apply the patches?