-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implicit import of Dispatch when importing Foundation? #1206
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
Implicit import of Dispatch when importing Foundation? #1206
Conversation
I support the general idea: that as I'll defer to @parkera etc. on whether this is the best way to achieve that. |
This gets us the nice Swift interface of Dispatch, right? Not an exported C API? |
I’m pretty sure that’s the case. The C dispatch API would be an import of “CDispatch". |
@swift-ci please test |
Interesting failure. Implicit import of Dispatch means XCTest must now know how to link against it when building. You can fix it with this small tweak: SwiftJava/swift-corelibs-xctest@1b73c3e |
I’ve created a PR on XCTest to resolve this: swiftlang/swift-corelibs-xctest#201 |
Can you create a simple app that is outside the Swift build system and imports Foundation with this change? Does this change what linker flags they need to use as well? |
Sure, I’ll try to create a test. It shouldn’t be a problem as something using a completed toolchain will find libdispatch.so and libFoundation.so in the same directory. It’s only during the build system build they are in different directories: |
You should be able to try the test again now the tweak to swift-corelibs-xctest was merged. |
@swift-ci please test |
Thanks again @briancroom, @parkera re: creating a test app I’ve been using this to patch run apps for weeks as well as running the foundation tests so I think this won't have an impact. Foundation itself is dependent on Dispatch anyway. |
Ok |
IMO, this should really be its own file, which IIRC is the same way that |
A whole new file just for one line seems a bit unnecessary - I'm fine with using |
I'm ok with doing it in NSObject - but can we put a comment or something with a bit of explanation of why it's there? |
84f4628
to
e5569b3
Compare
@swift-ci test and merge |
@swift-ci please test and merge |
Hi Apple,
With apologies for the rash of controversial PRs this week, I’m getting to the end the preparation of a release candidate for the Android/Swift toolchain that I’ve been working on and testing with a wide range of Open Source packages (Alamofire, Moya, RxSwift etc.) for portability. One assumption that commonly comes up in these projects is that importing Foundation is enough to have Dispatch classes available to the Swift source i.e it is imported implicitly when you import Foundation.
You must have considered this, and for compatibility with Darwin I would have thought this was the way to go so I’ve added an @_exported import of Dispatch to NSObject.swift in the toolchain for want of a better place to put it. I had also experimented with exporting CoreFoundation but functions like bind() and accept() seem to leak from CoreFoundation.h and are defined in Glibc causing ambiguity errors.
What are your thoughts?