Swift not able to compile

I was trying to install Swift for Tensorflow. I followed all the instruction correctly mentioned here: swift/Installation.md at main · tensorflow/swift · GitHub

But when I compile the swift file. I get this error: :0: error: unable to load standard library for target 'x86_64-unknown-windows-msvc'

Also, I'm able to fire Swift REPL but I when I declare a variable. I get this error:

λ swift
Welcome to compnerd.org Swift version 5.2-dev (LLVM 0829984b78, Swift ba64a644c8).
Type :help for assistance.
1> let a = 5
Assertion failed: false && "called into swift language runtime stub", file S:\14\s\toolchain\lldb\source\Target\SwiftLanguageRuntime.cpp, line 296
********************
Crash reproducer for lldb version 10.0.0 (https://github.com/apple/llvm-project revision 0829984b78323ed123ea27b998aa21c5babf1025)
compnerd.org Swift version 5.2-dev (LLVM 0829984b78, Swift ba64a644c8)

Reproducer written to 'C:\Users\antpc\AppData\Local\Temp\reproducer-f67d31'

Before attaching the reproducer to a bug report:
 - Look at the directory to ensure you're willing to share its content.
 - Make sure the reproducer works by replaying the reproducer.

Replay the reproducer with the following command:
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe -replay C:\Users\antpc\AppData\Local\Temp\reproducer-f67d31
********************
 #0 0x00007ff7c4e7c7b5 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe+0x1c7b5)
 #1 0x00007ffb9dad1861 (C:\WINDOWS\System32\ucrtbase.dll+0x71861)
 #2 0x00007ffb9dad2831 (C:\WINDOWS\System32\ucrtbase.dll+0x72831)
 #3 0x00007ffb9dad424e (C:\WINDOWS\System32\ucrtbase.dll+0x7424e)
 #4 0x00007ffb9dad4145 (C:\WINDOWS\System32\ucrtbase.dll+0x74145)
 #5 0x00007ffb9dad44d1 (C:\WINDOWS\System32\ucrtbase.dll+0x744d1)
 #6 0x00007ffb4981a482 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x67a482)
 #7 0x00007ffb49909bd4 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x769bd4)
 #8 0x00007ffb4990e78d PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x76e78d)
 #9 0x00007ffb4990c5cd PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x76c5cd)
#10 0x00007ffb49906aea PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x766aea)
#11 0x00007ffb496898ce PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4e98ce)
#12 0x00007ffb49697269 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4f7269)
#13 0x00007ffb4966334c PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4c334c)
#14 0x00007ffb4960f7b3 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x46f7b3)
#15 0x00007ffb496117de PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x4717de)
#16 0x00007ffb9da81542 (C:\WINDOWS\System32\ucrtbase.dll+0x21542)
#17 0x00007ffb9e2c6fd4 (C:\WINDOWS\System32\KERNEL32.DLL+0x16fd4)
#18 0x00007ffb9fc7cec1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x4cec1)

Given the Windows paths cc @compnerd :)

1 Like

@AbhimanyuAryan I would recommend that you carefully read over the instructions. I suspect that you are not using the toolchain correctly and missing flags. What is your exact invocation for the compiler?

I would expect something like this:

set SDKROOT=%SystemDrive%/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk
%SystemDrive%/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin/swiftc.exe -sdk %SDKROOT% -I %SDKROOT%\usr\lib\swift -L %SDKROOT%\usr\lib\swift\windows ...

I'd like to be able to remove the extra -I and -L flags but unfortunately, I've been busy with other work.

The REPL requires additional flags to work. You should invoke it as:

lldb "--repl=-sdk %SDKROOT% -I %SDKROOT%\usr\lib\swift -L %SDKROOT%\usr\lib\swift\windows"

Patches to improve the documentation welcome!

@compnerd I don't know everything seems to have installed just fine. I have also SET things correctly. please look into it

Also Swift requires python 3.7 with Visual Studio. I installed it but my system is still using python 2.7 globally is that a problem?

I saw PyInit__lldb error messages that is why I'm asking

I uninstall python 2.7 from control panel & now conda took over my system python with 3.7.5
I tried running swift command in terminal & it doesn't even fire REPL

I'm not even sure if it's a python problem....

Yes, lldb requires Python3.7 (which is part of Visual Studio), but should already be there I believe.

The errors are due to missing flags :). You must provide the SDK path (and currently an additional include and library search path which I hope to be able to remove, I think I have some ideas on that). In general, long term, your invocation should be something like:

swiftc -sdk [SDKPath] ...

In the mean time, it ends up being:

swiftc -sdk [SDKPath] -I [SDKPath]\usr\lib\swift -L [SDKPath]\usr\lib\swift\windows ...

That said, the integrated repl is not very well tested, I would recommend that you use the LLDB REPL (which requires that you pass in additional flags as I mentioned earlier).

The compilation errors you have not shared nor have you shared the compiler invocation so it is difficult to advise you on that.

so how should I compile test.swift. I type swiftc test.swift I get same error unable to load standard libary to target 'x86 .............

As I suggested upthread:

set SDKROOT=%SystemDrive%/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk
swiftc -sdk %SDKROOT% -I %SDKROOT%\usr\lib\swift -L %SDKROOT%\usr\lib\swift\windows -emit-executable test.swift -o test.exe

Should allow you to compile the program :)

It says %SDK_ROOT% system can't find it...I have already copy pasted this set SDKROOT=%SystemDrive%/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk

Should i go in environment variable and create this manually ??

If you create the environment variable from the Settings panel, it will be persistent, if you set it from the console using set, it will be ephemeral.

%SDK_ROOT% is the wrong variable .. the variable was %SDKROOT% without the underscore. I would recommend that you ensure that the paths are correct, because it sounds like something is missing if those paths are not found.

1 Like

wait I'll double check everything

@compnerd this is creating me the output file but how do I run this file? And this worked...I also want to use REPL like feature? Can you also paste command for that? you mentioned LLDB REPL...what command can fire that?

.\test.exe should execute the program.

I get this error when firing lldb

This application was unable to start correctly (0xc0000279). Click on Ok close the application.