Missing Swift tools version specification (Build Fail)

When running "swift build" in command prompt inside my file directory I receive the following error:

Yes, I have followed the install instructions correctly and everything is fresh with no duplicates.

File name is: "Package.swift"
Swift 5.7

Here is the command prompt logs: (same for developer and normal)

I recommend initialising a new project with swift package init --type executable. That will create a valid Package.swift.


This is the source of the error, Package.swift is not supposed to contain the source code for your package. Package.swift is a package manifest that specifies what dependencies, products, and targets your package declares.

Move your print("hello") code to a file with any other name and then you can compile it as a standalone source file with swiftc, or with swift build as a part of a package that has a valid Package.swift manifest.

1 Like

This is all it does when I run swiftc swift.swift

This is all that returns when I try to build a properly installed swift package.

A new swift package created via the command, or something you downloaded?

Created with the command.

kernel32.lib is provided by the Windows SDK, it sounds like you didn't install Visual Studio properly (this is already covered in the installation instructions) or you have multiple versions installed, in which case you need to use the Developer Command prompt for the Visual Studio version that you want to use.

Thank you I will try this later and keep you updated.

I think the problem here is that SwiftPM isn't reading anything from your manifest file. I.e. it thinks the file is empty.

When I tried to reproduce the two errors from your first screenshot, I got only the second error and a "hello":

The missing "hello" line from your output indicates that SwiftPM didn't read your print("hello"). Since standard library functions are allowed in the manifest, if the call is read, then "hello" should be in your output.

The first error message says that SwiftPM can't find your tools version specification, even though we can see it's there and well-formed. The specification parser's logic shouldn't be affected by the platform it runs on, and there are some really really extensive test cases just for parsing this line of comment, so I'm very confident that the error is not from the parser. (A bit of an aside: this makes me realise we probably should add some diagnostics for invisible characters, so we can point them out in the error message if they exist.)

So, basically all clues point to that the manifest isn't read by SwiftPM. Either there is a bug in the manifest loader or some calls to system APIs for reading the manifest are not working.

Also note: you will still have an "invalid manifest" error after this problem is resolved, because you don't have a Package instance named package in the manifest. We should improve the message here a bit to point out exactly what's causing the error (whether SwiftPM thinks it's empty or package is missing etc).


Wow thanks a lot I will definitely touch up on the documentation. I think another issue might be that the VS build tools were not installed. Will test again today.

This is now happening on my end after upgrading Visual Studio.

I reverted the upgrade, even uninstalled Swift and VS completely and did everything as it is written in the installing swift manual. No success. No matter what I do, no matter if I go by manual or install the components and swift myself, it does not work anymore.

I did dig a little deeper and even though I have used the exact steps, Kernel.lib is missing in my VS lib directory. Maybe this has been changed on MS's side of things?

Another update:

This is the log when using swiftc -v:
PS H:\Projects\SwiftVulkanTest> swiftc test.swift -v
compnerd.org Swift version 5.8 (swift-5.8-RELEASE)
Target: x86_64-unknown-windows-msvc
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift-frontend.exe -frontend -c -primary-file test.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -color-diagnostics -empty-abi-descriptor -resource-dir C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift -module-name test -o C:\Users\Marcel\AppData\Local\Temp\TemporaryDirectory.Cmx860\test-1.o
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\clang.exe -target x86_64-unknown-windows-msvc -nostartfiles -L C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\x86_64 C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\x86_64\swiftrt.obj C:\Users\Marcel\AppData\Local\Temp\TemporaryDirectory.Cmx860\test-1.o -I C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -v -o test.exe
error: link command failed with exit code 1104 (use -v to see invocation)
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
compnerd.org clang version 15.0.0
Target: x86_64-unknown-windows-msvc
Thread model: posix
InstalledDir: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\link.exe" -out:test.exe "-libpath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\lib\x64" "-libpath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\atlmfc\lib\x64" "-libpath:C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\ucrt\x64" "-libpath:C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\x64" "-libpath:C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\clang\15.0.0\lib\x86_64-unknown-windows-msvc" "-libpath:C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\x86_64" -nologo "C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\x86_64\swiftrt.obj" "C:\Users\Marcel\AppData\Local\Temp\TemporaryDirectory.Cmx860\test-1.o"
clang: error: linker command failed with exit code 1104 (use -v to see invocation)

I checked all libpaths and can confirm that these are the correct paths for the libs. Almost all libs are located there, but kernel.lib remains missing

This stackoverflow might be worth a look as well:

LINK : fatal error LNK1104: cannot open file 'kernel32.lib'

kernel32.lib is from the SDK, it should get picked up properly when you have the Windows SDK installed. Can you verify that it exists at %ProgramFiles(x86)%\Windows Kits\10\Lib\10.0.22621.0\um\x64\kernel32.Lib ?

You might need to uninstall and reinstall the Windows SDK (if you do this through VS, you will need to re-run the Swift installer unless you are on a nightly from main).