[K/N] Supported different runtime options for caches

This commit is contained in:
Igor Chevdar
2022-12-06 10:02:06 +02:00
committed by Space Team
parent 73e10b17c6
commit 342236491a
2 changed files with 52 additions and 36 deletions
@@ -22,7 +22,7 @@ class CacheBuilder(
private val configuration = konanConfig.configuration
private val autoCacheableFrom = configuration.get(KonanConfigKeys.AUTO_CACHEABLE_FROM)!!.map { File(it) }
fun needToBuild() = konanConfig.isFinalBinary && !konanConfig.optimizationsEnabled && autoCacheableFrom.isNotEmpty()
fun needToBuild() = konanConfig.isFinalBinary && konanConfig.ignoreCacheReason == null && autoCacheableFrom.isNotEmpty()
fun build() {
val allLibraries = konanConfig.resolvedLibraries.getFullList(TopologicalLibraryOrder)
@@ -80,12 +80,21 @@ class CacheBuilder(
put(KonanConfigKeys.NODEFAULTLIBS, true)
put(KonanConfigKeys.NOENDORSEDLIBS, true)
put(KonanConfigKeys.NOSTDLIB, true)
put(KonanConfigKeys.PARTIAL_LINKAGE, konanConfig.partialLinkage)
putIfNotNull(KonanConfigKeys.EXTERNAL_DEPENDENCIES, configuration.get(KonanConfigKeys.EXTERNAL_DEPENDENCIES))
put(KonanConfigKeys.LIBRARY_FILES, libraries)
put(KonanConfigKeys.CACHED_LIBRARIES, cachedLibraries)
put(KonanConfigKeys.CACHE_DIRECTORIES, listOf(libraryCacheDirectory.absolutePath))
put(KonanConfigKeys.MAKE_PER_FILE_CACHE, makePerFileCache)
put(KonanConfigKeys.PARTIAL_LINKAGE, konanConfig.partialLinkage)
putIfNotNull(KonanConfigKeys.EXTERNAL_DEPENDENCIES, configuration.get(KonanConfigKeys.EXTERNAL_DEPENDENCIES))
put(BinaryOptions.memoryModel, konanConfig.memoryModel)
put(KonanConfigKeys.PROPERTY_LAZY_INITIALIZATION, konanConfig.propertyLazyInitialization)
put(BinaryOptions.stripDebugInfoFromNativeLibs, !konanConfig.useDebugInfoInNativeLibs)
put(KonanConfigKeys.ALLOCATION_MODE, konanConfig.allocationMode)
put(KonanConfigKeys.GARBAGE_COLLECTOR, konanConfig.gc)
put(BinaryOptions.gcSchedulerType, konanConfig.gcSchedulerType)
put(BinaryOptions.freezing, konanConfig.freezing)
put(BinaryOptions.runtimeAssertionsMode, konanConfig.runtimeAssertsMode)
}
caches[library] = libraryCache.absolutePath
} catch (t: Throwable) {
@@ -393,17 +393,38 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
internal val additionalCacheFlags by lazy { platformManager.loader(target).additionalCacheFlags }
private val systemCacheFlavorString = buildString {
private fun StringBuilder.appendCommonCacheFlavor() {
append(target.toString())
if (debug) append("-g")
append("STATIC")
if (memoryModel != defaultMemoryModel)
append("-mm=$memoryModel")
if (freezing != defaultFreezing)
append("-freezing=${freezing.name}")
if (propertyLazyInitialization != defaultPropertyLazyInitialization)
append("-lazy_init=${if (propertyLazyInitialization) "enable" else "disable"}")
}
private val systemCacheFlavorString = buildString {
appendCommonCacheFlavor()
if (useDebugInfoInNativeLibs)
append("-runtime_debug")
if (allocationMode != defaultAllocationMode)
append("-allocator=${allocationMode.name}")
if (memoryModel == MemoryModel.EXPERIMENTAL && gc != defaultGC)
append("-gc=${gc.name}")
if (memoryModel == MemoryModel.EXPERIMENTAL && gcSchedulerType != defaultGCSchedulerType)
append("-gc-scheduler=${gcSchedulerType.name}")
if (runtimeAssertsMode != RuntimeAssertsMode.IGNORE)
append("-runtime_asserts=${runtimeAssertsMode.name}")
}
private val userCacheFlavorString = buildString {
append(target.toString())
if (debug) append("-g")
appendCommonCacheFlavor()
if (partialLinkage) append("-pl")
append("STATIC")
}
private val systemCacheRootDirectory = File(distribution.konanHome).child("klib").child("cache")
@@ -411,37 +432,23 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
private val autoCacheRootDirectory = configuration.get(KonanConfigKeys.AUTO_CACHE_DIR)?.let { File(it) } ?: systemCacheRootDirectory
internal val autoCacheDirectory = autoCacheRootDirectory.child(userCacheFlavorString)
internal val cacheSupport = run {
// TODO: Take some of these flags as part of cache meta-directory name.
val ignoreCacheReason = when {
optimizationsEnabled -> "for optimized compilation"
memoryModel != defaultMemoryModel -> "with ${memoryModel.name.lowercase()} memory model"
propertyLazyInitialization != defaultPropertyLazyInitialization -> {
"with${if (propertyLazyInitialization) "" else "out"} lazy top levels initialization"
}
useDebugInfoInNativeLibs -> "with native libs debug info"
allocationMode != defaultAllocationMode -> "with ${allocationMode.name.lowercase()} allocator"
memoryModel == MemoryModel.EXPERIMENTAL && gc != defaultGC -> "with ${gc.name.lowercase()} garbage collector"
memoryModel == MemoryModel.EXPERIMENTAL && gcSchedulerType != defaultGCSchedulerType -> {
"with ${gcSchedulerType.name.lowercase()} garbage collector scheduler"
}
freezing != defaultFreezing -> "with ${freezing.name.replaceFirstChar { it.lowercase() }} freezing mode"
runtimeAssertsMode != RuntimeAssertsMode.IGNORE -> "with runtime assertions"
sanitizer != null -> "with sanitizers enabled"
runtimeLogs != null -> "with runtime logs"
else -> null
}
CacheSupport(
configuration = configuration,
resolvedLibraries = resolvedLibraries,
ignoreCacheReason = ignoreCacheReason,
systemCacheDirectory = systemCacheDirectory,
autoCacheDirectory = autoCacheDirectory,
target = target,
produce = produce
)
internal val ignoreCacheReason = when {
optimizationsEnabled -> "for optimized compilation"
sanitizer != null -> "with sanitizers enabled"
runtimeLogs != null -> "with runtime logs"
else -> null
}
internal val cacheSupport = CacheSupport(
configuration = configuration,
resolvedLibraries = resolvedLibraries,
ignoreCacheReason = ignoreCacheReason,
systemCacheDirectory = systemCacheDirectory,
autoCacheDirectory = autoCacheDirectory,
target = target,
produce = produce
)
internal val cachedLibraries: CachedLibraries
get() = cacheSupport.cachedLibraries