[K/N] add header_cache output type
^KT-65443
This commit is contained in:
+1
@@ -47,6 +47,7 @@ internal fun resolveCacheBinaries(
|
|||||||
val list = when (cache.kind) {
|
val list = when (cache.kind) {
|
||||||
CachedLibraries.Kind.DYNAMIC -> dynamicCaches
|
CachedLibraries.Kind.DYNAMIC -> dynamicCaches
|
||||||
CachedLibraries.Kind.STATIC -> staticCaches
|
CachedLibraries.Kind.STATIC -> staticCaches
|
||||||
|
CachedLibraries.Kind.HEADER -> error("Header cache ${cache.path} cannot be used for linking")
|
||||||
}
|
}
|
||||||
|
|
||||||
list += if (dependency.kind is DependenciesTracker.DependencyKind.CertainFiles && cache is CachedLibraries.Cache.PerFile)
|
list += if (dependency.kind is DependenciesTracker.DependencyKind.CertainFiles && cache is CachedLibraries.Cache.PerFile)
|
||||||
|
|||||||
+6
-3
@@ -42,7 +42,7 @@ class CachedLibraries(
|
|||||||
autoCacheDirectory: File,
|
autoCacheDirectory: File,
|
||||||
autoCacheableFrom: List<File>
|
autoCacheableFrom: List<File>
|
||||||
) {
|
) {
|
||||||
enum class Kind { DYNAMIC, STATIC }
|
enum class Kind { DYNAMIC, STATIC, HEADER }
|
||||||
|
|
||||||
sealed class Cache(protected val target: KonanTarget, val kind: Kind, val path: String, val rootDirectory: String) {
|
sealed class Cache(protected val target: KonanTarget, val kind: Kind, val path: String, val rootDirectory: String) {
|
||||||
val bitcodeDependencies by lazy { computeBitcodeDependencies() }
|
val bitcodeDependencies by lazy { computeBitcodeDependencies() }
|
||||||
@@ -60,6 +60,7 @@ class CachedLibraries(
|
|||||||
protected fun Kind.toCompilerOutputKind(): CompilerOutputKind = when (this) {
|
protected fun Kind.toCompilerOutputKind(): CompilerOutputKind = when (this) {
|
||||||
Kind.DYNAMIC -> CompilerOutputKind.DYNAMIC_CACHE
|
Kind.DYNAMIC -> CompilerOutputKind.DYNAMIC_CACHE
|
||||||
Kind.STATIC -> CompilerOutputKind.STATIC_CACHE
|
Kind.STATIC -> CompilerOutputKind.STATIC_CACHE
|
||||||
|
Kind.HEADER -> CompilerOutputKind.HEADER_CACHE
|
||||||
}
|
}
|
||||||
|
|
||||||
class Monolithic(target: KonanTarget, kind: Kind, path: String)
|
class Monolithic(target: KonanTarget, kind: Kind, path: String)
|
||||||
@@ -154,6 +155,7 @@ class CachedLibraries(
|
|||||||
val baseName = getCachedLibraryName(library)
|
val baseName = getCachedLibraryName(library)
|
||||||
val dynamicFile = cacheBinaryPartDir.child(getArtifactName(target, baseName, CompilerOutputKind.DYNAMIC_CACHE))
|
val dynamicFile = cacheBinaryPartDir.child(getArtifactName(target, baseName, CompilerOutputKind.DYNAMIC_CACHE))
|
||||||
val staticFile = cacheBinaryPartDir.child(getArtifactName(target, baseName, CompilerOutputKind.STATIC_CACHE))
|
val staticFile = cacheBinaryPartDir.child(getArtifactName(target, baseName, CompilerOutputKind.STATIC_CACHE))
|
||||||
|
val headerFile = cacheBinaryPartDir.child(getArtifactName(target, baseName, CompilerOutputKind.HEADER_CACHE))
|
||||||
|
|
||||||
if (dynamicFile.absolutePath in cacheBinaryPartDirContents && staticFile.absolutePath in cacheBinaryPartDirContents)
|
if (dynamicFile.absolutePath in cacheBinaryPartDirContents && staticFile.absolutePath in cacheBinaryPartDirContents)
|
||||||
error("Both dynamic and static caches files cannot be in the same directory." +
|
error("Both dynamic and static caches files cannot be in the same directory." +
|
||||||
@@ -161,6 +163,7 @@ class CachedLibraries(
|
|||||||
return when {
|
return when {
|
||||||
dynamicFile.absolutePath in cacheBinaryPartDirContents -> Cache.Monolithic(target, Kind.DYNAMIC, dynamicFile.absolutePath)
|
dynamicFile.absolutePath in cacheBinaryPartDirContents -> Cache.Monolithic(target, Kind.DYNAMIC, dynamicFile.absolutePath)
|
||||||
staticFile.absolutePath in cacheBinaryPartDirContents -> Cache.Monolithic(target, Kind.STATIC, staticFile.absolutePath)
|
staticFile.absolutePath in cacheBinaryPartDirContents -> Cache.Monolithic(target, Kind.STATIC, staticFile.absolutePath)
|
||||||
|
headerFile.absolutePath in cacheBinaryPartDirContents -> Cache.Monolithic(target, Kind.HEADER, headerFile.absolutePath)
|
||||||
else -> {
|
else -> {
|
||||||
val libraryFileDirs = library.getFilesWithFqNames().map {
|
val libraryFileDirs = library.getFilesWithFqNames().map {
|
||||||
child(CacheSupport.cacheFileId(it.fqName, it.filePath))
|
child(CacheSupport.cacheFileId(it.fqName, it.filePath))
|
||||||
@@ -212,14 +215,14 @@ class CachedLibraries(
|
|||||||
val hasStaticCaches = allCaches.values.any {
|
val hasStaticCaches = allCaches.values.any {
|
||||||
when (it.kind) {
|
when (it.kind) {
|
||||||
Kind.STATIC -> true
|
Kind.STATIC -> true
|
||||||
Kind.DYNAMIC -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val hasDynamicCaches = allCaches.values.any {
|
val hasDynamicCaches = allCaches.values.any {
|
||||||
when (it.kind) {
|
when (it.kind) {
|
||||||
Kind.STATIC -> false
|
|
||||||
Kind.DYNAMIC -> true
|
Kind.DYNAMIC -> true
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -20,7 +20,7 @@ import java.io.File
|
|||||||
val KonanConfig.isFinalBinary: Boolean get() = when (this.produce) {
|
val KonanConfig.isFinalBinary: Boolean get() = when (this.produce) {
|
||||||
CompilerOutputKind.PROGRAM, CompilerOutputKind.DYNAMIC,
|
CompilerOutputKind.PROGRAM, CompilerOutputKind.DYNAMIC,
|
||||||
CompilerOutputKind.STATIC -> true
|
CompilerOutputKind.STATIC -> true
|
||||||
CompilerOutputKind.DYNAMIC_CACHE, CompilerOutputKind.STATIC_CACHE,
|
CompilerOutputKind.DYNAMIC_CACHE, CompilerOutputKind.STATIC_CACHE, CompilerOutputKind.HEADER_CACHE,
|
||||||
CompilerOutputKind.LIBRARY, CompilerOutputKind.BITCODE -> false
|
CompilerOutputKind.LIBRARY, CompilerOutputKind.BITCODE -> false
|
||||||
CompilerOutputKind.FRAMEWORK -> !omitFrameworkBinary
|
CompilerOutputKind.FRAMEWORK -> !omitFrameworkBinary
|
||||||
CompilerOutputKind.TEST_BUNDLE -> true
|
CompilerOutputKind.TEST_BUNDLE -> true
|
||||||
@@ -55,9 +55,15 @@ internal val CacheDeserializationStrategy?.containsRuntime: Boolean
|
|||||||
internal val NativeGenerationState.shouldLinkRuntimeNativeLibraries: Boolean
|
internal val NativeGenerationState.shouldLinkRuntimeNativeLibraries: Boolean
|
||||||
get() = producedLlvmModuleContainsStdlib && cacheDeserializationStrategy.containsRuntime
|
get() = producedLlvmModuleContainsStdlib && cacheDeserializationStrategy.containsRuntime
|
||||||
|
|
||||||
val CompilerOutputKind.isCache: Boolean
|
val CompilerOutputKind.isFullCache: Boolean
|
||||||
get() = this == CompilerOutputKind.STATIC_CACHE || this == CompilerOutputKind.DYNAMIC_CACHE
|
get() = this == CompilerOutputKind.STATIC_CACHE || this == CompilerOutputKind.DYNAMIC_CACHE
|
||||||
|
|
||||||
|
val CompilerOutputKind.isHeaderCache: Boolean
|
||||||
|
get() = this == CompilerOutputKind.HEADER_CACHE
|
||||||
|
|
||||||
|
val CompilerOutputKind.isCache: Boolean
|
||||||
|
get() = this.isFullCache || this.isHeaderCache
|
||||||
|
|
||||||
internal fun produceCStubs(generationState: NativeGenerationState) {
|
internal fun produceCStubs(generationState: NativeGenerationState) {
|
||||||
generationState.cStubsManager.compile(
|
generationState.cStubsManager.compile(
|
||||||
generationState.config.clang,
|
generationState.config.clang,
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ internal class DynamicCompilerDriver : CompilerDriver() {
|
|||||||
CompilerOutputKind.BITCODE -> error("Bitcode output kind is obsolete.")
|
CompilerOutputKind.BITCODE -> error("Bitcode output kind is obsolete.")
|
||||||
CompilerOutputKind.DYNAMIC_CACHE -> produceBinary(engine, config, environment)
|
CompilerOutputKind.DYNAMIC_CACHE -> produceBinary(engine, config, environment)
|
||||||
CompilerOutputKind.STATIC_CACHE -> produceBinary(engine, config, environment)
|
CompilerOutputKind.STATIC_CACHE -> produceBinary(engine, config, environment)
|
||||||
CompilerOutputKind.PRELIMINARY_CACHE -> TODO()
|
CompilerOutputKind.HEADER_CACHE -> produceBinary(engine, config, environment)
|
||||||
CompilerOutputKind.TEST_BUNDLE -> produceBundle(engine, config, environment)
|
CompilerOutputKind.TEST_BUNDLE -> produceBundle(engine, config, environment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-3
@@ -90,6 +90,14 @@ internal fun <C : PhaseContext> PhaseEngine<C>.runBackend(backendContext: Contex
|
|||||||
fun runAfterLowerings(fragment: BackendJobFragment, generationState: NativeGenerationState) {
|
fun runAfterLowerings(fragment: BackendJobFragment, generationState: NativeGenerationState) {
|
||||||
val tempFiles = createTempFiles(config, fragment.cacheDeserializationStrategy)
|
val tempFiles = createTempFiles(config, fragment.cacheDeserializationStrategy)
|
||||||
val outputFiles = generationState.outputFiles
|
val outputFiles = generationState.outputFiles
|
||||||
|
if (context.config.produce.isHeaderCache) {
|
||||||
|
newEngine(generationState) { generationStateEngine ->
|
||||||
|
generationStateEngine.runPhase(SaveAdditionalCacheInfoPhase)
|
||||||
|
File(outputFiles.nativeBinaryFile).createNew()
|
||||||
|
generationStateEngine.runPhase(FinalizeCachePhase, outputFiles)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
backendEngine.useContext(generationState) { generationStateEngine ->
|
backendEngine.useContext(generationState) { generationStateEngine ->
|
||||||
val bitcodeFile = tempFiles.create(generationState.llvmModuleName, ".bc").javaFile()
|
val bitcodeFile = tempFiles.create(generationState.llvmModuleName, ".bc").javaFile()
|
||||||
@@ -258,7 +266,7 @@ internal fun PhaseEngine<NativeGenerationState>.compileModule(module: IrModuleFr
|
|||||||
if (checkExternalCalls) {
|
if (checkExternalCalls) {
|
||||||
runPhase(RewriteExternalCallsCheckerGlobals)
|
runPhase(RewriteExternalCallsCheckerGlobals)
|
||||||
}
|
}
|
||||||
if (context.config.produce.isCache) {
|
if (context.config.produce.isFullCache) {
|
||||||
runPhase(SaveAdditionalCacheInfoPhase)
|
runPhase(SaveAdditionalCacheInfoPhase)
|
||||||
}
|
}
|
||||||
runPhase(WriteBitcodeFilePhase, WriteBitcodeFileInput(context.llvm.module, bitcodeFile))
|
runPhase(WriteBitcodeFilePhase, WriteBitcodeFileInput(context.llvm.module, bitcodeFile))
|
||||||
@@ -275,10 +283,10 @@ internal fun <C : PhaseContext> PhaseEngine<C>.compileAndLink(
|
|||||||
runPhase(ObjectFilesPhase, ObjectFilesPhaseInput(moduleCompilationOutput.bitcodeFile, compilationResult))
|
runPhase(ObjectFilesPhase, ObjectFilesPhaseInput(moduleCompilationOutput.bitcodeFile, compilationResult))
|
||||||
val linkerOutputKind = determineLinkerOutput(context)
|
val linkerOutputKind = determineLinkerOutput(context)
|
||||||
val (linkerInput, cacheBinaries) = run {
|
val (linkerInput, cacheBinaries) = run {
|
||||||
val resolvedCacheBinaries = resolveCacheBinaries(context.config.cachedLibraries, moduleCompilationOutput.dependenciesTrackingResult)
|
val resolvedCacheBinaries by lazy { resolveCacheBinaries(context.config.cachedLibraries, moduleCompilationOutput.dependenciesTrackingResult) }
|
||||||
when {
|
when {
|
||||||
context.config.produce == CompilerOutputKind.STATIC_CACHE -> {
|
context.config.produce == CompilerOutputKind.STATIC_CACHE -> {
|
||||||
compilationResult to ResolvedCacheBinaries(emptyList(), resolvedCacheBinaries.dynamic)
|
compilationResult to ResolvedCacheBinaries(emptyList(), emptyList())
|
||||||
}
|
}
|
||||||
shouldPerformPreLink(context.config, resolvedCacheBinaries, linkerOutputKind) -> {
|
shouldPerformPreLink(context.config, resolvedCacheBinaries, linkerOutputKind) -> {
|
||||||
val prelinkResult = temporaryFiles.create("withStaticCaches", ".o").javaFile()
|
val prelinkResult = temporaryFiles.create("withStaticCaches", ".o").javaFile()
|
||||||
|
|||||||
+2
-1
@@ -366,7 +366,8 @@ abstract class KotlinAndroidProjectExtension(project: Project) : KotlinSingleTar
|
|||||||
enum class NativeCacheKind(val produce: String?, val outputKind: CompilerOutputKind?) {
|
enum class NativeCacheKind(val produce: String?, val outputKind: CompilerOutputKind?) {
|
||||||
NONE(null, null),
|
NONE(null, null),
|
||||||
DYNAMIC("dynamic_cache", CompilerOutputKind.DYNAMIC_CACHE),
|
DYNAMIC("dynamic_cache", CompilerOutputKind.DYNAMIC_CACHE),
|
||||||
STATIC("static_cache", CompilerOutputKind.STATIC_CACHE);
|
STATIC("static_cache", CompilerOutputKind.STATIC_CACHE),
|
||||||
|
HEADER("header_cache", CompilerOutputKind.HEADER_CACHE);
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun byCompilerArgument(argument: String): NativeCacheKind? =
|
fun byCompilerArgument(argument: String): NativeCacheKind? =
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ enum class CompilerOutputKind {
|
|||||||
override fun suffix(target: KonanTarget?) = ".${target!!.family.staticSuffix}"
|
override fun suffix(target: KonanTarget?) = ".${target!!.family.staticSuffix}"
|
||||||
override fun prefix(target: KonanTarget?) = target!!.family.staticPrefix
|
override fun prefix(target: KonanTarget?) = target!!.family.staticPrefix
|
||||||
},
|
},
|
||||||
PRELIMINARY_CACHE {
|
HEADER_CACHE {
|
||||||
override fun suffix(target: KonanTarget?) = ""
|
override fun suffix(target: KonanTarget?) = ".header"
|
||||||
};
|
};
|
||||||
|
|
||||||
abstract fun suffix(target: KonanTarget? = null): String
|
abstract fun suffix(target: KonanTarget? = null): String
|
||||||
|
|||||||
Reference in New Issue
Block a user