Invalid manifest after using `swift package init --type executable`

Hey all,

I have been encountering an Invalid manifest error when building any swiftpm project on Windows 11 (22H2 build 22621.2283). This happens even on packages generated using swift package init that should just produce a dummy executable.

I could reproduce this on Swift 5.9.1 installed as per the instructions on swift.org and I made sure that the right Windows SDK is installed.

The error is the following (eg. while running resolve):

C:\Users\Federico\example> swift package resolve
error: 'example': Invalid manifest (compiled with: ["C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swiftc.exe", "-L", "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\pm\\ManifestAPI", "-lPackageDescription", "-sdk", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk", "-libc", "MD", "-I", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows", "-I", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-L", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-use-ld=lld", "-swift-version", "5", "-I", "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\pm\\ManifestAPI", "-package-description-version", "5.9.0", "C:\\Users\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.vJIEVe\\manifest.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-o", "C:\\Users\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.AGeIBj\\example-manifest.exe"])
Missing or empty JSON output from manifest compilation for example

This is a repro case using -vv (I omitted some clutter output from the powershell):

C:\Users\Federico\t1> swift package --version
Swift Package Manager - Swift 5.9.1
C:\Users\Federico> mkdir example
C:\Users\Federico> cd example
C:\Users\Federico\example> swift package init --type executable
Creating executable package: example
Creating Package.swift
Creating .gitignore
Creating Sources/
Creating Sources\main.swift
C:\Users\Federico\example> swift build -vv
error: 'example': Invalid manifest (compiled with: ["C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swiftc.exe", "-L", "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\pm\\ManifestAPI", "-lPackageDescription", "-sdk", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk", "-libc", "MD", "-I", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows", "-I", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-L", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-use-ld=lld", "-swift-version", "5", "-I", "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\pm\\ManifestAPI", "-package-description-version", "5.9.0", "C:\\Users\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.lQfhIj\\manifest.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-v", "-o", "C:\\Users\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.PYKICt\\example-manifest.exe"])
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift-frontend.exe -frontend -c -primary-file C:\Users\Federico\AppData\Local\Temp\TemporaryDirectory.lQfhIj\manifest.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -I C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows -I C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -I C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\pm\ManifestAPI -swift-version 5 -package-description-version 5.9.0 -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -empty-abi-descriptor -resource-dir C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift -module-name main -plugin-path C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin -plugin-path C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\local\bin -o C:\Users\Federico\AppData\Local\Temp\TemporaryDirectory.eg4OUT\manifest-1.o
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\clang.exe -target x86_64-unknown-windows-msvc -fuse-ld=lld -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\Federico\AppData\Local\Temp\TemporaryDirectory.eg4OUT\manifest-1.o -L C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\pm\ManifestAPI -L C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -I C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -v -o C:\Users\Federico\AppData\Local\Temp\TemporaryDirectory.PYKICt\example-manifest.exe -lPackageDescription
Swift version 5.9.1 (swift-5.9.1-RELEASE)
Target: x86_64-unknown-windows-msvc
swift.org clang version 16.0.0
Target: x86_64-unknown-windows-msvc
Thread model: posix
InstalledDir: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin
 "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\lld-link" "-out:C:\\Users\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.PYKICt\\example-manifest.exe" "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\lib\\x64" "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\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\\16.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" "-libpath:C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\pm\\ManifestAPI" "-libpath:C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\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\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.eg4OUT\\manifest-1.o" PackageDescription.lib

I have also verified that my swift install is able to compile and link, as in I can use swiftc to build a simple hello world program.

I could also run the commands in the very verbose output above manually, replacing the manifest.swift file in a temporary directory with the example\Package.swift. I could not figure out what command would output a JSON file, my assupmtion was swift-frontend but that did not appeart to be the case.

Unfortunately swiftpm deletes all the temporary directories and files it created on failure, so I could not check what files it actually uses.

I'd appreciate any suggestion on how to move forwards here, perhaps there is some other test I can do that can further reveal what's going on here. Meanwhile, I'll get a hold of another Windows 11 instance and see if I can reproduce it there too. While it would be a shame that my particular Windows 11 / Swift install fails, it would at least explain why I can't seem to find anyone else encountering this exact issue.

Are you in regular PowerShell or Visual Studio developer PowerShell? From what I remember about using Swift on Windows, it only works in the latter.

TL;DR: it runs only from VSCode PowerShell, not from Visual Studio or Terminal.

Thanks for the input, I think you are right!

I was using the regular PowerShell, but I also tried on the Developer PowerShell for VS 2022 with the same result. I read something about the topic, but I didn't think much of it and only used the dev shell from within Terminal.

Using the shell from within Visual Studio, I get a new error:

C:\Users\Federico\example> swift build -vv
error: 'example': Invalid manifest (compiled with: ["C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swiftc.exe", "-L", "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\pm\\ManifestAPI", "-lPackageDescription", "-sdk", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk", "-libc", "MD", "-I", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows", "-I", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-L", "C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-use-ld=lld", "-swift-version", "5", "-I", "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\pm\\ManifestAPI", "-package-description-version", "5.9.0", "C:\\Users\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.f7JJ0X\\manifest.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-import", "-v", "-o", "C:\\Users\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.BWZnT4\\example-manifest.exe"])
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift-frontend.exe -frontend -c -primary-file C:\Users\Federico\AppData\Local\Temp\TemporaryDirectory.f7JJ0X\manifest.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -I C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows -I C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -I C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\pm\ManifestAPI -swift-version 5 -package-description-version 5.9.0 -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -empty-abi-descriptor -resource-dir C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift -module-name main -plugin-path C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin -plugin-path C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\local\bin -o C:\Users\Federico\AppData\Local\Temp\TemporaryDirectory.3uLnVZ\manifest-1.o
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\clang.exe -target x86_64-unknown-windows-msvc -fuse-ld=lld -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\Federico\AppData\Local\Temp\TemporaryDirectory.3uLnVZ\manifest-1.o -L C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\pm\ManifestAPI -L C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -I C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -v -o C:\Users\Federico\AppData\Local\Temp\TemporaryDirectory.BWZnT4\example-manifest.exe -lPackageDescription
error: fatalError
Swift version 5.9.1 (swift-5.9.1-RELEASE)
Target: x86_64-unknown-windows-msvc
error: link command failed with exit code 1 (use -v to see invocation)
swift.org clang version 16.0.0
Target: x86_64-unknown-windows-msvc
Thread model: posix
InstalledDir: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin
 "C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\lld-link" "-out:C:\\Users\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.BWZnT4\\example-manifest.exe" "-libpath:C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\clang\\16.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" "-libpath:C:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\pm\\ManifestAPI" "-libpath:C:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\Library\\XCTest-development\\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\\Federico\\AppData\\Local\\Temp\\TemporaryDirectory.3uLnVZ\\manifest-1.o" PackageDescription.lib
lld-link: error: <root>: undefined symbol: mainCRTStartup
clang: error: linker command failed with exit code 1 (use -v to see invocation)

IIUC mainCRTStartup is associated with the C runtime, and I can't figure out why I get this error exclusively from Visual Studio.

I finally opened VSCode (not Visual Studio) and used its PowerShell terminal to run swift build and that did the trick.

I am happy that this worked, but the idea of this working exclusively from VSCode PowerShell is "wrinkling my brain". I'll see if I can find what's changing in the shell environment.

1 Like