[K/N] Supported different runtime options for caches
This commit is contained in:
+12
-3
@@ -22,7 +22,7 @@ class CacheBuilder(
|
|||||||
private val configuration = konanConfig.configuration
|
private val configuration = konanConfig.configuration
|
||||||
private val autoCacheableFrom = configuration.get(KonanConfigKeys.AUTO_CACHEABLE_FROM)!!.map { File(it) }
|
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() {
|
fun build() {
|
||||||
val allLibraries = konanConfig.resolvedLibraries.getFullList(TopologicalLibraryOrder)
|
val allLibraries = konanConfig.resolvedLibraries.getFullList(TopologicalLibraryOrder)
|
||||||
@@ -80,12 +80,21 @@ class CacheBuilder(
|
|||||||
put(KonanConfigKeys.NODEFAULTLIBS, true)
|
put(KonanConfigKeys.NODEFAULTLIBS, true)
|
||||||
put(KonanConfigKeys.NOENDORSEDLIBS, true)
|
put(KonanConfigKeys.NOENDORSEDLIBS, true)
|
||||||
put(KonanConfigKeys.NOSTDLIB, 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.LIBRARY_FILES, libraries)
|
||||||
put(KonanConfigKeys.CACHED_LIBRARIES, cachedLibraries)
|
put(KonanConfigKeys.CACHED_LIBRARIES, cachedLibraries)
|
||||||
put(KonanConfigKeys.CACHE_DIRECTORIES, listOf(libraryCacheDirectory.absolutePath))
|
put(KonanConfigKeys.CACHE_DIRECTORIES, listOf(libraryCacheDirectory.absolutePath))
|
||||||
put(KonanConfigKeys.MAKE_PER_FILE_CACHE, makePerFileCache)
|
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
|
caches[library] = libraryCache.absolutePath
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
|
|||||||
+40
-33
@@ -393,17 +393,38 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
|||||||
|
|
||||||
internal val additionalCacheFlags by lazy { platformManager.loader(target).additionalCacheFlags }
|
internal val additionalCacheFlags by lazy { platformManager.loader(target).additionalCacheFlags }
|
||||||
|
|
||||||
private val systemCacheFlavorString = buildString {
|
private fun StringBuilder.appendCommonCacheFlavor() {
|
||||||
append(target.toString())
|
append(target.toString())
|
||||||
if (debug) append("-g")
|
if (debug) append("-g")
|
||||||
append("STATIC")
|
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 {
|
private val userCacheFlavorString = buildString {
|
||||||
append(target.toString())
|
appendCommonCacheFlavor()
|
||||||
if (debug) append("-g")
|
|
||||||
if (partialLinkage) append("-pl")
|
if (partialLinkage) append("-pl")
|
||||||
append("STATIC")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val systemCacheRootDirectory = File(distribution.konanHome).child("klib").child("cache")
|
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
|
private val autoCacheRootDirectory = configuration.get(KonanConfigKeys.AUTO_CACHE_DIR)?.let { File(it) } ?: systemCacheRootDirectory
|
||||||
internal val autoCacheDirectory = autoCacheRootDirectory.child(userCacheFlavorString)
|
internal val autoCacheDirectory = autoCacheRootDirectory.child(userCacheFlavorString)
|
||||||
|
|
||||||
internal val cacheSupport = run {
|
internal val ignoreCacheReason = when {
|
||||||
// TODO: Take some of these flags as part of cache meta-directory name.
|
optimizationsEnabled -> "for optimized compilation"
|
||||||
val ignoreCacheReason = when {
|
sanitizer != null -> "with sanitizers enabled"
|
||||||
optimizationsEnabled -> "for optimized compilation"
|
runtimeLogs != null -> "with runtime logs"
|
||||||
memoryModel != defaultMemoryModel -> "with ${memoryModel.name.lowercase()} memory model"
|
else -> null
|
||||||
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 cacheSupport = CacheSupport(
|
||||||
|
configuration = configuration,
|
||||||
|
resolvedLibraries = resolvedLibraries,
|
||||||
|
ignoreCacheReason = ignoreCacheReason,
|
||||||
|
systemCacheDirectory = systemCacheDirectory,
|
||||||
|
autoCacheDirectory = autoCacheDirectory,
|
||||||
|
target = target,
|
||||||
|
produce = produce
|
||||||
|
)
|
||||||
|
|
||||||
internal val cachedLibraries: CachedLibraries
|
internal val cachedLibraries: CachedLibraries
|
||||||
get() = cacheSupport.cachedLibraries
|
get() = cacheSupport.cachedLibraries
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user