esensar / kotlinx-serialization-msgpack

MsgPack support for kotlinx.serialization -- msgpack.org[kotlinx.serialization]
https://www.ensarsarajcic.com/kotlinx-serialization-msgpack/
MIT License
44 stars 9 forks source link

Add ios target support #40

Closed makindotcc closed 3 years ago

makindotcc commented 3 years ago

Dunno if this is 100% correct as it's my first days with kotlin multiplatform, but it compiles! also basic serialization on ios seems to work.

esensar commented 3 years ago

Hello @makindotcc :wave:

Thank you for your contribution. I don't think that library needs to have ios defined as a target for the library to work on iOS. All code is supported on all platforms, since it is using only common source set. Other targets are defined only for testing purposes. This would only be needed if we wanted to run iOS specific tests for the library, which is not required I think.

Let me know if you run into issues using library this way. I believe you should be able to just add this library to your multiplatform project as instructed in README:

implementation("com.ensarsarajcic.kotlinx:serialization-msgpack:${kotlinxSerializationMsgPackVersion}")

And you should be able to target iOS without any issues in your multiplatform project.

makindotcc commented 3 years ago

Hello 👋

When I try to use main version, like that:

        val commonMain by getting {
            dependencies {
                implementation("com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0")
            }
        }

then I get following errors:

❯ ./gradlew build

[...]

> Task :shared:compileKotlinIos FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared:compileKotlinIos'.
> Could not resolve all files for configuration ':shared:iosCompileKlibraries'.
   > Could not resolve com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0.
     Required by:
         project :shared
      > No matching variant of com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 was found. The consumer was configured to find a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64' but:
          - Variant 'js-api' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares a usage of 'kotlin-api' of a component:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'js-runtime' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0:
              - Incompatible because this component declares a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'jvm-api' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares an API of a component:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'jvm-runtime' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'metadata-api' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares a usage of 'kotlin-api' of a component:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_x64')
          - Variant 'native-api' capability com.ensarsarajcic.kotlinx:serialization-msgpack:0.2.0 declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64'

[...]

I saw, like you said, that the library is based only on "common" source set, so maybe there is a better way to add support for all targets instead of adding every target manually?

esensar commented 3 years ago

I think you are right... Looking at kotlinx-serialization, it seems all targets are added manually: https://github.com/Kotlin/kotlinx.serialization/blob/master/gradle/native-targets.gradle

esensar commented 3 years ago

Thank you once again for your contribution @makindotcc. This should be available in version 0.2.1. Can you confirm it is working as expected?

makindotcc commented 3 years ago

Yes, it works as expected ❤️. Thank you and have a nice day. Working serialization on iOS