[Gradle][Native][Cache] Don't skip metadata-based interop libraries
`resolveSingleFileKlib` by default doesn't support klibs with non-default ir providers. In case of cache generation for native interop libraries we need to override this behavior because they have ir_provider=kotlin.native.cinterop.
This commit is contained in:
@@ -230,10 +230,11 @@ abstract class KotlinLibraryProperResolverWithAttributes<L : KotlinLibrary>(
|
||||
class SingleKlibComponentResolver(
|
||||
klibFile: String,
|
||||
knownAbiVersions: List<KotlinAbiVersion>?,
|
||||
logger: Logger
|
||||
logger: Logger,
|
||||
knownIrProviders: List<String>
|
||||
) : KotlinLibraryProperResolverWithAttributes<KotlinLibrary>(
|
||||
emptyList(), listOf(klibFile), knownAbiVersions, emptyList(),
|
||||
null, null, false, logger, emptyList()
|
||||
null, null, false, logger, knownIrProviders
|
||||
) {
|
||||
override fun libraryComponentBuilder(file: File, isDefault: Boolean) = createKotlinLibraryComponents(file, isDefault)
|
||||
}
|
||||
@@ -244,6 +245,7 @@ class SingleKlibComponentResolver(
|
||||
* - searching among user-supplied libraries by "unique_name" that matches the given library name
|
||||
* - filtering out pre-1.4 libraries (with the old style layout)
|
||||
* - filtering out library components that have different ABI version than the ABI version of the current compiler
|
||||
* - filtering out libraries with non-default ir_provider.
|
||||
*
|
||||
* If no match found, fails with [Logger#fatal].
|
||||
*
|
||||
@@ -251,5 +253,23 @@ class SingleKlibComponentResolver(
|
||||
*/
|
||||
object CompilerSingleFileKlibResolveStrategy : SingleFileKlibResolveStrategy {
|
||||
override fun resolve(libraryFile: File, logger: Logger) =
|
||||
SingleKlibComponentResolver(libraryFile.absolutePath, listOf(KotlinAbiVersion.CURRENT), logger).resolve(libraryFile.absolutePath)
|
||||
SingleKlibComponentResolver(
|
||||
libraryFile.absolutePath, listOf(KotlinAbiVersion.CURRENT), logger, emptyList()
|
||||
).resolve(libraryFile.absolutePath)
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to [CompilerSingleFileKlibResolveStrategy], but doesn't filter out
|
||||
* libraries with [knownIrProviders].
|
||||
*/
|
||||
// TODO: It looks like a hack because it is.
|
||||
// The reason this strategy exists is that we shouldn't skip Native metadata-based interop libraries
|
||||
// when generating compiler caches.
|
||||
class CompilerSingleFileKlibResolveAllowingIrProvidersStrategy(
|
||||
private val knownIrProviders: List<String>
|
||||
) : SingleFileKlibResolveStrategy {
|
||||
override fun resolve(libraryFile: File, logger: Logger) =
|
||||
SingleKlibComponentResolver(
|
||||
libraryFile.absolutePath, listOf(KotlinAbiVersion.CURRENT), logger, knownIrProviders
|
||||
).resolve(libraryFile.absolutePath)
|
||||
}
|
||||
+17
-6
@@ -24,13 +24,11 @@ import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.asValidFrameworkName
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
|
||||
import org.jetbrains.kotlin.konan.library.KLIB_INTEROP_IR_PROVIDER_IDENTIFIER
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind.*
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.resolveSingleFileKlib
|
||||
import org.jetbrains.kotlin.library.uniqueName
|
||||
import org.jetbrains.kotlin.library.unresolvedDependencies
|
||||
import org.jetbrains.kotlin.library.*
|
||||
import java.io.File
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.security.MessageDigest
|
||||
@@ -645,6 +643,12 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
||||
}
|
||||
|
||||
class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
|
||||
private val nativeSingleFileResolveStrategy: SingleFileKlibResolveStrategy
|
||||
get() = CompilerSingleFileKlibResolveAllowingIrProvidersStrategy(
|
||||
listOf(KLIB_INTEROP_IR_PROVIDER_IDENTIFIER)
|
||||
)
|
||||
|
||||
private val compilation: KotlinNativeCompilation
|
||||
get() = binary.compilation
|
||||
|
||||
@@ -729,7 +733,11 @@ class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
cacheDirectory.mkdirs()
|
||||
|
||||
val artifactsLibraries = artifactsToAddToCache
|
||||
.map { resolveSingleFileKlib(org.jetbrains.kotlin.konan.file.File(it.file.absolutePath)) }
|
||||
.map {
|
||||
resolveSingleFileKlib(
|
||||
org.jetbrains.kotlin.konan.file.File(it.file.absolutePath), strategy = nativeSingleFileResolveStrategy
|
||||
)
|
||||
}
|
||||
.associateBy { it.uniqueName }
|
||||
|
||||
// Top sort artifacts.
|
||||
@@ -798,7 +806,10 @@ class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
val platformLib = platformLibs[platformLibName] ?: error("$platformLibName is not found in platform libs")
|
||||
if (File(rootCacheDirectory, platformLibName.cachedName).exists())
|
||||
return
|
||||
for (dependency in resolveSingleFileKlib(org.jetbrains.kotlin.konan.file.File(platformLib.absolutePath)).unresolvedDependencies)
|
||||
val unresolvedDependencies = resolveSingleFileKlib(
|
||||
org.jetbrains.kotlin.konan.file.File(platformLib.absolutePath), strategy = nativeSingleFileResolveStrategy
|
||||
).unresolvedDependencies
|
||||
for (dependency in unresolvedDependencies)
|
||||
ensureCompilerProvidedLibPrecached(dependency.path, platformLibs, visitedLibs)
|
||||
project.logger.info("Compiling $platformLibName (${visitedLibs.size}/${platformLibs.size}) to cache")
|
||||
val args = mutableListOf(
|
||||
|
||||
@@ -13,6 +13,7 @@ const val KONAN_DISTRIBUTION_KLIB_DIR = "klib"
|
||||
const val KONAN_DISTRIBUTION_COMMON_LIBS_DIR = "common"
|
||||
const val KONAN_DISTRIBUTION_PLATFORM_LIBS_DIR = "platform"
|
||||
const val KONAN_DISTRIBUTION_COMMONIZED_LIBS_DIR = "commonized"
|
||||
const val KLIB_INTEROP_IR_PROVIDER_IDENTIFIER = "kotlin.native.cinterop"
|
||||
|
||||
const val KONAN_DISTRIBUTION_SOURCES_DIR = "sources"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user