Hello. Has anyone been able to successfully run `....
# multiplatform
m
Hello. Has anyone been able to successfully run
./gradlew iosSimulatorArm64Test
in GitHub Actions without any tests getting skipped? I have tests in
commonTest
and even if I intentionally make a test fail, it will appear to "pass" in CI but it's as if the tests are skipped. The reverse is true for
./gradlew iosX64Test
where it runs successfully in GitHub Actions (the test fails as expected) but gets skipped on my local dev machine (M1 Mac).
j
That seems to be exactly what I'd expect
h
iosX64 requires an Intel cpu, while iosArm64 requires an Apple Silicon (M1) cpu. Github uses Intel cpu, so these tests are skipped as expected.
j
You can't run an architecture on a different one without emulation
Also note that GitHub announced arm mac's are coming
But if you really need to test both architectures you'll need two jobs
m
Thank you for the clarification. I figured that's where things were headed. I was hoping to have some form of consistency where if a test fails in CI, developers can easily reproduce on their local machines and troubleshoot accordingly. We're just starting to dabble with KMM so this is all kinda new for us. 🙂
h
Yeah, Github arm support should come, but it was moved very often to the future: https://github.com/orgs/github/projects/4247?pane=issue&itemId=5944419
m
And by "us", I mean the Android team 😄
Thank you @jw and @hfhbd!
j
It should be rare that you have a failure in one architecture but not another
m
I was hoping to have some form of consistency where if a test fails in CI, developers can easily reproduce on their local machines and troubleshoot accordingly.
One solution my teammate suggested was to have a custom
iosTest
task that acts as an alias for either
iosX64Test
if running in CI or
iosSimulatorArm64Test
if not.
j
If you are using hierarchical source sets that task already exists and will run both, and then only one will actually run
m
Oh sweet! I'll check it out.
So I'm following the Kotlin Gradle snippet from https://kotlinlang.org/docs/multiplatform-hierarchy.html#target-shortcuts-and-arm64-apple-silicon-simulators, but when I try to run the
iosTest
task, I get the error indicating that that task does not exist
Copy code
* What went wrong:
Task 'iosTest' not found in root project '*****' and its subprojects. Some candidates are: 'iosX64Test', 'jvmTest', 'test'.
When I run the
tasks
task on one of my KMM modules, the only tasks that show up under
Verification tasks
are
Copy code
Verification tasks
------------------
allTests - Runs the tests for all targets and create aggregated report
check - Runs all checks.
iosSimulatorArm64Test - Executes Kotlin/Native unit tests for target iosSimulatorArm64.
iosX64Test - Executes Kotlin/Native unit tests for target iosX64.
jvmTest - Runs the tests of the test test run.
h
ios() doesn’t contain the simulator target, you have to add this target manually.
m
Correct. From the snippet in the link I referenced above, it explicitly adds
iosSimulatorArm64()
below
ios()
. Which is what I'm also doing.
h
Okay, but you need to add it to the source set hierarchy manually too.
j
You'll want to use the new natural hierarchy DSL if you can
it shipped in 1.8.20
m
Ah, okay. I'm still on 1.8.10.
h
I guess this experimental function isn’t documented well 😐
j
you can always build it up yourself manually
m
FWIW, here is my configuration
Copy code
kotlin {
  applyKotlinMultiplatformConfiguration() // This just setting explicit API mode

  ios()
  // Add the ARM64 simulator target
  iosSimulatorArm64()

  val iosMain by sourceSets.getting
  val iosTest by sourceSets.getting
  val iosSimulatorArm64Main by sourceSets.getting
  val iosSimulatorArm64Test by sourceSets.getting

  // Set up dependencies between the source sets
  iosSimulatorArm64Main.dependsOn(iosMain)
  iosSimulatorArm64Test.dependsOn(iosTest)
}
h
This looks correct and should work 🤔
m
Meaning an
iosTest
Gradle task should exist yes?
The `iosTest`/`iosMain` source sets work as expected. It's just that as far as the test tasks that are available, I only see
iosSimulatorArm64Test
and
iosX64Test
as the specific test tasks that pertain to iOS.
Another approach was to create a custom
iosTest
task like so
Copy code
tasks.register("iosTest") {
  group = "Verification"
  description = "An alias for iosX64Test if running in CI; otherwise iosSimulatorArm64Test."
  dependsOn(
      // GitHub Actions uses Intel CPU in their Mac images. Trying to run iosSimulatorArm64Test
      // (arm64 tests) in CI results in the tests silently getting skippped rather than the build
      // failing. The reverse is true for our dev machines (assuming M1 chip) where tests from
      // iosX64Test get silently skipped.
      if (System.getenv("CI") != null) {
        "iosX64Test"
      } else {
        "iosSimulatorArm64Test"
      })
}
This appears to be working for me and there is no task name clash.
h
This definitely works, but afaik there should be a predefined task.
m
I'll keep digging. Thanks for the help 🙂
147 Views