apollographql / apollo-kotlin

:rocket:  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
https://www.apollographql.com/docs/kotlin
MIT License
3.76k stars 655 forks source link

Add support for watchosX64 #6261

Closed jeantuffier closed 4 hours ago

jeantuffier commented 6 days ago

Use case

I'm trying to share my logic with a Apple project targeting WatchOS. When adding watchosX64() to my project, the build fails because apollo only supports

watchosArm32()
watchosArm64()
watchosSimulatorArm64()

I can make xcode build the Watch Os target only if I choose the stand alone emulator and not the one saying "via Iphone". If I choose it, I get the following error:

No matching variant of com.apollographql.apollo:apollo-runtime:4.0.0 was found. The consumer was configured to find a library for use during 'kotlin-api', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_x64', attribute 'org.jetbrains.kotlin.platform.type' with value 'native' but:

Are there any limitations to not supporting it? If I try to build the ios app target on the iPhone simulator, I get the same error.

Describe the solution you'd like

Simply add watchosX64() to the supported targets

BoD commented 4 days ago

Hi!

For the record, watchosX64 is for the simulator on Intel Macs.

There is no particular reason why we don't include this target. Would you be interested in opening a pull request? Targets are handled in this file.

jeantuffier commented 2 days ago

Hi, that's strange then. I run my project on a MacBook Pro M1. Do you have any ideas why I would get this error? It might be I have other dependencies that supports it and somehow requires it from Apollo too

BoD commented 2 days ago

In your initial message you said you explicitly added the watchosX64 target to your project? If you actually don't need it you may omit it and this should solve the issue.

jeantuffier commented 1 day ago

I wasn't very clear and probably confused myself here, sorry. Let me try to explain better :

If I don't add the watchosX64 target to my project and only use those

listOf(
    iosArm64(),
    iosSimulatorArm64(),
    watchosArm64(),
    watchosSimulatorArm64(),
    tvosArm64(),
    tvosSimulatorArm64(),
)

I get the following error in xcode with any simulator :

Ignoring file '/path/to/my/mltiplatform/project/build/xcode-frameworks/Debug/watchsimulator10.5/MyProject.framework/MyProject': fat file missing arch 'x86_64', file has 'arm64' Linker command failed with exit code 1

Now if I add watchosX64 to my project to fix that issue, I obviously get

No matching variant of com.apollographql.apollo:apollo-runtime:4.0.0 was found. The consumer was configured to find a library for use during 'kotlin-metadata', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'watchos_x64'

I can make a PR of course but It might be there's something wrong with my project somewhere making xcode fail to compile it.

BoD commented 1 day ago

Thanks for following up!

Hmm yes indeed this is surprising, I don't see why XCode is complaining about x86_64 when you only have Arm64 targets in your project. And you're right that adding the target to Apollo Kotlin may not fix the issue. Are you able to make a simplified version of your project with the Apollo Kotlin dependency removed to compile and run?

jeantuffier commented 6 hours ago

Turned out xcode has a $(ARCHS_STANDARD) property set in Build Settings > Architectures > Architectures. It has different values depending on the target. For the watch target, it has arm64, X86_64 and some others. By replacing the property with a simple "arm64" it all work smoothly.

Thanks for the help and sorry I used your time for something completely unrelated to Apollo!

BoD commented 4 hours ago

TIL and no worries at all. Glad it works now.

github-actions[bot] commented 4 hours ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better.