ge-org / multiplatform-swiftpackage

Gradle plugin that generates a Swift Package Manager manifest and an XCFramework to distribute a Kotlin Multiplatform library for Apple platforms.
Apache License 2.0
333 stars 49 forks source link

M1 support #41

Open jizoquval opened 2 years ago

jizoquval commented 2 years ago

Attention

This repo is not maintained anymore. Please use @luca992 fork.

Changed

Fixed

netroy commented 2 years ago

@ge-org can we please have this merged and released? it would unblock a bunch of us who want to start either building KMP for arm64, or simply want debug symbols when debugging an iOS app on a device (instead of of the simulator). I suppose it'd also unblock people who want to debug on the simulator on an M1 mac.

dstranz commented 2 years ago

Hello @jizoquval, thank you for you work. I'm testing your change but it doesn't seem to work with my project.

I have following configuration:

multiplatformSwiftPackage {
    packageName("MyProject")
    swiftToolsVersion("5.3")
    buildConfiguration { release() }
    targetPlatforms {
        iOS { v("13") }
    }
    outputDirectory(File(projectDir, "build/xcframework"))
}

And then run:

./gradlew :MyProject:createXCFramework

But created XCFramework doesn't have arm64-simulator architecture.

ls MyProject/build/xcframework/MyProject.xcframework
Info.plist           ios-arm64            ios-x86_64-simulator

I'm using Kotlin 1.5.30 and Gradle 7.2.

batuypn commented 2 years ago

Hi @dstranz, I think you need to add iosSimulatorArm64() target in your build.gradle like here. But also the dependencies used in the project should have support for arm64 (for example, currently ktor doesnt have).

mqln commented 2 years ago

Hello, @ge-org ! Any luck on this? My team needs M1 support, so we're deciding if we should just add it ourselves and fork the repo here.

dstranz commented 2 years ago

Hello, @dstranz! Any luck on this? My team needs M1 support, so we're deciding if we should just add it ourselves and fork the repo here.

Hello 👋🏻

I'm also waiting for merging M1 support to released version of this Gradle plugin.

Maybe you should ask project owner about future plans for this task?

netroy commented 2 years ago

I managed to get this working by uploading a built jar to our internal maven repo. But the createXCFramework task now fails with

Both 'ios-arm64-simulator' and 'ios-x86_64-simulator' represent two equivalent library definitions.

I see that this is coming from xcodebuild, and not this plugin. But, does anyone with more xcode experience know if I'm doing anything wrong?

netroy commented 2 years ago

I also noticed that iosArm64 and iosX64 builds in the build folder contain both a debugFramework as well as a releaseFramework. But, iosSimulatorArm64 only has a releaseFramework.

this is how I've enabled ios builds in my gradle file:

kotlin {
  ....
  listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
  ).forEach {
    it.binaries.framework {
      ....
    }
  }
  ....
}

How can I get the debugFramework for iosSimulatorArm64? I assume I need that to be able to see compile and debug any app using this xcframework.

dstranz commented 2 years ago

I've just see that there is a new JetBrains plugin for creating XCFramework. That maybe a good replacement for this plugin. It Gradle configuration looks like that in new created project:

import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

kotlin {
    android()

    val xcf = XCFramework()
    listOf(
        iosX64(),
        iosArm64(),
        //iosSimulatorArm64() sure all ios dependencies support this target
    ).forEach {
        it.binaries.framework {
            baseName = "MyLibrary"
            xcf.add(this)
        }
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
            }
        }
        val iosX64Main by getting
        val iosArm64Main by getting
        //val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            //iosSimulatorArm64Main.dependsOn(this)
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        //val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            //iosSimulatorArm64Test.dependsOn(this)
        }
    }
}

android {
    compileSdk = 31
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 21
        targetSdk = 31
    }
}
adamwaite commented 2 years ago

Thanks @dstranz. With this new plugin, where is the generated framework after running a ./gradlew build? I see frameworks in bin and fat-framework but no idea which to use.

jizoquval commented 2 years ago

@adamwaite Under the build folder you will have fat-framework and XCFrameworks. XCFrameworks/release is exactly what you need.

This is my setup

    val xcf = XCFramework("YourLibName")
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { target ->
        target.binaries.framework {
            baseName = "YourLibName"
            xcf.add(this)
        }
    }

    sourceSets {
        val commonMain by getting
        val androidMain by getting
        val androidTest by getting 
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
    }

And you can build it using next gradle command: ./gradlew shared:assembleYourLibNameXCFramework

JohNan commented 2 years ago

@ge-org What's stopping from merging this?

luca992 commented 2 years ago

Has anyone published the fork of this PR, are they are not maintaining this anymore?

luca992 commented 2 years ago

Forked this pr and published it here 👍 settings.gradle:

pluginManagement {
    repositories {
        maven ("https://s01.oss.sonatype.org/content/repositories/releases/")
    }
}
id("io.github.luca992.multiplatform-swiftpackage") version "2.0.3-arm64"
luca992 commented 2 years ago

So turns out there's a few issues with this pr. I'm running into this issue: https://developer.apple.com/forums/thread/666335

Before making an XCFramwork: macos (including simulators) arm64, x64, and x86 binaries need to be packed in a fat framework 🙃

I'm gonna make a pr for your fork to include the fixes @jizoquval

luca992 commented 2 years ago

