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-10707] Issues importing Obj-C module in Obj-C Target #4710

Closed
ryanwilson opened this issue May 17, 2019 · 5 comments
Closed

[SR-10707] Issues importing Obj-C module in Obj-C Target #4710

ryanwilson opened this issue May 17, 2019 · 5 comments
Labels

Comments

@ryanwilson
Copy link
Contributor

Previous ID SR-10707
Radar rdar://problem/51669951
Original Reporter @ryanwilson
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift Package Manager - Swift 5.0.0 (swiftpm-14490.62.2)
macOS Mojave 10.14.5
Xcode Version 10.2.1 (10E1001)

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

md5: 117d0287ac49e91ba50cd47da0c45e30

Issue Description:

(First reported on the forums)

With two C based targets where one has a dependency on the other, I would expect to be able to use `@import <ModuleNameFromTarget>;` to import the generated module in the C (Objective-C in this case) code. I'm able to successfully import modules from both targets in a Swift based target, but not in a C based target. The only way to successfully import headers from the other target is to use the header name directly as a file import.

There are two errors that occur:

  1. Running swift build or swift run will result in a fatal error: module 'Foo' not found.

  2. If you generate an Xcode project, C based modules are disabled in the generated project so it fails right away.

I created a simple repro project on GitHub to demonstrate this with annotations on the problematic lines.

@ryanwilson
Copy link
Contributor Author

I'm not sure if this is a quick fix or not, but if nobody is going to look at it for a while I can take an attempt at fixing this with some guidance on where to start 🙂

@swift-ci
Copy link
Contributor

Comment by Matt Thomas (JIRA)

So, I sort of got your sample project working with the Xcode11/Swift5.1 toolchain (specifically building with Xcode11 and xcodebuild).

  1. In RWBar.m, I noticed you were using @import RWFoo, but the actual target name (and thus module name) specified in your *Package.*swift is ObjCFoo.

  2. If you change that import to @import ObjCFoo, you can both build in Xcode and xcodebuild*

  3. running swift build still throws an error.

*

xcodebuild -scheme spm-module-repro -sdk iphonesimulator13.0 -destination 'platform=iOS Simulator,name=iPhone Xs'

@ankitspd
Copy link
Member

Ah. It looks like we're missing `-fmodule-map-file=/private/tmp/SPM-Module-Repro/.build/x86_64-apple-macosx/debug/ObjCFoo.build/module.modulemap` argument when compiling RWBar.m. The fix would involve adding the modulemap argument when constructing plan for C targets. This is all in BuildPlan.swift if you want to take a stab at it.

@ryanwilson
Copy link
Contributor Author

Thanks codecaffeine (JIRA User) - updated in the GitHub Repo.

Thanks Ankit - I'll take a look this week and see if I can get it working, I appreciate the direction!

@ankitspd
Copy link
Member

#2336

@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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants