tuist / tuist

Tuist's CLI
https://tuist.io
MIT License
4.51k stars 537 forks source link

SPM external dependency of Realm fails to build #3928

Closed jmbene closed 7 months ago

jmbene commented 2 years ago

Describe the bug I’m having problems with version 2.0 of Tuist and the Realm dependency when I’m trying to add a SPM dependency in the new Dependencies.swift file. If I fetch the dependencies and then try to warm the cache I receive the following error:

$ tuist cache warm
Resolved cache profile 'Development' from Tuist's defaults
Generating workspace Tuist2.xcworkspace
Generating project Tuist2
Generating project RealmDatabase
Generating project Realm
Hashing cacheable targets
Targets to be cached: Bid, ObjectStore, Realm, Storage, SyncClient, Tuist2Kit, Tuist2UI
Filtering cacheable targets
Generating workspace Tuist2.xcworkspace
Generating project Tuist2
Generating project Realm
Generating project RealmDatabase
Building cacheable targets
** BUILD FAILED **

The following build commands failed:
    CompileC /Users/user/Library/Developer/Xcode/DerivedData/Tuist2-ghwkelueyzdckhgvykcnxryadssl/Build/Intermediates.noindex/RealmDatabase.build/Debug-iphonesimulator/Storage.build/Objects-normal/x86_64/version.o /Users/josemiguel.benedicto/Downloads/tuist2/Tuist/Dependencies/SwiftPackageManager/.build/checkouts/realm-core/src/realm/version.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'Storage' from project 'RealmDatabase')
(1 failure)
[Storage] Compiling version.cpp
❌ /Users/user/Downloads/tuist2/Tuist/Dependencies/SwiftPackageManager/.build/checkouts/realm-core/src/realm/version.cpp:35:5: non-void function 'get_extra' should return a value [-Wreturn-type]
    return REALM_VERSION_EXTRA;
    ^

If I generate the project, focus in the app target and build it without warming the cache I receive the same error:

❌ /Users/user/Documents/workspace/tuist2/Tuist/Dependencies/SwiftPackageManager/.build/checkouts/realm-core/src/realm/version.cpp:35:5: non-void function 'get_extra' should return a value [-Wreturn-type]
    return REALM_VERSION_EXTRA;
    ^

The following build commands failed:
    CompileC /Users/user/Library/Developer/Xcode/DerivedData/Tuist2-ghwkelueyzdckhgvykcnxryadssl/Build/Intermediates.noindex/RealmDatabase.build/Debug-iphonesimulator/Storage.build/Objects-normal/x86_64/version.o /Users/user/Downloads/tuist2/Tuist/Dependencies/SwiftPackageManager/.build/checkouts/realm-core/src/realm/version.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'Storage' from project 'RealmDatabase')
(1 failure)

To Reproduce Steps to reproduce the behavior:

I have a super small project that includes Realm dependency to reproduce the issue: tuist2.zip

Then follow these commands to warm the cache:

  1. tuist dependency fetch
  2. tuist cache warm

It is also replicable when generating and focusing the project and then building in Xcode:

  1. tuist dependency fetch
  2. tuist generate
  3. tuist focus Tuist2
  4. Run the Tuist2 target

Expected behavior The SPM package compiles

Screenshots N/A

Desktop (please complete the following information):

Additional context I suspect there are some issues relate wrong C++ dialect or some flags that aren't applied property or missing build settings when compiling.

luispadron commented 2 years ago

@danyf90 The Realm package has a lot CXX settings the Package.swift here. Would this be the cause of the build errors?

danieleformichelli commented 2 years ago

They should be handled by the mapping logic. Given the error is only on REALM_VERSION_EXTRA maybe it's empty and that case is not handled properly?

luispadron commented 2 years ago

@danyf90 Yah that looks like it may be the case there is the possibility it's empty as the package has some logic in there to determine if it's set or not

danieleformichelli commented 2 years ago

You can check the generated project and see if the variable is there

InViZz commented 2 years ago

any update?

adellibovi commented 2 years ago

hi @InViZz , we believe this got fixed in #3995 feel free to use the branch to try it out.

adellibovi commented 2 years ago

I am going to reopen, this, there is a HEADER_SEARCH_PATH which must inherit from Realm framework to compile correctly. There is a WIP at #4002. Currently Realm on its own will compile fine, but not when imported.

alexanderwe commented 2 years ago

We are currently also facing the issue with Realm. When we include an external SPM dependency that relies on Realm it fails to build. I already tried out the main branch of tuist and the issue still persists in the generated project.

Drag0ndust commented 2 years ago

