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

M1 support #41

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

M1 support #41

wants to merge 9 commits into from

Conversation

jizoquval
Copy link

@jizoquval jizoquval commented Sep 2, 2021

Attention

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

Changed

  • new arm simulator targets: macosArm64, iosSimulatorArm64, watchosSimulatorArm64, tvosSimulatorArm64
  • kotlin version to 1.6.20
  • gradle 7.4.2

Fixed

  • desktop (arm64, x64, and x86) binaries need to be packed in a fat framworks building XCFramworks (Thanks to @luca992)

@netroy
Copy link
Contributor

netroy commented Oct 19, 2021

@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
Copy link

dstranz commented Oct 21, 2021

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
Copy link

batuypn commented Oct 22, 2021

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
Copy link

mqln commented Nov 9, 2021

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
Copy link

dstranz commented Nov 9, 2021

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
Copy link
Contributor

netroy commented Nov 12, 2021

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
Copy link
Contributor

netroy commented Nov 12, 2021

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
Copy link

dstranz commented Nov 22, 2021

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
Copy link

adamwaite commented Dec 2, 2021

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
Copy link
Author

@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
Copy link

JohNan commented Jan 20, 2022

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

@luca992
Copy link

luca992 commented Apr 26, 2022

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

@luca992
Copy link

luca992 commented Apr 27, 2022

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
Copy link

luca992 commented Apr 28, 2022

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
Copy link

luca992 commented Apr 29, 2022

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
Copy link

luca992 commented Apr 29, 2022

@jizoquval jizoquval#2 made a PR for your PR 😅

@jizoquval
Copy link
Author

@luca992 Thanks, I will look at it tomorrow!

Entry META-INF/gradle-plugins/com.chromaticnoise.multiplatform-swiftpackage.properties is a duplicate but no duplicate handling strategy has been set.
@markst
Copy link

markst commented May 5, 2022

Works great here!:

image

if (targets.isNotEmpty()) {
val buildType = if (targets[0].linkTask.name.contains("Release")) "release" else "debug"
baseName = configuration.packageName.value
destinationDir = buildDir.resolve("bin/iosSimulatorUniversal/${buildType}Framework")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible this isn't honouring multiplatformSwiftPackage.outputDirectory?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error: the path does not point to a valid framework: xxxx/build/bin/iosSimulatorUniversal/releaseFramework/xxx.framework

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I touched anything that would affect outputDirectory. The intermediate build binaries stored in bin shouldn't affect outputDirectory?

How did you cause that error?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luca992 I can provide example gradle file. Version 2.0.3 succeeds. But it seems this fork is generating the intermediate framework with the wrong filename. The output appears to be our manifest package name rather than defined baseName.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only seems to be the case for iosSimulatorUniversal. Resolution to succeed build is to label baseName the same as our manifest package name. But this means the wrong framework name for imports.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @jizoquval will take a look this week

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haven't been able to test changes yet. gave up trying to use checked out version. might it be possible to make another release on your repository @luca992 ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. I'll do that today

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markst try my new build 2.0.5-arm64

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @luca992. @jizoquval those changes seems to have fixed the issue!

@jacao
Copy link

jacao commented May 24, 2022

+1 on this issue

@lazar-otasevic-cif
Copy link

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

@luca992
Copy link

luca992 commented Jun 29, 2022

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
Copy link

markst commented Jun 29, 2022

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
Copy link

luca992 commented Jun 29, 2022

@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
Copy link

luca992 commented Jun 29, 2022

Yeah. Gradle resolved it for me. Just tried

@lazar-otasevic-cif
Copy link

its working! thanks

@Nebneb
Copy link

Nebneb commented Aug 31, 2022

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
Copy link

luca992 commented Aug 31, 2022

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
Copy link

muellnes commented Oct 1, 2022

@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
Copy link

luca992 commented Nov 16, 2022

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
Copy link

luca992 commented Jan 9, 2023

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
Copy link

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 its Info.plist file

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

But here's the project .

@luca992
Copy link

luca992 commented Feb 26, 2023

@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
Copy link

@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
Copy link

luca992 commented Feb 26, 2023

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

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

@LukeSmith16
Copy link

@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
Copy link

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

@luca992
Copy link

luca992 commented Jun 8, 2023

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:
#41 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet