[swift-dev] How to run Swift on Windows
Kazuki Ohara
kazuki.ohara at gmail.com
Mon Dec 18 11:00:31 CST 2017
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 at gmail.com>:
> On 12/14/17, Kazuki Ohara via swift-dev <swift-dev at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171219/4b3bf69e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm.patch
Type: application/octet-stream
Size: 4091 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171219/4b3bf69e/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swift.patch
Type: application/octet-stream
Size: 14976 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171219/4b3bf69e/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang.patch
Type: application/octet-stream
Size: 1906 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171219/4b3bf69e/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compiler-rt.patch
Type: application/octet-stream
Size: 9418 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171219/4b3bf69e/attachment-0003.obj>
More information about the swift-dev
mailing list