Skip to content

Conversation

Munzey
Copy link
Contributor

@Munzey Munzey commented Jul 3, 2020

Note: the ios() target is a shortcut to create targets for iosArm64(since ios11 all apps must be 64 bit) and iosX64(simulator) that will have any code in commonMain be depended on for code residing in iosMain.
See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#target-shortcuts for details.

Note regarding publishing: the iOS artifacts must be compiled and deployed/published on a machine running macOS with full Xcode installed. see https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#using-kotlinnative-targets

Note:the ios target is a shortcut to create targets for iosArm64 and iosX64 that will have any code in common main be depended on for code living in iosMain.
See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#target-shortcuts

Second note: the iOS artifacts must be compiled and deployed on a machine running macOS with full Xcode installed.
@Munzey
Copy link
Contributor Author

Munzey commented Jul 3, 2020

also just occurred to me, @michaelbull do you think it would be handy to add a section to the readme advertising that the lib is mpp-friendly?

@michaelbull
Copy link
Owner

the iOS artifacts must be compiled and deployed/published on a machine running macOS with full Xcode installed.

This is going to be problematic. Right now the published artifacts are built on my local PC (Fedora 31). The CI itself doesn't publish the packages, as they are signed with my GPG key. Not sure how to get around this.

@Munzey
Copy link
Contributor Author

Munzey commented Jul 10, 2020

oof yep that's gonna make this tricky.
I would volunteer (macbook pro) but not sure how big a pain that would be to try to give me access rights to publish it.
I guess other option is to borrow one, or find a used mac mini for sale or something 😅

@Munzey
Copy link
Contributor Author

Munzey commented Jul 17, 2020

ok there is one more option - rent a macos server: https://checkout.macincloud.com

looks like they do a prepaid 30$ for 30 hours plan, or 20$ to rent for a month 🤷

@Munzey
Copy link
Contributor Author

Munzey commented Jul 20, 2020

could also be handy to get it added to this list: https://github.com/AAkira/Kotlin-Multiplatform-Libraries

@william-reed
Copy link

any updates on working something out for this? this is a blocker for me right now since I can't use it in my multiplatform project

@michaelbull
Copy link
Owner

No viable solutions have been proposed yet so unfortunately not

@yshrsmz
Copy link

yshrsmz commented Nov 20, 2020

About CI and deployment, GitHub Actions offers macOS environment.

@Munzey
Copy link
Contributor Author

Munzey commented Nov 20, 2020

About CI and deployment, GitHub Actions offers macOS environment.

that's pretty cool! so It would be free for this repository: https://docs.github.com/en/free-pro-team@latest/github/setting-up-and-managing-billing-and-payments-on-github/about-billing-for-github-actions#about-billing-for-github-actions

interestingly for macOS though the time is multiplied by ten - which sounds more than enough if we set up a plan only for the master branch for publishing - 200 mins a month sounds plenty.

@Munzey
Copy link
Contributor Author

Munzey commented Nov 20, 2020

ah actually maybe this wont work - if we need to install xcode in the environment, that would immediately exceed the limit for a free account (approx 12gbs):

The storage used by a repository is the total storage used by GitHub Actions artifacts and GitHub Packages

I think we'd need to run an action like: https://github.com/marketplace/actions/setup-xcode
so this would stop us going this direction.
EDIT: not true, see latest comment.

On a side note, the original link I posted regarding needing full xcode installed is no longer there. It seems a lot of the documentation around the multiplatform plugin has been shuffled around.

If we only needed the command line tools (approx 120mbs), then this would be viable

@Munzey
Copy link
Contributor Author

Munzey commented Nov 20, 2020

so turns out xcode comes preinstalled on the github action macos images 🤦
https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11.0-Readme.md

so looks like this should be a good option!

Ill update this pr once #37 and #36 are merged

@michaelbull
Copy link
Owner

Can we somehow get the artifacts off of the machine that builds them? Ultimately they need signing before going onto maven central