is there any workaround which I can use until this problem is solved?

adellibovi commented 2 years ago

@Drag0ndust a part of the fix will be included in the next version (which probably will be released today in some hours), yet there will be the need of a second fix and it won't compile yet. But you may workaround this second issue by adding the correct HEADER_SEARCH_PATH

vexonius commented 2 years ago
Screenshot 2022-03-11 at 18 28 09

Hi guys, have you figured correct path for header paths? I tried many, but no luck...

Also, is there any updates for this issue? Thanks

danieleformichelli commented 2 years ago

@vexonius I think you need to add the HEADER_SEARCH_PATHS to the target depending on Realm (i.e. in the Project.swift), I'll try to add it to the app_with_spm_dependencies fixture if I find the time to try it :rocket:

av-ivashchenko-sigma commented 2 years ago

Hi @danyf90! Were you able to find some time trying to verify the workaround for the Realm integration issue?

lordcodes commented 2 years ago

@danyf90 It looks like the Project file that is generated for Realm is missing the 'Headers' build phase. If I compare it to another library that requires public header files the one generated by Tuist for that does have a Headers build phase, whereas the Project file for Realm has none on any of it's targets.

danieleformichelli commented 2 years ago

@lordcodes there is a "complex" logic to understand whether to define the headers as build phase or add them to the project search path that we are mimicking from SPM. It's possible that there is some problem there, but I think it's more likely that we just need to fix the header search paths of the targets depending on realm. There is a PR by @adellibovi introducing imparted settings that should go in that direction, but it still need some adjustments 🚀

lordcodes commented 2 years ago

@danyf90 As a test I altered the generated Realm project to add a Headers build phase, then added all the header files to it and it allowed it to get further, however, it failed at a later stage due to symbols and warnings about the header files not being in Realm.h umbrella header. I will have been hacking it to try and add the header files so likely did something wrong there.

Thanks for the information. For now I will move all my other SPM dependencies to use Dependencies.swift and will leave Realm using the previous approach for now.

danieleformichelli commented 2 years ago

Make sense, I hope we can solve this soon! 🤞

lordcodes commented 2 years ago

I see the exact thing I raised was discussed on that PR you linked to, concerning using the Headers build phase vs other approaches. Good to have the context.

amirthytejeshwar-sc commented 2 years ago

Hey can you please let us know if and when can we expect this to be resolved? Is there any plan regarding the same. Thanks!

luispadron commented 2 years ago

Folks, this is an open source project. I imagine the maintainers don't actively use Realm so it's not immediately something we can budget time for, it would be helpful to get a PR that adds a test for this / attempts a fix we can then review and help further

danieleformichelli commented 2 years ago

There is this open PR, but it still need some fixes before being ready. If anyone wants to contribute they are welcome!

kimxwan0319 commented 2 years ago

Is there any progress??

shvetsjr commented 1 year ago

Would be nice with some updates regarding this issue. Would love to help but I think I won't be able to :D

marciliojrs commented 1 year ago

I solved this issue by using a xcframework instead of SPM or Carthage.

danieleformichelli commented 1 year ago

I solved this issue by using a xcframework instead of SPM or Carthage.

@marciliojrs could you please elaborate on that (e.g. which xcframework have you used)?

marciliojrs commented 1 year ago

Apologies for my previous brief response, I was on a mobile device. So explaining a bit better... In the testing phase of migrating my project to Tuist, I encountered a several obstacles when trying to integrate Realm. Despite trying various Tuist and Realm versions, I was unable to get it to work as an SPM or Carthage dependency. So, to overcome this issue, I opted to store an xcframework version of Realm in an S3 bucket and download it to my local directory. This allowed me to use it as a local xcframework dependency in my project.

github-actions[bot] commented 1 year ago

Hola 👋,

We want to inform you that the issue has been marked as stale. This means that there hasn't been any activity or updates on it for quite some time, and it's possible that it may no longer be relevant or actionable. If you still believe that this issue is valid and requires attention, please provide an update or any additional information that can help us address it. Otherwise, we may consider closing it in the near future. Thank you for your understanding.

Jaeki-Lee commented 9 months ago

Anyone has solution for this?

pepicrft commented 8 months ago

Not yet @Jaeki-Lee

kapitoshka438 commented 8 months ago

@Jaeki-Lee @pepicrft I was able to solve this problem by passing these settings to the Project's SettingDictionary:

"HEADER_SEARCH_PATHS": [
    "$(SRCROOT)/Tuist/Dependencies/SwiftPackageManager/.build/checkouts/realm-swift/include",
    "$(inherited)"
]