Skip to content

Commit

Permalink
[native, build] Depend on interop klibs inside local build/, not in d…
Browse files Browse the repository at this point in the history
…ist/

Interop klibs are built into two steps:
1. Compile interop klibs in kotlin-native/platformLibs/build/konan/libs
   This is done in KonanInteropTasks with names like:
   'compileKonanAndroid_arm64-mediaAndroid_arm64'
2. Move them to kotlin-native/dist/klib/platform
   This is done in regular Sync-tasks with names like:
   'android_arm64-media'

Some interop klibs depend on other interop klibs (e.g.
android_arm64/media library depends on android_arm64/posix). This
commit changes how this dependency is declared;

Before:
- KonanInteropTasks declared dependencies on raw files in
  kotlin-native/dist/klib/platform.
  Example: 'compileKonanAndroid_arm64-mediaAndroid_arm64' declared
  a dependency on
  'kotlin-native/dist/klib/platform/android_arm64/o.j.k.n.p.posix'-dir

- KonanInteropTasks declared dependencies on Sync-tasks, i.e. tasks
  from #1 declare dependencies on tasks from #2.
  Example: 'compileKonanAndroid_arm64-mediaAndroid_arm64' declared a
  dependency on 'android_arm64-posix'

After:
- KonanInteropTasks declare dependencies on raw files in
  kotlin-native/platformLibs/build/konan/libs.
  Example: 'compileKonanAndroid_arm64-mediaAndroid_arm64' declares
  a dependency on
  'kotlin-native/platformLibs/build/konan/libs/android_arm64/o.j.k.n.p.posix'

- KonanInteropTasks declare dependencies on other KonanInteropTasks.
  Example: 'compileKonanAndroid_arm64-mediaAndroid_arm64' declares
  a dependency on 'compileKonanAndroid_arm64-posixAndroid_arm64'

This improves incapsulation and makes it less likely for inputs of
these tasks to overlap with outputs of other tasks that write into dist/
(and overlapping outputs lead to error in Gradle)
  • Loading branch information
dsavvinov authored and Space Team committed May 14, 2024
1 parent df140ea commit da57bc5
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions kotlin-native/platformLibs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ plugins {

// region: Util functions.
fun KonanTarget.defFiles() =
project.fileTree("src/platform/${family.visibleName}")
.filter { it.name.endsWith(".def") }
.map { DefFile(it, this) }
project.fileTree("src/platform/${family.visibleName}")
.filter { it.name.endsWith(".def") }
.map { DefFile(it, this) }


fun defFileToLibName(target: String, name: String) = "$target-$name"
Expand All @@ -49,6 +49,7 @@ enabledTargets(platformManager).forEach { target ->
val installTasks = mutableListOf<TaskProvider<out Task>>()
val cacheTasks = mutableListOf<TaskProvider<out Task>>()

// First register all interop-libraries
target.defFiles().forEach { df ->
val libName = defFileToLibName(targetName, df.name)
val fileNamePrefix = PlatformLibsInfo.namePrefix
Expand All @@ -62,17 +63,30 @@ enabledTargets(platformManager).forEach { target ->
noEndorsedLibs(true)
noPack(true)
libraries {
klibFiles(df.config.depends.map { "$konanHome/klib/platform/$targetName/${fileNamePrefix}${it}" })
klibFiles(df.config.depends.map { layout.buildDirectory.dir("konan/libs/$targetName/${fileNamePrefix}${it}") })
}
extraOpts("-Xpurge-user-libs", "-Xshort-module-name", df.name, "-Xdisable-experimental-annotation")
compilerOpts("-fmodules-cache-path=${project.layout.buildDirectory.dir("clangModulesCache").get().asFile}")
}
}
}

// After all interop-libraries are registered, configure tasks (need to do it after all interop-libraries
// are registered, because they cross-reference each other)
target.defFiles().forEach { df ->
val libName = defFileToLibName(targetName, df.name)
val fileNamePrefix = PlatformLibsInfo.namePrefix
val artifactName = "${fileNamePrefix}${df.name}"

@Suppress("UNCHECKED_CAST")
val libTask = konanArtifacts.getByName(libName).getByTarget(targetName) as TaskProvider<KonanInteropTask>
libTask.configure {
dependsOn(df.config.depends.map { defFileToLibName(targetName, it) })
dependsOn(
df.config.depends.map {
val dependencyLibName = defFileToLibName(targetName, it)
konanArtifacts.getByName(dependencyLibName).getByTarget(targetName)
}
)
dependsOn(":kotlin-native:${targetName}CrossDist")

enableParallel = project.findProperty("kotlin.native.platformLibs.parallel")?.toString()?.toBoolean() ?: true
Expand Down

0 comments on commit da57bc5

Please sign in to comment.