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

Quick Swift<->Obj-C header imports relies on compiler bug #933

Open
1 task done
zacwest opened this issue Nov 5, 2019 · 3 comments
Open
1 task done

Quick Swift<->Obj-C header imports relies on compiler bug #933

zacwest opened this issue Nov 5, 2019 · 3 comments
Labels

Comments

@zacwest
Copy link

zacwest commented Nov 5, 2019

  • I have read CONTRIBUTING and have done my best to follow them.

What did you do?

I'm integrating Quick into a codebase where I need to define the Xcode module/framework manually. As part of that, I'm roughly following the .podspec to produce results. Part of this investigation yielded an issue: I couldn't get the Quick Objective-C files to be able to see the World class from Swift.

This is because internal Swift classes are not accessible, even within the same module:

Because the generated header is part of the framework’s public interface, only declarations marked with the public or open modifier appear in the generated header for a framework target. Methods and properties that are marked with the internal modifier and declared within a class that inherits from an Objective-C class are accessible to the Objective-C runtime.

Your reaction might be: but clearly Quick is doing that right now, and it compiles fine!

It took me all day, but I finally narrowed down the "why": Quick is asking for extension-only API which exposes an underlying bug in the compiler which causes internal Swift things to be available in the Quick-Swift.h file.

You can reproduce this issue by disabling the extension-only flag in the Xcode project (set APPLICATION_EXTENSION_API_ONLY to NO) and it'll stop compiling, unable to find World:

…/Sources/QuickObjectiveC/QuickSpec.m:30:27: Use of undeclared identifier 'World'; did you mean 'bold'?

I recommend you take a look at how the bridging is working here so that you're not stuck scrambling to get this to work once the underlying bug is resolved. You can likely use the fact that internal properties and methods are still available to get the kind of segregation you're looking for.

Environment

List the software versions you're using:

  • Quick: 87c4848
  • Nimble: n/a
  • Xcode Version: 11.1/11.2
  • Swift Version: Xcode Default
@ajanuar
Copy link

ajanuar commented Apr 17, 2020

How do you solve this issue in your case? thanks!

I got the same error message when compiling Quick in Bazel.

@zacwest
Copy link
Author

zacwest commented Apr 17, 2020

You need to pass -application-extension down to the Swift compiler in order to get this bug to happen (and make it compile). I can't tell you the Bazel specifics, though it's likely similar, but in Buck this looks like:

apple_library(
  # …
  swift_compiler_flags = [ "-application-extension" ],
)

@ajanuar
Copy link

ajanuar commented Apr 17, 2020

thanks! it works.

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