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

Creating a module with New Architecture and including a .swift file introduces compiler errors #46212

Open
gtokman opened this issue Aug 26, 2024 · 11 comments
Labels
Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@gtokman
Copy link

gtokman commented Aug 26, 2024

Description

I'm upgrading one of our open-source libraries, which uses Swift for the logic. However, when I include swift in the podspec source_files, I get compiler errors.

Steps to reproduce

I'm running into compiler errors after updating the podspec for the module to include .swift files in the ios/ directory.

 s.source_files = "ios/**/*.{h,m,mm,cpp,swift}" <--- adding Swift

After building the development pod, I get this error:
Screenshot 2024-08-26 at 10 11 15 AM

I found a workaround by omitting the following:
1.

 s.source_files = "ios/**/*.{h,m,mm,cpp}" <--- remove swift
  1. run bundle exec pod install

  2. Add the .swift file manually

Screenshot 2024-08-26 at 10 18 12 AM

After building the project, there is no compiler error. This is fine for testing, but I need to update the podspec to include the file in the Compile Sources, otherwise, other errors will occur.

React Native Version

0.74.0

Affected Platforms

Runtime - iOS

Areas

TurboModule - The New Native Module System

Output of npx react-native info

System:
  OS: macOS 14.4.1
  CPU: (8) arm64 Apple M1
  Memory: 175.06 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.0
    path: ~/.nvm/versions/node/v18.18.0/bin/node
  Yarn:
    version: 3.6.4
    path: /opt/homebrew/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.0/bin/npm
  Watchman:
    version: 2024.04.15.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/gary/.rvm/gems/ruby-2.7.5/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    API Levels:
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
      - "34"
    Build Tools:
      - 28.0.3
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 32.1.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-32 | Google APIs ARM 64 v8a
      - android-32 | Google Play ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-Tiramisu | Google APIs ARM 64 v8a
    Android NDK: 22.1.7171670
IDEs:
  Android Studio: 2023.2 AI-232.10300.40.2321.11668458
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/gary/.rvm/rubies/ruby-2.7.5/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.2
    wanted: 0.75.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

n/a

Reproducer

https://github.com/candlefinance/oss/tree/feat-convert-send-na

Screenshots and Videos

No response

@gtokman gtokman added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Aug 26, 2024
@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.74.5. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Aug 26, 2024
@react-native-bot
Copy link
Collaborator

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:

@Rexogamer

This comment was marked as resolved.

@nullishamy
Copy link

@gtokman Seen you add labels, do you have permission to delete the comment above? Almost certainly malware

@Rexogamer

This comment was marked as resolved.

@cipolleschi
Copy link
Contributor

@gtokman thanks for the issue... A few points:

  1. Swift is not officially supported by the New Architecture. I know it's something big that is missing, but we don't have the resources to work on that at the moment. I hope that this will come soon.
  2. Swift and C++ does not really work well together. Yes, we have the Swift/Cxx interoperability but it is not complete sadly and I don't think it is stable enough to be used
  3. It looks like that your pod is failing before some swift file is trying to import the <memory> C++ module. That could also happen for transitive dependencies. Swift can't import C++ modules, hence the failure.

@gtokman
Copy link
Author

gtokman commented Aug 27, 2024

@cipolleschi, thanks for the context.

  1. It looks like that your pod is failing before some swift file is trying to import the <memory> C++ module. That could also happen for transitive dependencies. Swift can't import C++ modules, hence the failure.

I mentioned that I found a workaround. My thought was that a Build Setting was not being set correctly, which led to the pod failing to compile if I included Swift source_files. Do you have an idea of what would be different? I guess I can try to diff the .xcodeproj. of the generated vs. manually adding the file.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Aug 27, 2024
@cortinico cortinico removed the Needs: Attention Issues where the author has responded to feedback. label Aug 28, 2024
@cipolleschi
Copy link
Contributor

when you add the swift file manually, Xcode usually creates some bridging headers and extra configuration files.
We need to look into what is generated to see how Xcode resolve the issue and then "commit" those files into the library.

I can see if I can find some time to look into it, but it will likely happen in a couple of weeks as next week we have React Universe and I'll be in Poland for the Conference.

@gtokman
Copy link
Author

gtokman commented Aug 28, 2024

when you add the swift file manually, Xcode usually creates some bridging headers and extra configuration files. We need to look into what is generated to see how Xcode resolve the issue and then "commit" those files into the library.

I can see if I can find some time to look into it, but it will likely happen in a couple of weeks as next week we have React Universe and I'll be in Poland for the Conference.

Appreciate it @cipolleschi!

I do see the alert in Xcode for the bridging header, but I don't create it. Bridging headers are for Obj-C -> Swift. To use Swift -> Obj-C you just need to import the generated Swift headers i.e Send.swift -> #import "candlefinance_send-Swift.h".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

8 participants
@cortinico @cipolleschi @gtokman @react-native-bot @Rexogamer @nullishamy and others