Gradle, native: Generate platform libraries at the user side

Since 1.4, a regular K/N distribution will not contain prebuilt
platform libraries, so the libraries must be generated at the
user side.

This patch adds support for such generation to the MPP Gradle
plugin. The generation itself is performed by separate utility
provided by the K/N compiler distribution. The plugin checks
existence of platform libraries for required targets and starts
this utility if some some of these libraries are missing. Building
caches for platform libraries is also performed at this step.

The patch also adds some project properties allowing a user to
workaround potential problems. User will be able to:
  - Use a special distribution with prebuilt platform libraries.
  - Force building platform libraries in the good old sourcecode mode
    in case of some issues with the new metadata mode.

Kotlin/Native counterpart: https://github.com/JetBrains/kotlin-native/pull/3829.

Issue #KT-32931 Fixed
This commit is contained in:
Ilya Matveev
2020-01-14 11:37:37 +07:00
parent 64a4d09bb3
commit 27f5c577c9
17 changed files with 535 additions and 50 deletions
@@ -22,3 +22,6 @@ fun konanCommonLibraryPath(libraryName: String) =
fun konanPlatformLibraryPath(libraryName: String, platform: String) =
File(KONAN_DISTRIBUTION_KLIB_DIR, KONAN_DISTRIBUTION_PLATFORM_LIBS_DIR).resolve(platform).resolve(libraryName)
// Used to provide unique names for platform libraries according to KT-36720.
const val KONAN_PLATFORM_LIBS_NAME_PREFIX = "org.jetbrains.kotlin.native.platform."
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.konan.properties.Properties
import org.jetbrains.kotlin.konan.properties.keepOnlyDefaultProfiles
import org.jetbrains.kotlin.konan.properties.loadProperties
import org.jetbrains.kotlin.konan.util.DependencyDirectories
import org.jetbrains.kotlin.konan.util.visibleName
class Distribution(
private val onlyDefaultProfiles: Boolean = false,
@@ -90,6 +91,10 @@ class Distribution(
fun runtime(target: KonanTarget) = runtimeFileOverride ?: "$stdlibDefaultComponent/targets/${target.visibleName}/native/runtime.bc"
fun platformDefs(family: Family) = "$konanHome/konan/platformDef/${family.visibleName}"
fun platformLibs(target: KonanTarget) = "$klib/platform/${target.visibleName}"
val launcherFiles = listOf("launcher.bc")
val dependenciesDir = DependencyDirectories.defaultDependenciesRoot.absolutePath