Windows Nightlies

windows

(Saleem Abdulrasool) #61

You launched the "native x86" Developer command prompt rather than the "native x64" Developer Command Prompt. Running vsdevcmd -arch=x64 -no_logo should put you into the right state. @RMJay, happy to take MRs for improving the getting started doc btw ;-)


#62

Thank you :pray: @compnerd for working on this. I’ll be keeping an eye on this and see if I can aid in anyway.


(Stefan Springer) #63

Thank you for your efforts. The instructions on https://dev.azure.com/compnerd/windows-swift could be somehow a little better for someone who is not an expert in those toolchain issues.

E.g. I do not know what those paths %UniversalCRTSdkDir% and %VCToolsInstallDir% are, I suppose (my paths):

%UniversalCRTSdkDir%\Include%UCRTVersion%:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0

%VCToolsInstallDir%\include:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include

Do the versions for those two things need to be somehow aligned? And have those environment variables to be set? And: After I downloaded and unpacked the ICU libraries, what do I do with them? How do I add them to my target?

It would be nice if those instructions were more complete / easier to follow. Thank you.

...And some other questions:

  1. It would be nice if the necessary tools could be installed without a full Visual Studio install, e.g. the Windows SDK can be downloaded separately, what else is needed?
  2. OK, I need all of this to compile Swift programs on Windows. Then what is needed to run them elsewhere (on a fresh Windows, without Visual Studio or Windows SDK installed)? Could I make a package so that from that package the program can be run without further requirements? On which Windows versions can it be run?
  3. What are the exact commands to compile Swift programs on Windows (example command), in particular: what special options could be used e.g. for static linking?

(Robert Muckle-Jones) #64

I am not sure why you are asking about %UniversalCRTSdkDir% and %VCToolsInstallDir% I didn't need to worry about those when following Compnerds instructions. However, there are two things which probably should be clearer (I couldn't make a pull request to modify them. When I clicked the edit pen on Azure I just got permission denied).

Firstly Compnerds instructions have you edit the environment variables via command prompt. I found it easier to go to the environment variable edit dialog and set them there.

Notice the third value in the path variables is where swift.exe resides and in fifth corresponds to where I chose to locate the extracted ICU library (ie. I renamed the folder icu and put it in C:\Library). When you edit the environment variables in this dialog you have to restart Windows in order for them to take effect.

Secondly, provided you have Visual Studio installed then to have the correct visual studio toolchain available you need to open the 'x64 Native Tools Command Prompt for VS 2017' located as shown (yes Windows is weird).


(Saleem Abdulrasool) #65

@RMJay, I'm happy to have changes to the instructions to make it clearer. Setting it through the GUI makes it persistent, and I think that having that in the instructions is perfectly fine as an alternative approach. Just create a PR on github at: https://github.com/compnerd/swift-windows-build ... I'll take care of propagating that into Azure.


(Saleem Abdulrasool) #66

@sspringer, the point of using those variables is so that you don't need to worry about them. As long as you are using the x64 Native Tools Command Prompt for VS 2017 Developer Command Prompt, the instructions should just DTRT. As to the ICU bits, the libraries need to be in %PATH%. I'm happy to accept PRs to improve the documentation.

I think that documenting the use of the swift compiler itself probably belongs in the swift repository as that has nothing to do with the use of it on Windows, that would be the same everywhere.

Packaging your results is far beyond the scope of the toolchain. That is entirely how to do development, which I'm not sure is really relevant to the toolchain. Although, that does point out the usefulness of having a separate artifact for the runtime components only from the SDK. I think that I might try to create a separate package for that if I get some time (or happy to have help if someone else beats me to it in making the changes to the Azure pipelines).


(Stefan Springer) #67

@RMJay, @compnerd: Thanks, it is much clearer now.


(Pedro José Pereira Vieito) #68

@compnerd Hi! I am trying to build Core Foundation (and Foundation :slight_smile:) on Windows, but I didn't find any documentation about how to do it. Using cmake to generate a Visual Studio project doesn't seem to work: when building the CoreFoundation project the cl.exe compiler receives invalid parameters (some seem to be clang specific) and aborts the compilation.