@william-reed
Copy link

william-reed commented Nov 20, 2020 via email

@Munzey
Copy link
Contributor Author

Munzey commented Nov 20, 2020

yep looks like there is this handy action: https://github.com/marketplace/actions/upload-a-build-artifact

they have a page on general stuff about artifacts too: https://docs.github.com/en/free-pro-team@latest/actions/guides/storing-workflow-data-as-artifacts

@msfjarvis
Copy link

yep looks like there is this handy action: https://github.com/marketplace/actions/upload-a-build-artifact

There's an official action here.

@msfjarvis
Copy link

Usage is pretty simple as well, you can see a live example here which is used to upload JUnit results when CI fails.

@yshrsmz
Copy link

yshrsmz commented Nov 20, 2020

I can't paste a link now but iirc sqldelight does signing and deployment with GitHub Actions

@william-reed
Copy link

I can't paste a link now but iirc sqldelight does signing and deployment with GitHub Actions

I believe @michaelbull needs to sign them manually since he uses his GPG key.

also if you can get this working on multiplatform, I believe this will be the first library to support it. Even the experimental kotlin.Result has bugs on multiplatform

@michaelbull
Copy link
Owner

I believe @michaelbull needs to sign them manually since he uses his GPG key.

Yeah so fundamentally right I am building releases on my local PC and using a GPG key (yubikey) to sign them. I would like to continue to do this because it removes any possibility of somebody hijacking my GitHub account and pushing a malicious release to maven central, which is a possibility if I put my GPG key somewhere in the repo itself and achieve CD.

@Munzey
Copy link
Contributor Author

Munzey commented Nov 30, 2020

this is ready to merge again

@mayankmkh
Copy link

Any updates on this? I really want to use this library in KMM project.

@michaelbull
Copy link
Owner

Hi @mayankmkh. I think somebody suggested using github actions for building the artifacts on iOS, which was a potential solution, but no progress has been made on that yet. This is a prerequisite for them to be signed and uploaded to maven central, so as soon as that part of the puzzle is solved we should be good to go I think? Others in this thread may remember something I've forgotten though.

@mayankmkh
Copy link

mayankmkh commented Jan 18, 2021

Hi @michaelbull. I looked into Github Actions and as suggested in the comments above it should work. GPG signature file can be added as Github Secret and used inside the Github Action Workflow. There is an option to manually trigger the Workflow which accepts input and can be triggered from within Github or from an API call. For additional security, instead of saving the GPG key password in Secrets, the password can be passed as an input.
I don't have much experience with Github Actions so maybe others can give some more insight.

Edit: https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow

@michaelbull
Copy link
Owner

I've implemented the necessary GitHub action to automate deployments going forward. As you can see it's successfully publishing the JS artifacts now, so the missing piece going forward is for us to configure this job in the workflow to also run on macOS as well as ubuntu, at which point we can compile these artifacts and they will be automatically signed and published.

If somebody can finish that last piece off we can close this issue down and be a true MPP.

@Munzey
Copy link
Contributor Author

Munzey commented Feb 1, 2021

@michaelbull nice work!
Ive pushed what I believe is the small required change - from reading the github action doc and into the actions in use, it seems the only necessary step was to move the publish job to a macos environment. Other than that, I believe this should mean we are good to go! 🚀

@mayankmkh
Copy link

Great work! 🚀 @michaelbull @Munzey
I also looked into some open-source multiplatform libraries, and all of them are using macOS image to publish them with exception of Linux and Windows artifacts. Some examples

@Munzey I don't know if runs-on is case sensitive or not but Github suggests using macos-latest

@Munzey
Copy link
Contributor Author

Munzey commented Feb 1, 2021

I actually copied that casing from the splitties project 😅

@michaelbull
Copy link
Owner

