<div dir="ltr"><div>Hi Eric,</div><div><br></div><div>> Do you mind elaborating on how you got it built with MSVC?</div><div><br></div><div>Sure. I succeeded to build LLVM, clang and Swift compiler with the tag of swift-4.0.2-RELEASE.<br>LLVM and clang seem to work okay and Swift compiler can compile swift sources but the generated exectables crash.</div><div>Here's my procedure. This is based on <a href="https://github.com/apple/swift/blob/master/docs/Windows.md">https://github.com/apple/swift/blob/master/docs/Windows.md</a>.</div><div><br></div><div># Prerequisite</div><div><br></div><div>* Visaul Stduio 2017<br>* CMake<br>* ninja<br>* Python 2.7 (not Python 3)<br>* Git for Windows<br>Append Cmake, ninja, Python 2.7 and git to your PATH.<br></div><div><br></div><div>I assume your working direcotry is C:\swift.</div><div><br></div><div># ICU</div><div><br></div><div>Download <a href="http://download.icu-project.org/files/icu4c/60.2/icu4c-60_2-src.zip">http://download.icu-project.org/files/icu4c/60.2/icu4c-60_2-src.zip</a> and extract to C:\swift\icu.<br>Open C:\swift\icu\source\allinone.sln with Visual Studio.<br>This file is for Visaul Stduio 2015, so we need convert the project files to use Visual Studio 2017's toolchian.<br>Right click 'allinone' solution in Solution Explorer and select 'Re-target the solution'. <br>(I'm not using the English version of Visual Stduio, so the actual representation may differ.)<br>Then change the configuration to Release, x64 and build it.</div><div><br></div><div># Checkout sources</div><div><br></div><div>Open x64 Native Tools Command Prompt of Visual Studio 2017, checkout the repositories and apply the attached patches with this mail.</div><div><br></div><div>VsDevCmd -arch=amd64<br>set swift_source_dir=c:\swift<br>cd \<br>mkdir swift<br>cd swift</div><div><br></div><div>git clone <a href="https://github.com/apple/swift-cmark.git">https://github.com/apple/swift-cmark.git</a><br>mv swift-cmark cmark<br>git checkout swift-4.0.2-RELEASE<br>cd ..</div><div><br></div><div>git clone <a href="https://github.com/apple/swift.git">https://github.com/apple/swift.git</a><br>cd swift<br>git checkout swift-4.0.2-RELEASE<br>patch -p1 < swift.patch<br>cd ..</div><div><br></div><div>git clone <a href="https://github.com/apple/swift-clang.git">https://github.com/apple/swift-clang.git</a><br>move swift-clang clang<br>cd clang<br>git checkout swift-4.0.2-RELEASE<br>patch -p1 < clang.patch<br>cd ..</div><div><br></div><div>git clone <a href="https://github.com/apple/swift-compiler-rt.git">https://github.com/apple/swift-compiler-rt.git</a><br>move swift-compiler-rt compiler-rt<br>cd compiler-rt<br>git checkout swift-4.0.2-RELEASE<br>patch -p1 < compiler-rt.patch<br>cd ..</div><div><br></div><div>git clone <a href="https://github.com/apple/swift-llvm.git">https://github.com/apple/swift-llvm.git</a><br>move swift-llvm llvm<br>cd llvm<br>git checkout swift-4.0.2-RELEASE<br>patch -p1 < llvm.patch<br>cd ..</div><div><br></div><div>mklink /J "%swift_source_dir%/llvm/tools/clang" "%swift_source_dir%/clang"<br>mklink /J "%swift_source_dir%/llvm/tools/compiler-rt" "%swift_source_dir%/compiler-rt"</div><div><br></div><div># Build cmark</div><div><br></div><div>mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64"<br>pushd "%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64"<br>cmake -G "Ninja" -DCMAKE_BUILD_TYPE=RelWithDebInfo "%swift_source_dir%/cmark"<br>popd<br>cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64/" -- -v</div><div><br></div><div># Build LLVM/clang/compiler-rt</div><div><br></div><div>mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"<br>pushd "%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"<br>cmake -G "Ninja"^<br> -DCMAKE_BUILD_TYPE=RelWithDebInfo^<br> -DLLVM_ENABLE_ASSERTIONS=TRUE^<br> -DLLVM_TOOL_COMPILER_RT_BUILD=TRUE^<br> -DLLVM_BUILD_EXTERNAL_COMPILER_RT=TRUE^<br> -DCMAKE_C_FLAGS="/bigobj /DCRT_HAS_128BIT"^<br> -DCMAKE_CXX_FLAGS="/bigobj /DCRT_HAS_128BIT" ^<br> "%swift_source_dir%/llvm"<br>popd<br>cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64" -- -v</div><div><br></div><div># Build swift</div><div><br></div><div>xcopy /s /i "%VCToolsInstallDir%\include" "%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\visualc"<br>copy "%swift_source_dir%\swift\stdlib\public\Platform\visualc.modulemap" "%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\visualc\module.modulemap"<br>xcopy /s /i "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt" "%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\ucrt"<br>copy "%swift_source_dir%\swift\stdlib\public\Platform\ucrt.modulemap" "%swift_source_dir%\build\Ninja-RelWithDebInfo\modules\ucrt\module.modulemap"</div><div><br></div><div>mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfo/swift-windows-amd64"<br>pushd "%swift_source_dir%/build/Ninja-RelWithDebInfo/swift-windows-amd64"<br>cmake -G "Ninja"^<br> -DCMAKE_BUILD_TYPE=RelWithDebInfo^<br> -DCMAKE_C_COMPILER="%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64/bin/clang-cl.exe"^<br> -DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 /Z7"^<br> -DCMAKE_CXX_COMPILER="%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64/bin/clang-cl.exe"^<br> -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 /Z7"^<br> -DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER=FALSE^<br> -DSWIFT_INCLUDE_DOCS=FALSE^<br> -DSWIFT_INCLUDE_TESTS=FALSE^<br> -DSWIFT_PATH_TO_CMARK_SOURCE="%swift_source_dir%/cmark"^<br> -DSWIFT_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64"^<br> -DSWIFT_CMARK_LIBRARY_DIR="%swift_source_dir%/build/Ninja-RelWithDebInfo/cmark-windows-amd64/src"^<br> -DSWIFT_PATH_TO_LLVM_SOURCE="%swift_source_dir%/llvm"^<br> -DSWIFT_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"^<br> -DSWIFT_PATH_TO_CLANG_SOURCE="%swift_source_dir%/llvm/tools/clang"^<br> -DSWIFT_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfo/llvm-windows-amd64"^<br> -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"^<br> -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"^<br> -DICU_UC_LIB_NAME="icuuc"^<br> -DICU_UC_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^<br> -DICU_UC_INCLUDE_DIRS="%swift_source_dir%/icu/include"^<br> -DICU_I18N_LIB_NAME="icuin"^<br> -DICU_I18N_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^<br> -DICU_I18N_INCLUDE_DIRS="%swift_source_dir%/icu/include"^<br> "%swift_source_dir%/swift"<br>popd<br>cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfo/swift-windows-amd64" -- -v</div><div><br></div><div>I hope your success!</div><div><br></div><div>Kazuki<br></div><div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-12-18 10:18 GMT+09:00 Eric Wing <span dir="ltr"><<a href="mailto:ewmailing@gmail.com" target="_blank">ewmailing@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 12/14/17, Kazuki Ohara via swift-dev <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>> wrote:<br>
> Hi,<br>
><br>
> I'm interested in running Swift on Windows.<br>
><br>
> I found the document to build the Swift compiler for Windows (<br>
> <a href="https://github.com/apple/swift/blob/master/docs/Windows.md" target="_blank" rel="noreferrer">https://github.com/apple/<wbr>swift/blob/master/docs/<wbr>Windows.md</a>) and tried it.<br>
> I managed to build it with MSVC, but the resulting compiler could not<br>
> generate executables run properly.<br>
> (The executables seem to crash during initializing Swift's runtime<br>
> systems.)<br>
><br>
> Are there someone who can build the compiler works properly on Windows with<br>
> master branch or at least 4.x branches?<br>
> I found <a href="https://github.com/tinysun212/swift-windows" target="_blank" rel="noreferrer">https://github.com/tinysun212/<wbr>swift-windows</a>, but this seems to be<br>
> on 3.x branch.<br>
><br>
> Thank you,<br>
> Kazuki Ohara<br>
><br>
<br>
Do you mind elaborating on how you got it built with MSVC? I posted<br>
like a month ago to the Swift list that I was unable to even get past<br>
building the LLVM stage due to compile errors.<br>
<br>
Thanks,<br>
Eric<br>
</blockquote></div><br></div>