-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add support for textual imports to -emit-objc-header #62386
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
Add support for textual imports to -emit-objc-header #62386
Conversation
Currently headers produced with `-emit-objc-header` / `-emit-objc-header-path` produce headers that include modular imports. If the consumer wishes to operate without modules enabled, these headers cannot be used. This patch introduces a new flag (`-emit-clang-header-nonmodular-includes`) that when enabled attempts to argument each modular import included in such a header with a set of equivalent textual imports.
@swift-ci Please test |
@swift-ci please test source compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine to me. We'll have to keep out eye on https://ci.swift.org/job/oss-swift_tools-RA_stdlib-DA_test-device-non_executable to make sure it lands cleanly.
Hi @NuriAmari–– I'm working on adding Swift Package Manager support for mixed language (Swift + Objective-C) targets in swiftlang/swift-package-manager#5919. I'm running into an issue and am unsure if this PR's flag is a solution to the same problem– I was hoping you could weigh in. The Based on my understanding of this PR, the To test, I checked out the nightly toolchain and passed this flag instead of The problem I'm facing now is that, although I noticed the generated interop header change slightly, the new flag does not prevent the addition of the module style umbrella import. I'll share the relevant part of my generated header:
Note: I also used I'm now thinking that this new flag has no effect on the I'd appreciate any thoughts! |
Hi @ncooke3 Unfortunately I don't think this flag will have the effect you are looking for.
Sort of, yes it translates to non-modular imports, but if there are umbrella headers available it will use them. You can read the change to see more detail, but the logic goes something like: -> If the Clang module has an umbrella header, include that But these headers are only included if the Clang module definition specifies them, which I'm assuming wouldn't be an issue for you.
Yes, this change has no effect on that include. It is generated here: https://github.com/NuriAmari/swift/blob/cd4b9a64169550a47b795c86f5d9fa0d2376b0c9/lib/PrintAsClang/PrintAsClang.cpp#L636-L643 . If the code is any indication, that include is meant to be a bridging header.
Do you mean by including Happy to help, I think what you want is achievable, but I'm not entirely sure what that is right now. |
Thanks @NuriAmari for taking the time- this is helpful!
Yes, I'm claiming that by including
I have a feeling I'm wrong about this though–– I'm not super confident about my understanding of
If by textual one, you are referring to Unless a mixed target (e.g. My current workaround I've been locally developing/testing does the following:
This workaround seems to work. One side effect is that the target's sources as well as clients can import the generated umbrella header– which might seem a bit unexpected because it is a build artifact. On the other hand, the target's sources can import the generated Swift header so there is some precedent for importing generated build artifacts. In the case of the Based on the code you sent, what would be better than my current workaround would be it there was a flag to pass in the bridging header imported within the I'm very much open to any alternative ideas as well! |
I worked backwards from the code you sent and found the |
Generally in C based languages, <...> is for system headers, "..." is for user created headers, but to my knowledge
Yes by textual I just mean
Certainly worth a try. Use |
Thanks @NuriAmari! I experimented with both options but couldn't get the textual import to change. Based on this code, it seems that in order to use the value from the Unfortunately though, I cannot use I think this limitation makes sense to me that you can either use one or the other. So far, Edit:
That didn't seem to work. The Swift sources can't seem to find any ObjC types within the scope. I think I'll have to stick to the workaround described in my above comment #62386 (comment). |
A second attempt at #60971, but without the flaky test.
The test that was removed was designed to test header emission against the SDK. It was already complicated having to handle the SDK on different platforms, and would break if the SDK changed. Rather than attempt to make a test that is vague enough to be SDK resilient I've just removed the test; the tests against the more stable mock-sdk should be enough to prevent regression. The functionality itself has been tested extensively against the SDK and other libraries.