e: /Users/runner/work/kotlin-result/kotlin-result/kotlin-result-coroutines/src/commonTest/kotlin/com.github.michaelbull.result.coroutines/RunBlockingTest.kt: (11, 12): Expected function 'runBlockingTest' has no actual declaration in module <com.michael-bull.kotlin-result:kotlin-result-coroutines_test> for Native
> Task :kotlin-result-coroutines:compileTestKotlinIosX64 FAILED

@michaelbull
Copy link
Owner

@Munzey the iOS tests are failing because of a missing runBlockingTest declaration. Also I guess people are going to want windows artifacts as soon as we get the mac ones working, so maybe we should bite the bullet ahead of time and get that working in the same PR. We should probably be conditionally publishing the macOS artifacts when building on mac, and the windows ones on windows, etc.

This article on the subject looks useful.

@Munzey
Copy link
Contributor Author

Munzey commented Feb 5, 2021

sorry yes will try take a look at this over next couple days 😓

@Munzey
Copy link
Contributor Author

Munzey commented Feb 8, 2021

@michaelbull should be working now.

Wanted to mention that I'm not sure as a library whether we should be offering the multithreaded branch of coroutines to support multi threaded coroutines for iOS due to:

The current version of kotlinx.coroutines, which can be used for iOS, supports usage only in a single thread. You cannot send work to other threads by changing a dispatcher.

To switch the dependency we would just add-native-mt as listed here:
https://kotlinlang.org/docs/mobile/concurrency-and-coroutines.html#multithreaded-coroutines

However I'm not sure if that would be problematic downstream.

Also had a look at that doc for using matrix with build jobs - without showing a full script I found it kinda confusing how to get the yaml to not complain. I found splitties workflows to be a lot easier to follow: https://github.com/LouisCAD/Splitties/tree/main/.github/workflows

Either way, I think that's a larger change outside the scope of this pr (also I'd rather not commit that as I don't have access to the workflow to test it).

@mayankmkh
Copy link

@Munzey I think the non-multithreaded version should be used in the library as mentioned in the link provided by you.

Because the main version of kotlinx.coroutines is a single-threaded one, libraries will almost certainly rely on this version.

Also, user can simply override the dependency (mentioned in the link) as

implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2-native-mt"){
    version {
        strictly("1.4.2-native-mt")
    }
}

How about adding this to README?

@michaelbull As many use cases for multiplatform targets mobile-only, maybe we can have a separate PR for other platforms?

@michaelbull
Copy link
Owner

michaelbull commented Feb 10, 2021

Looks like it's working

There are two bits of follow on work before I want to consider making a release for this. We need to use a matrix of build targets, because right now the macOS build is taking 8 minutes just to run ./gradlew check, which is rather unacceptable.

Ideally we would:

  • Run the cross-platform tests (i.e. ./gradlew check) on ubuntu
  • Run only the iOS tests on macOS
  • Publish the JVM artifacts on ubuntu
  • Publish only the iOS artifacts on macOS

@Munzey
Copy link
Contributor Author

Munzey commented Feb 10, 2021

@mayankmkh regarding the multi threading I think then maybe best to just leave as is, wait and see if someone encounters a problem with async behaviour on ios before attempting to change anything or document this. At least we are aware of the potential issue.

Other than that, any volunteers to cleanup the github actions script so we can get a release going?

@michaelbull
Copy link
Owner

michaelbull commented Feb 10, 2021

I've got the cross platform tests running on ubuntu now and the iosX64Test task running on macOS, so that should help speed it up. If people want other platforms, they can adapt the workflow and added the necessary build targets in a separate PR.

@avently
Copy link
Contributor

avently commented Mar 24, 2021

@Munzey @michaelbull could you, please, support LinuxX64, MingwX64 and MacosX64 as well?
Adapting native target and a build error guided me here

@michaelbull
Copy link
Owner

@avently we're open to pull requests to add other platforms - there are links in this issue's comments to help anyone that wants to pick that bit of work up

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.

7 participants