Working build:

pluginManagement {
    repositories {
        maven ("https://s01.oss.sonatype.org/content/repositories/releases/")
    }
}
id("io.github.luca992.multiplatform-swiftpackage") version "2.0.4-arm64"
luca992 commented 2 years ago

@jizoquval https://github.com/jizoquval/multiplatform-swiftpackage/pull/2 made a PR for your PR 😅

jizoquval commented 2 years ago

@luca992 Thanks, I will look at it tomorrow!

markst commented 2 years ago

Works great here!:

image
jacao commented 2 years ago

+1 on this issue

lazar-otasevic-cif commented 2 years ago

how can i use this fork since the original one is abandoned?

luca992 commented 2 years ago

Created a new release with the latest changes for this pr:

pluginManagement {
    repositories {
        maven ("https://s01.oss.sonatype.org/content/repositories/releases/")
    }
}
id("io.github.luca992.multiplatform-swiftpackage") version "2.0.5-arm64"
markst commented 2 years ago

thanks @luca992 . can't seem to use it yet:

  • Plugin Repositories (could not resolve plugin artifact 'io.github.luca992.multiplatform-swiftpackage:io.github.luca992.multiplatform-swiftpackage.gradle.plugin:2.0.5-arm64')
luca992 commented 2 years ago

@markst If you tried immediately it probably wasn't indexed yet. Should be up now I think: https://repo1.maven.org/maven2/io/github/luca992/multiplatform-swiftpackage/io.github.luca992.multiplatform-swiftpackage.gradle.plugin/

luca992 commented 2 years ago

Yeah. Gradle resolved it for me. Just tried

lazar-otasevic-cif commented 2 years ago

its working! thanks

Nebneb commented 1 year ago

Hi there, any news on this PR?

I do experiment this issue and the fix @luca992 provided is working fine on my side, but it is still a little bit hacky to use a fork for this fix instead of an approved release.

luca992 commented 1 year ago

Hi there, any news on this PR?

I do experiment this issue and the fix @luca992 provided is working fine on my side, but it is still a little bit hacky to use a fork for this fix instead of an approved release.

Idk not up to me 🤷‍♂️.

Ps. The macos fat framework workaround can now be removed on kotlin 1.8 dev builds and be ported over to how the fat frameworks are being generated for the other targets. https://youtrack.jetbrains.com/issue/KT-47355/Support-macos-target-for-FatFramework-task

muellnes commented 1 year ago

@luca992 changes are working also fine on my side. So what is still the issue with integrating the changes? Does someone need to make the Travis CI job happy?

luca992 commented 1 year ago

Kotlin 1.8.0-beta is out. That macOs fat framework workaround now could probably be removed now to match all the other targets.

luca992 commented 1 year ago

They clearly aren't maintaining this. I updated my fork with a new release using kotlin 1.8.0 that removes my hacky macOs fat framework workaround. I don't see the point in submitting more pr updates here until someone responds, and I will just maintain my own fork 🙃.

// build.gradle.kts
plugins {
  // projects targting kotlin >=1.8.0
  id("io.github.luca992.multiplatform-swiftpackage") version "2.1.4"
  // projects targting kotlin <1.8.0
  id("io.github.luca992.multiplatform-swiftpackage") version "2.0.5-arm64"
}
LukeSmith16 commented 1 year ago

Hey @luca992 - Just playing around with your fork on a new project. After running gradlew createSwiftPackage and then fetching the package remotely in my xcode project i'm getting this error: Missing path (/Users/.../Library/Developer/Xcode/DerivedData/project/SourcePackages/checkouts/kmmtest/shared.xcframework/ios-arm64_x86_64-simulator/dSYMs) from XCFramework 'shared.xcframework' as defined by 'DebugSymbolsPath' in itsInfo.plistfile

I'm not sure if this directly relates to your fork.

But here's the project .

luca992 commented 1 year ago

@LukeSmith16 yeah idk off hand. I'll take a look.

One thing to note... Sometimes I have to run createSwiftPackage twice, as the first run sometimes doesn't generate all the files. I'm not sure why exactly, or even if my fork's changes are to blame. I haven't had time to look into it yet. Maybe try that, and see if that helps?

LukeSmith16 commented 1 year ago

@luca992 Thanks for the reply! Yeah so if i drag the package locally into xcode it works fine. It's just when i fetch it remotely it can't locate the dsyms. I thought this could have been .gitignore not including the dsym files, but it's not 😢 - I will keep trying to figure out why this isn't working for me but maybe i think it's not related to your fork as it's working locally fine.

luca992 commented 1 year ago

@LukeSmith16 you didn't check-in the files in the dsyms folders.

My project for reference: https://github.com/eqoty-labs/secretk

LukeSmith16 commented 1 year ago

@luca992 Yeah i'm having to check those dsym files in manually at the moment. I don't know why GIT isn't picking them up 🤔 - But yeah i got it working after manually checking them in, thanks for the help 👍

SamvelDev commented 1 year ago

Hey dear, I still don't understand if this problem is solved or not, I still have a problem ((( please help me @jizoquval @

luca992 commented 1 year ago

Hey dear, I still don't understand if this problem is solved or not, I still have a problem ((( please help me @jizoquval @

should be working with my fork: https://github.com/ge-org/multiplatform-swiftpackage/pull/41#issuecomment-1376051526