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-13773] SPM: cannot use resources with .xcodeproj #4482

Open
swift-ci opened this issue Oct 25, 2020 · 4 comments
Open

[SR-13773] SPM: cannot use resources with .xcodeproj #4482

swift-ci opened this issue Oct 25, 2020 · 4 comments
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-13773
Radar rdar://problem/70687404
Original Reporter edbentley (JIRA User)
Type Bug
Environment

macOS Catalina 10.15.7

Xcode 12.1

Additional Detail from JIRA
Votes 2
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: b1fe56e5aa36f83b7e1264897fe33eab

Issue Description:

If a Swift package has a .xcodeproj file, it's not possible to use resources since the error Type 'Bundle' has no member “module” always comes up when building. It's possible to just not use a .xcodeproj file, but in some cases it's unavoidable.

For example, if you create a Swift Package which relies on UIKit, it's not possible to use `swift test` to run CLI tests.

# build works
swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator"
# but test gives error "module 'XCTest' was created for incompatible target x86_64-apple-macos10.15"
swift test -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator"

This can solved by generating a .xcodeproj:

```
swift package generate-xcodeproj
xcodebuild build -sdk iphoneos -scheme 'MyPackage-Package'
xcodebuild test -destination 'name=iPhone 11' -scheme 'MyPackage-Package'
```

However adding resources to the package then ends up with the error:

Type 'Bundle' has no member 'module'
Type of expression is ambiguous without more context

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Contributor Author

swift-ci commented Oct 5, 2021

Comment by Patrick Beard (JIRA)

I experienced this bug the other day and solved it a different way. I was trying to add individual .png files to my executable target, using:

resources: [.copy("foo.png"), .copy("bar.png")]

When building with SPM, the Bundle.module accessor would get generated, but loading the Package.swift into Xcode 13, the accessor would not get generated. I fixed it by moving all of the image files into a subdirectory called "Resources" and switching to this form:

resources: [.process("Resources")])

@kirilltitov
Copy link

Same problem (Xcode 13A1030d, default toolchain), except none of the suggested solutions worked (didn't try xcodeproj, though). Luckily, the generated file resource_bundle_accessor.swift is accessible, I copied the whole thing into a (hopefully) tmp file and renamed module into _module.

FYI I have not a .target, but rather an .executableTarget in my Package.swift and this problem manifests only in Xcode, running swift run from terminal works perfectly.

UPD: this solution didn't work in Linux (Docker, image 5.5), however, doing nothing (just use Bundle.module without anything) worked. I find myself mildly frustrated.

@swift-ci
Copy link
Contributor Author

Comment by Nicole Stone (JIRA)

Running into this same issue on Xcode 13.2.1. Calling `swift package generate-xcodeproj` did not fix the issue for me. But doing what @kirilltitov describes by just copying the generated file into a temp file did work for me.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants