[K/N] add flag to klib manifest for header klibs

^KT-65443
This commit is contained in:
Johan Bay
2024-01-08 15:54:29 +01:00
committed by Space Cloud
parent 1b521d564f
commit 59f0c0464b
3 changed files with 17 additions and 5 deletions
@@ -31,6 +31,7 @@ const val KLIB_PROPERTY_CONTAINS_ERROR_CODE = "contains_error_code"
// Native-specific:
const val KLIB_PROPERTY_INTEROP = "interop"
const val KLIB_PROPERTY_HEADER = "header"
const val KLIB_PROPERTY_EXPORT_FORWARD_DECLARATIONS = "exportForwardDeclarations"
const val KLIB_PROPERTY_INCLUDED_FORWARD_DECLARATIONS = "includedForwardDeclarations"
const val KLIB_PROPERTY_IR_PROVIDER = "ir_provider"
@@ -126,6 +127,9 @@ interface KotlinLibrary : BaseKotlinLibrary, MetadataLibrary, IrLibrary
val KotlinLibrary.isInterop: Boolean
get() = manifestProperties.getProperty(KLIB_PROPERTY_INTEROP) == "true"
val KotlinLibrary.isHeader: Boolean
get() = manifestProperties.getProperty(KLIB_PROPERTY_HEADER) == "true"
val KotlinLibrary.packageFqName: String?
get() = manifestProperties.getProperty(KLIB_PROPERTY_PACKAGE)
@@ -118,7 +118,7 @@ internal class DynamicCompilerDriver : CompilerDriver() {
val headerKlibPath = config.headerKlibPath
if (!headerKlibPath.isNullOrEmpty()) {
val headerKlib = engine.runFir2IrSerializer(FirSerializerInput(fir2IrOutput, produceHeaderKlib = true))
engine.writeKlib(headerKlib, headerKlibPath)
engine.writeKlib(headerKlib, headerKlibPath, produceHeaderKlib = true)
// Don't overwrite the header klib with the full klib and stop compilation here.
// By providing the same path for both regular output and header klib we can skip emitting the full klib.
if (File(config.outputPath).canonicalPath == File(headerKlibPath).canonicalPath) return null
@@ -144,7 +144,7 @@ internal class DynamicCompilerDriver : CompilerDriver() {
val headerKlibPath = config.headerKlibPath
if (!headerKlibPath.isNullOrEmpty()) {
val headerKlib = engine.runSerializer(frontendOutput.moduleDescriptor, psiToIrOutput, produceHeaderKlib = true)
engine.writeKlib(headerKlib, headerKlibPath)
engine.writeKlib(headerKlib, headerKlibPath, produceHeaderKlib = true)
// Don't overwrite the header klib with the full klib and stop compilation here.
// By providing the same path for both regular output and header klib we can skip emitting the full klib.
if (File(config.outputPath).canonicalPath == File(headerKlibPath).canonicalPath) return null
@@ -12,14 +12,17 @@ import org.jetbrains.kotlin.backend.konan.driver.PhaseContext
import org.jetbrains.kotlin.backend.konan.driver.PhaseEngine
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.konan.library.impl.buildLibrary
import org.jetbrains.kotlin.library.KLIB_PROPERTY_HEADER
import org.jetbrains.kotlin.library.KotlinAbiVersion
import org.jetbrains.kotlin.library.KotlinLibraryVersioning
import org.jetbrains.kotlin.library.metadata.KlibMetadataVersion
import org.jetbrains.kotlin.util.removeSuffixIfPresent
import java.util.*
internal data class KlibWriterInput(
val serializerOutput: SerializerOutput,
val customOutputPath: String?
val customOutputPath: String?,
val produceHeaderKlib: Boolean
)
internal val WriteKlibPhase = createSimpleNamedCompilerPhase<PhaseContext, KlibWriterInput>(
"WriteKlib", "Write klib output",
@@ -43,7 +46,11 @@ internal val WriteKlibPhase = createSimpleNamedCompilerPhase<PhaseContext, KlibW
metadataVersion = metadataVersion,
)
val target = config.target
val manifestProperties = config.manifestProperties
val manifestProperties = config.manifestProperties ?: Properties()
if (input.produceHeaderKlib) {
manifestProperties.setProperty(KLIB_PROPERTY_HEADER, "true")
}
if (!nopack) {
val suffix = outputFiles.produce.suffix(target)
@@ -80,6 +87,7 @@ internal val WriteKlibPhase = createSimpleNamedCompilerPhase<PhaseContext, KlibW
internal fun <T : PhaseContext> PhaseEngine<T>.writeKlib(
serializationOutput: SerializerOutput,
customOutputPath: String? = null,
produceHeaderKlib: Boolean = false,
) {
this.runPhase(WriteKlibPhase, KlibWriterInput(serializationOutput, customOutputPath))
this.runPhase(WriteKlibPhase, KlibWriterInput(serializationOutput, customOutputPath, produceHeaderKlib))
}