swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.68k stars 1.32k forks source link

"swift package resolve" creates a .exe in a temp folder #7105

Open alexanderjung-sdxag opened 9 months ago

alexanderjung-sdxag commented 9 months ago

Description I am new to swift and got stuck with the example https://www.swift.org/getting-started/cli-swiftpm/ under Windows 11.

swift build - and I have narrowed it down to swift package restore - results in the following error message:

c:\Swift\MyCLI>swift package restore
error: 'mycli': Error Domain=NSCocoaErrorDomain Code=257 "You don’t have permission."

I could not find out, for which file or directory the permissions are missing.

Steps to reproduce I just followed the steps described in: https://www.swift.org/getting-started/ https://www.swift.org/install/windows/#installation-via-windows-package-manager https://www.swift.org/getting-started/cli-swiftpm/

Expected behavior swift build without error.

Environment

Swift version 5.9.1 (swift-5.9.1-RELEASE)
Target: x86_64-unknown-windows-msvc

Microsoft Windows [Version 10.0.22000.2600]

Visual Studio 2022 Developer Command Prompt v17.8.0 - x64

Any help solving the issue - or at least tracking down the root cause - would be appreciated!

Additional info Same issue in VS Code. swiftc Sources\main.swift -o MyCLI.exe works.

neonichu commented 9 months ago

Not sure what swift package restore is? Did you maybe mean swift package resolve? I don't have access to a Windows machine but at least in the toolchain we ship on macOS, there is no such thing as swift package restore.

alexanderjung-sdxag commented 9 months ago

swift package restore and swift package resolve seem to be doing the same, (At least the resulting error is.) I don't remember where I've gotten this from. (I'm going to change the title though.)

BTW: I also don't remember the option to pass to swift to get the detailed commands (i.e. swift package restore/resolve)...

Here's the output with --vv if that is any help:

c:\Swift\MyCLI>swift build --vv
debug: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -print-target-info
debug: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -print-target-info
debug: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -print-target-info
debug: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -print-target-info
debug: registering 'repository fetching' with terminator
debug: registering 'registry downloads' with terminator
debug: registering 'binary artifacts downloads' with terminator
debug: registering 'plugin runner' with terminator
debug: registering 'build system' with terminator
debug: 'mycli': evaluating manifest for 'mycli' v. unknown
debug: 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\JungAl\AppData\Local\Temp\TemporaryDirectory.UNDgPt\manifest.swift -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -v -o C:\Users\JungAl\AppData\Local\Temp\TemporaryDirectory.o1Ia3x\mycli-manifest.exe
debug: C:\Users\JungAl\AppData\Local\Temp\TemporaryDirectory.o1Ia3x\mycli-manifest.exe -handle 370 -context "{""packageDirectory"":""C:\\Users\\JungAl\\AppData\\Local\\Temp\\TemporaryDirectory.UNDgPt""}"
error: 'mycli': Error Domain=NSCocoaErrorDomain Code=257 "You don’t have permission."
neonichu commented 9 months ago

Looks like this is an issue in manifest loading, not sure where mycli comes from or what it is supposed to be, it looks like we're trying to execute mycli-manifest.exe and maybe that gets cut off somewhere and we're trying to execute something that doesn't exist instead?

alexanderjung-sdxag commented 9 months ago

mycli is just a minimalist hello world application, created as per these instructions: https://www.swift.org/getting-started/cli-swiftpm/ And I can only guess what swift.exe is doing here - that is the reason I am stuck.

To be clear: This is the "You are new to swift? Try this simple hello-word-application to get you started"-example from the official swift documentation. And it does not work as advertised.

alexanderjung-sdxag commented 7 months ago

I'm one step further: ist seems that the toolchain creates an .exe in the temp folder and tries to access it. image This is denied by Microsoft Defender (and IMHO rightly so). I would consider this a bug....

alexanderjung-sdxag commented 7 months ago

I have just renamed the issue to: "swift package resolve" creates a .exe in a temp folder

Rationale: Placing executables in temporary folders is a typical behavior of malware. For this reason accessing executables in temporary folders is prevented by Microsoft Defender in many companies.

My suggestion would be that the swift toolchain uses a local build folder (usually ./obj in other systems) for its temporary output.