1>ClCompile:
1>  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\CL.exe /c /I"Z:\Documents\Developer\Swift\swift-corelibs-foundation\build\CoreFoundation-prefix\src\CoreFoundation-build\CoreFoundation.framework\PrivateHeaders" /I"Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation" /I"C:\Library\libxml2-2.9.3-win32-x86_64\include\libxml2" /I"C:\Library\curl-7.64.0-win64-mingw\include" /I"C:\Library\icu4c-63_1-Win64-MSVC2017\include" /I"Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\OFF" /I"Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\OFF\tests" /I"Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\OFF\src\BlocksRuntime" /Zi /nologo /W1 /WX- /diagnostics:classic /Od /Ob0 /Oy- /D _USRDLL /D _DLL /D DEPLOYMENT_TARGET_WINDOWS /D U_SHOW_DRAFT_API /D CF_BUILDING_CF /D DEPLOYMENT_ENABLE_LIBDISPATCH /D DEPLOYMENT_RUNTIME_SWIFT /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"CoreFoundation.dir\Debug\\" /Fd"CoreFoundation.dir\Debug\CoreFoundation.pdb" /Gd /TC /analyze- /errorReport:queue  -F Z:/Documents/Developer/Swift/swift-corelibs-foundation/build/CoreFoundation-prefix/src/CoreFoundation-build -include Z:/Documents/Developer/Swift/swift-corelibs-foundation/CoreFoundation/Base.subproj/CoreFoundation_Prefix.h -fblocks -fconstant-cfstrings -fdollars-in-identifiers -fexceptions -fno-common -fcf-runtime-abi=swift -Wno-shorten-64-to-32 -Wno-deprecated-declarations -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-unused-variable -Wno-int-conversion -Wno-unused-function -Wno-microsoft-enum-forward-reference "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFBase.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFFileUtilities.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFKnownLocations.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFPlatform.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFRuntime.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFSortFunctions.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFSystemDirectories.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFUtilities.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFUUID.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Base.subproj\CFWindowsUtilities.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFArray.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFBag.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFBasicHash.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFBinaryHeap.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFBitVector.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFData.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFDictionary.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFSet.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFStorage.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Collections.subproj\CFTree.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Error.subproj\CFError.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Locale.subproj\CFCalendar.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Locale.subproj\CFCalendar_Enumerate.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Locale.subproj\CFDateComponents.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Locale.subproj\CFDateFormatter.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Locale.subproj\CFDateInterval.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Locale.subproj\CFLocale.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Locale.subproj\CFLocaleIdentifier.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Locale.subproj\CFLocaleKeys.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Locale.subproj\CFNumberFormatter.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\NumberDate.subproj\CFBigNumber.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\NumberDate.subproj\CFDate.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\NumberDate.subproj\CFNumber.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\NumberDate.subproj\CFTimeZone.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Parsing.subproj\CFBinaryPList.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Parsing.subproj\CFOldStylePList.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Parsing.subproj\CFPropertyList.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Parsing.subproj\CFXMLInputStream.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Parsing.subproj\CFXMLInterface.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Parsing.subproj\CFXMLNode.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Parsing.subproj\CFXMLParser.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Parsing.subproj\CFXMLTree.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_Binary.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_DebugStrings.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_Executable.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_Grok.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_InfoPlist.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_Locale.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_Main.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_ResourceFork.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_Resources.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_Strings.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFBundle_Tables.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFPlugIn.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFPlugIn_Factory.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFPlugIn_Instance.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\PlugIn.subproj\CFPlugIn_PlugIn.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Preferences.subproj\CFApplicationPreferences.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Preferences.subproj\CFPreferences.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Preferences.subproj\CFXMLPreferencesDomain.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\RunLoop.subproj\CFRunLoop.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\RunLoop.subproj\CFSocket.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Stream.subproj\CFConcreteStreams.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Stream.subproj\CFSocketStream.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\Stream.subproj\CFStream.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFAttributedString.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFBurstTrie.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFCharacterSet.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFRegularExpression.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFRunArray.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFString.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFStringEncodings.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFStringScanner.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFStringTransform.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\String.subproj\CFStringUtilities.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\StringEncodings.subproj\CFBuiltinConverters.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\StringEncodings.subproj\CFICUConverters.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\StringEncodings.subproj\CFPlatformConverters.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\StringEncodings.subproj\CFStringEncodingConverter.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\StringEncodings.subproj\CFStringEncodingDatabase.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\StringEncodings.subproj\CFUniChar.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\StringEncodings.subproj\CFUnicodeDecomposition.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\StringEncodings.subproj\CFUnicodePrecomposition.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\URL.subproj\CFURLAccess.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\URL.subproj\CFURL.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\URL.subproj\CFURLComponents.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\URL.subproj\CFURLComponents_URIParser.c" "Z:\Documents\Developer\Swift\swift-corelibs-foundation\CoreFoundation\URL.subproj\CFURLSessionInterface.c"
1>Project build ended "Z:\Documents\Developer\Swift\swift-corelibs-foundation\build\CoreFoundation-prefix\src\CoreFoundation-build\CoreFoundation.vcxproj" (destinos predeterminados) -- ERROR.
1>cl : Command line error D8021 : invalid numeric argument '/FZ:/Documents/Developer/Swift/swift-corelibs-foundation/build/CoreFoundation-prefix/src/CoreFoundation-build' [Z:\Documents\Developer\Swift\swift-corelibs-foundation\build\CoreFoundation-prefix\src\CoreFoundation-build\CoreFoundation.vcxproj]

