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

Repro changes for Swift/Objc Interop #1174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yongjincho92
Copy link

This PR contains changes that reproduce the Swift Objc interop issue we observe in our codebase. I was able to make a repro within rules_swift example directory.

Notes :

  • We pass "-fmodules" copt to all objc_library targets in our codebase.
  • I added a Renderer (swift_library) which defines a public protocol that conforms to NSObjectProtocol
  • Imported Renderer from existing swift_library Printer.
  • Ran command to build main.m : bazelisk build examples/apple/objc_interop:main -s --disk_cache=""

Expected outcome :
Compilation succeeds

Actual outcome :
Compilation failure

ERROR: /Users/ycho/Snapchat/Dev/rules_swift/examples/apple/objc_interop/BUILD:36:13: Compiling examples/apple/objc_interop/main.m failed: (Exit 1): wrapped_clang failed: error executing ObjcCompile command (from target //examples/apple/objc_interop:main) external/apple_support~1.13.0~apple_cc_configure_extension~local_config_apple_cc/wrapped_clang -target arm64-apple-macosx13.0 '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall ... (remaining 44 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from examples/apple/objc_interop/main.m:20:
bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/generated_header/Printer-Swift.h:279:9: fatal error: module 'Renderer' not found
@import Renderer;
 ~~~~~~~^~~~~~~~
1 error generated.

If I remove -fmodules copt from objc_library, I get the following error :

ERROR: /Users/ycho/Snapchat/Dev/rules_swift/examples/apple/objc_interop/BUILD:36:13: Compiling examples/apple/objc_interop/main.m failed: (Exit 1): wrapped_clang failed: error executing ObjcCompile command (from target //examples/apple/objc_interop:main) external/apple_support~1.13.0~apple_cc_configure_extension~local_config_apple_cc/wrapped_clang -target arm64-apple-macosx13.0 '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall ... (remaining 42 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from examples/apple/objc_interop/main.m:20:
bazel-out/darwin_arm64-fastbuild/bin/examples/apple/objc_interop/generated_header/Printer-Swift.h:313:78: error: cannot find protocol declaration for 'SnapRenderProtocol'
@interface OIPrinter (SWIFT_EXTENSION(examples_apple_objc_interop_Printer)) <SnapRenderProtocol>
                                                                             ^
1 error generated.

@yongjincho92 yongjincho92 changed the title repro interop Repro changes for Swift/Objc Interop Feb 26, 2024
@yongjincho92
Copy link
Author

@keith this is a repro I found while working on swift objc interop in our codebase. I wonder if this is a bug on swift generated header logic (-Swift.h) or we're using the interop in an unexpected way.

@keith
Copy link
Member

keith commented Mar 4, 2024

hrm. Unless something major changed I'm surprised others haven't reported this too. Seems to me like we need to be generating a pcm here that can be used by the objc compile.

@luispadron
Copy link
Contributor

I think folks are running into this today and it'd be great to document or fix if possible

From the Bazel slack I see this:

I also know rules_swift_package_manager had to work around this issue by creating custom modulemaps

@aaronsky
Copy link
Contributor

aaronsky commented Mar 4, 2024

If this is the same problem I'm thinking of, I was also running into this last week. I worked around it with a modified implementation of @thii's objc_module_map_config.bzl from rules_apple_line. I needed to customize it heavily to make it work for me, but this approach did help objc_library with module map discovery.

@luispadron
Copy link
Contributor

Have we checked if the newly merged aspect_hint feature helps here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants