What are the current options for not implementing ...
# multiplatform
k
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
it allow not duplicate code and have gradle configs with both architectures enabled in same time. and IDE correct resolve all actuals
k
Does it work on Windows? E.g. building targets that are not related to ios, running jvm/common tests, etc?
a
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
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
yes. ios target disabled on windows as i know (but i not check self)
k
thx, i will try
m
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
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
1.3.70? That’s exciting
k
@louiscad where i could find more about HMPP?
l
In youtrack.jetbrains.com since it's still under development @Konstantin Petrukhnov
k
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
In this case IDE not recognize iosMain as iOS source set
k
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
not if you do it right
a
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
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
Thx, I will check :)
k
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 😞