Should I use clang? How I generate the build instructions with cmake?

Thanks in advance!

UPDATE: I was able to build Core Foundation on Windows on the Visual Studio command prompt using the following cmake configuration:

cmake .. -G Ninja^
  -DCMAKE_BUILD_TYPE=Release^
  -DCMAKE_C_COMPILER=clang-cl^
  -DCMAKE_CXX_COMPILER=clang-cl^
  -DCMAKE_SWIFT_COMPILER=swiftc.exe^
  -DCMAKE_CXX_FLAGS="/GS- /Oy"^
  -DCMKE_SHARED_LINKER_FLAGS="/INCRMENTAL:NO"^
  -DBUILD_SHARED_LIBS=YES^
  -DENABLE_TESTING=NO^
  -DCMAKE_C_COMPILER_TARGET=x86_64-unknown-windows-msvc^
  -DENABLE_SWIFT=YES^
  -DCURL_LIBRARY="C:\Library\curl-7.64.0-win64-mingw\bin\libcurl-x64.dll"^
  -DCURL_INCLUDE_DIR="C:\Library\curl-7.64.0-win64-mingw\include"^
  -DICU_LIBRARY="C:\Library\icu4c-63_1-Win64-MSVC2017\bin64\icuuc63.dll"^
  -DICU_INCLUDE_DIR="C:\Library\icu4c-63_1-Win64-MSVC2017\include"^
  -DLIBXML2_LIBRARY="C:\Library\libxml2-2.9.3-win32-x86_64\bin\libxml2-2.dll"^
  -DLIBXML2_INCLUDE_DIR="C:\Library\libxml2-2.9.3-win32-x86_64\include\libxml2"^
  -DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE=Z:\Documents\Developer\Swift\swift-corelibs-libdispatch^
  && cmake --build .

Also, it seem to be a bug on the compiler when importing WinSDK and using an invalid identifier on the source code, instead of showing a compile-time error, it crashes with the following message:

Assertion failed: anonymousFieldDecl && "anonymous field not generated", file D:\a\1\s\swift\lib\ClangImporter\ImportDecl.cpp, line 769
Wrote crash dump file "C:\Users\pvieito\AppData\Local\Temp\swiftc.exe-a664fa.dmp"
LLVMSymbolizer: error reading file: PDB Error: Unable to load PDB.  Make sure the file exists and is readable.  Calling loadDataForExe

LLVMSymbolizer: error reading file: PDB Error: Unable to load PDB.  Make sure the file exists and is readable.  Calling loadDataForExe

LLVMSymbolizer: error reading file: PDB Error: Unable to load PDB.  Make sure the file exists and is readable.  Calling loadDataForExe

#0 0x00007ff6e6b50bf5 (C:\Library\Developer\Toolchains\Swift.xctoolchain\usr\bin\swiftc.exe+0x3640bf5)
#1 0x00007ffc24d9e19d (C:\Windows\System32\ucrtbase.dll+0x6e19d)
...

(Saleem Abdulrasool) #69

There are commands in WindowsBuild.md in the swift repository with the CMake invocation. There is a bug for the assertion failure that occurs with the import on Jira. I've not looked into that yet as I am trying to finish the port first instead. Briefly what is happening is that the declaration in the header requires a Microsoft extension, and that trips up the autocorrect code. You can work around it by passing -disable-typo-correction to swiftc -frontend for the time being. There is a patch for NSData on GitHub, and the WIP patch has the changes that I made to FileManager but that is incomplete.