Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14579] Unable to import XCTest on Windows #4428

Closed
swift-ci opened this issue May 4, 2021 · 10 comments
Closed

[SR-14579] Unable to import XCTest on Windows #4428

swift-ci opened this issue May 4, 2021 · 10 comments
Assignees

Comments

@swift-ci
Copy link
Contributor

swift-ci commented May 4, 2021

Previous ID SR-14579
Radar None
Original Reporter SDGGiesbrecht (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Windows 10

Swift 5.4

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug, Windows
Assignee @compnerd
Priority Medium

md5: 67816bae400b324ab24712ed7c9bdd16

Issue Description:

swift test
[...]
D:\a\SDGCornerstone\SDGCornerstone\Sources\SDGXCTestUtilities\TestCase.swift:17:10: error: no such module 'XCTest'
  import XCTest
         ^

The issue can be evaded by specifying its location manually:

swift test -Xswiftc -I -Xswiftc C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows\x86_64 -Xswiftc -L -Xswiftc C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\lib\swift\windows

In case it makes a difference, this is in a normal target (not a test target).

@swift-ci
Copy link
Contributor Author

swift-ci commented May 4, 2021

Comment by Eugene Gubin (JIRA)

IIRC location of XCTest should be added to the PATH environment variable.

@compnerd
Copy link
Collaborator

Please provide a verbose log of the build and the environment. I suspect that your environment is not setup properly as XCTest works out of the box for me on a number of environments.

@swift-ci
Copy link
Contributor Author

Comment by Jeremy David Giesbrecht (JIRA)

As noted in the description, import XCTest does work in a testTarget(...), it just doesn’t work from a normal target(...).

So I doubt it is an environment problem, but rather it seems SwiftPM or the driver or something is treating the target types differently from one another.

I will try to fish out a full verbose log.

@swift-ci
Copy link
Contributor Author

Comment by Jeremy David Giesbrecht (JIRA)

I trimmed the package down to a single target with only one source file, this is the log of `swift build --verbose`:

D:\a\SDGCornerstone\SDGCornerstone>swift build --verbose 
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -print-target-info
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -print-target-info
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\4_2 -lPackageDescription -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -libc MD -swift-version 5 -I C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\pm\4_2 -package-description-version 5.3.0 D:\a\SDGCornerstone\SDGCornerstone\Package.swift -o "C:\Users\RUNNER~1\AppData\Local\Temp\TemporaryDirectory.hWctI3\sdgcornerstone-manifest.exe"
"C:\Users\RUNNER~1\AppData\Local\Temp\TemporaryDirectory.hWctI3\sdgcornerstone-manifest.exe" -handle 39c
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -module-name SDGXCTestUtilities -incremental -emit-dependencies -emit-module -emit-module-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\SDGXCTestUtilities.swiftmodule -output-file-map D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\SDGXCTestUtilities.build\output-file-map.json -parse-as-library -c D:\a\SDGCornerstone\SDGCornerstone\Sources\SDGXCTestUtilities\TestCase.swift -I D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug -target x86_64-unknown-windows-msvc -swift-version 5 -enable-batch-mode -index-store-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\index\store -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -libc MD -Onone -enable-testing -g -j2 -DSWIFT_PACKAGE -DDEBUG -module-cache-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\ModuleCache -parseable-output
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -frontend -c -primary-file D:\a\SDGCornerstone\SDGCornerstone\Sources\SDGXCTestUtilities\TestCase.swift -emit-module-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\SDGXCTestUtilities.build\TestCase~partial.swiftmodule -emit-module-doc-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\SDGXCTestUtilities.build\TestCase~partial.swiftdoc -emit-module-source-info-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\SDGXCTestUtilities.build\TestCase~partial.swiftsourceinfo -emit-dependencies-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\SDGXCTestUtilities.build\TestCase.d -emit-reference-dependencies-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\SDGXCTestUtilities.build\TestCase.swiftdeps -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -I D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug -enable-testing -g -module-cache-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -enable-anonymous-context-mangled-names -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -parse-as-library -module-name SDGXCTestUtilities -o D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\SDGXCTestUtilities.build\TestCase.swift.o -index-store-path D:\a\SDGCornerstone\SDGCornerstone\.build\x86_64-unknown-windows-msvc\debug\index\store -index-system-modules
D:\a\SDGCornerstone\SDGCornerstone\Sources\SDGXCTestUtilities\TestCase.swift:15:8: error: no such module 'XCTest'

import XCTest

       ^

@swift-ci
Copy link
Contributor Author

Comment by Jeremy David Giesbrecht (JIRA)

Actually, never mind about a difference between target tests. My memory failed me.

Just now I moved it to a test target and got the same error and essentially the same log, (the only differences being the temporary directory, handle identifier and the fact that the target path moved from `Sources` to `Tests`).

@swift-ci
Copy link
Contributor Author

Comment by Jeremy David Giesbrecht (JIRA)

Are we supposed to manually create a DEVELOPER_DIR environment variable after installation?

if let DEVELOPER_DIR = ProcessEnv.vars["DEVELOPER_DIR"],

@compnerd
Copy link
Collaborator

The installer creates the environment variables for you. You should relaunch the session after the installation to ensure that all the system changes are picked up.

@compnerd
Copy link
Collaborator

compnerd commented Jul 8, 2021

I'm going to mark this as resolved for now. If this is still an issue, feel free to re-open it.

@swift-ci
Copy link
Contributor Author

swift-ci commented Nov 2, 2021

Comment by Jeremy David Giesbrecht (JIRA)

This seems to still be an issue in 5.5.1:

curl --location ^
  https://swift.org/builds/swift-5.5.1-release/windows10/swift-5.5.1-RELEASE/swift-5.5.1-RELEASE-windows10.exe ^
  --output %TEMP%\swift-5.5.1-RELEASE-windows10.exe
%TEMP%\swift-5.5.1-RELEASE-windows10.exe /passive
set SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk
echo SDKROOT=%SDKROOT%>>%GITHUB_ENV%
copy %SDKROOT%\usr\share\ucrt.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
copy %SDKROOT%\usr\share\visualc.modulemap "%VCToolsInstallDir%\include\module.modulemap"
copy %SDKROOT%\usr\share\visualc.apinotes "%VCToolsInstallDir%\include\visualc.apinotes"
copy %SDKROOT%\usr\share\winsdk.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
set Path=C:\Library\icu-67\usr\bin;%Path%
set Path=C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin;%Path%
set Path=C:\Library\Swift-development\bin;%Path%
set Path=C:\Library\Developer\Platforms\Windows.platform\Developer\Library\XCTest-development\usr\bin;%Path%
swift --version

swift test

(...happily building all sorts of targets... but then suddenly...)

error: no such module 'XCTest'
import XCTest
       ^

Note that despite what the updates to the downloads page say, the module maps must still be copied and the path must still be added to manually. Remove any of that, and the whole thing breaks.

That makes me think the core of the issue might have something to do with your comment about relaunching the session. (I am not sitting at a Windows machine, I am only using it remotely for CI tests.)

@swift-ci
Copy link
Contributor Author

Comment by Jeremy David Giesbrecht (JIRA)

I found and switched to gha-setup-swift and the problem vanished.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants