https://kotlinlang.org logo
k

Konstantin Petrukhnov

10/30/2019, 5:17 AM
What are the current options for not implementing twice actual for ios arm/x64? I know it was mentioned multiple times in conversations during last few month. It is hard to dig through search and comments in slack.
Is there anything like sample below that works? configure(iosX64) { sourceSets.dependsOn iosArm64 }
a

alex009

10/30/2019, 5:43 AM
it allow not duplicate code and have gradle configs with both architectures enabled in same time. and IDE correct resolve all actuals
k

Konstantin Petrukhnov

10/30/2019, 5:53 AM
Does it work on Windows? E.g. building targets that are not related to ios, running jvm/common tests, etc?
a

alex009

10/30/2019, 5:58 AM
on windows symlink not same 😞 we use it just for ios, what not work on windows anyways, but for other targets symlinks not usefull i think
k

Konstantin Petrukhnov

10/30/2019, 6:02 AM
I mean if I use symlink for ios targets, will I be able to build and run tests for common/jvm targets on windows?
a

alex009

10/30/2019, 6:08 AM
yes. ios target disabled on windows as i know (but i not check self)
k

Konstantin Petrukhnov

10/30/2019, 6:18 AM
thx, i will try
m

Marc Reichelt

10/30/2019, 8:11 AM
I would recommend against symlinks because then something will go wrong on one platform. I’m trying to find out how we could define the same source set for both architectures in an easy way, so that way we have an answer for all new developers who want to go down that road
l

louiscad

10/30/2019, 10:35 AM
For now, symlinks and hitting cmd+S and cmd+option+Y is the best we got. This will no longer be necessary once HMPP (hierarchical multiplatform projects) is ready (should arrive in 1.3.70).
4
f

Fudge

10/30/2019, 11:06 AM
1.3.70? That’s exciting
k

Konstantin Petrukhnov

10/30/2019, 11:19 AM
@louiscad where i could find more about HMPP?
l

louiscad

10/30/2019, 11:19 AM
In youtrack.jetbrains.com since it's still under development @Konstantin Petrukhnov
k

Kris Wong

10/30/2019, 1:10 PM
i would recommend against symlinks for a few reasons
Copy code
targets.withType<KotlinNativeTarget> {
        compilations["main"].defaultSourceSet {
            dependsOn(sourceSets["iosMain"])
        }

        binaries.framework {
            baseName = "${project.extra["iosFrameworkName"]}"
        }
    }
a

alex009

10/30/2019, 1:30 PM
In this case IDE not recognize iosMain as iOS source set
k

Kris Wong

10/30/2019, 1:42 PM
you just need to name one of your iOS targets as "ios"
in this case
expect
in common code will be show warning "iosX64 have not `actual`" ?
k

Kris Wong

10/30/2019, 1:47 PM
not if you do it right
a

alex009

10/30/2019, 1:47 PM
when i try set two targets to one sourceset IDE show errors about one of
actual
where i can see "right" sample?) have you on github?
k

Kris Wong

10/30/2019, 1:50 PM
Copy code
kotlin {
    jvm()
    iosX64("ios")
    iosArm32("iosArm32")
    iosArm64("iosArm64")

    ...

    targets.withType<KotlinNativeTarget> {
        compilations.getByName("main") {
            defaultSourceSet {
                if (name != "iosMain") {
                    dependsOn(sourceSets["iosMain"])
                }
            }
        }
        binaries.framework {
            baseName = "${project.extra["iosFrameworkName"]}"
        }
    }
}
a

alex009

10/30/2019, 2:09 PM
Thx, I will check :)
k

Konstantin Petrukhnov

11/25/2019, 7:47 AM
It seems I was able to use snippet below to solve all all issues. • compiles • only one source folder • actual correctly highlighted in IDE • expect highlight that there is no impl for iosX64 (only class name) • (bonus) no need for "iosMain" target
Copy code
kotlin {

  sourceSets {

    ios {
            kotlin.srcDirs += project.file("src/iosMain/kotlin")
            dependencies {

            }
        }

    iosX64 {
      dependsOn ios
    }
  }

  targets {
        //ios real device
        iosArm64("ios")
        //ios simulator
        iosX64("iosX64")

        configure([ios, iosX64]) {
            compilations.getByName("main") {
                defaultSourceSet {
                    if (name != "ios") {
                        dependsOn(sourceSets["ios"])
                    }
                }
            }
        }
    }
}
And that will fail, if you need to specify separate dependencies for arm/simulator 😞
2 Views