Support short library names in compiler, interop and platform libs
Fixes for KT-36720 and KT-36721 change a scheme that is used to generate unique names for klibs: now we use "fully qualified" names that include a group and a name of a library (e.g. org.jetbrains.kotlin. native.posix). But in some cases we still need short library names. For example to display platform libs in the IDE or to export some symbols of a library to an ObjC framework. This patch adds support for such short names to: - klib generation in the compiler - cinterop tool (both sourcecode and metadata mode) - platform libraries (both prebuilt and built on the user side) Support for C/ObjC export remains.
This commit is contained in:
committed by
Ilya Matveev
parent
624328c3cc
commit
ce1cb39c41
+6
@@ -28,6 +28,7 @@ const val PURGE_USER_LIBS = "Xpurge-user-libs"
|
||||
const val TEMP_DIR = "Xtemporary-files-dir"
|
||||
const val NOPACK = "nopack"
|
||||
const val COMPILE_SOURCES = "Xcompile-source"
|
||||
const val SHORT_MODULE_NAME = "Xshort-module-name"
|
||||
|
||||
// TODO: unify camel and snake cases.
|
||||
// Possible solution is to accept both cases
|
||||
@@ -108,6 +109,11 @@ open class CInteropArguments(argParser: ArgParser =
|
||||
fullName = "Xsource-compiler-option",
|
||||
description = "compiler options for sources provided via -$COMPILE_SOURCES"
|
||||
).multiple()
|
||||
|
||||
val shortModuleName by argParser.option(ArgType.String,
|
||||
fullName = SHORT_MODULE_NAME,
|
||||
description = "A short name used to denote this library in the IDE and during Objective-C export"
|
||||
)
|
||||
}
|
||||
|
||||
class JSInteropArguments(argParser: ArgParser = ArgParser("jsinterop",
|
||||
|
||||
+4
-2
@@ -32,7 +32,8 @@ fun createInteropLibrary(
|
||||
target: KonanTarget,
|
||||
manifest: Properties,
|
||||
dependencies: List<KotlinLibrary>,
|
||||
nopack: Boolean
|
||||
nopack: Boolean,
|
||||
shortName: String?
|
||||
) {
|
||||
val version = KotlinLibraryVersioning(
|
||||
libraryVersion = null,
|
||||
@@ -49,7 +50,8 @@ fun createInteropLibrary(
|
||||
target,
|
||||
|
||||
BuiltInsPlatform.NATIVE,
|
||||
nopack = nopack
|
||||
nopack = nopack,
|
||||
shortName = shortName
|
||||
).apply {
|
||||
val metadata = metadata.write(ChunkingWriteStrategy())
|
||||
addMetadata(SerializedMetadata(metadata.header, metadata.fragments, metadata.fragmentNames))
|
||||
|
||||
+2
-1
@@ -374,7 +374,8 @@ private fun processCLib(flavorName: String, cinteropArguments: CInteropArguments
|
||||
outputPath = cinteropArguments.output,
|
||||
manifest = def.manifestAddendProperties,
|
||||
dependencies = stdlibDependency + imports.requiredLibraries.toList(),
|
||||
nopack = cinteropArguments.nopack
|
||||
nopack = cinteropArguments.nopack,
|
||||
shortName = cinteropArguments.shortModuleName
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -123,8 +123,9 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
arguments.libraries.toNonNullList())
|
||||
put(LINKER_ARGS, arguments.linkerArguments.toNonNullList() +
|
||||
arguments.singleLinkerArguments.toNonNullList())
|
||||
arguments.moduleName ?. let{ put(MODULE_NAME, it) }
|
||||
arguments.target ?.let{ put(TARGET, it) }
|
||||
arguments.moduleName?.let{ put(MODULE_NAME, it) }
|
||||
arguments.shortModuleName?.let { put(SHORT_MODULE_NAME, it) }
|
||||
arguments.target?.let{ put(TARGET, it) }
|
||||
|
||||
put(INCLUDED_BINARY_FILES,
|
||||
arguments.includeBinaries.toNonNullList())
|
||||
|
||||
@@ -195,10 +195,17 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(
|
||||
value = INCLUDE_ARG,
|
||||
valueDescription = "<path>",
|
||||
description = "A path to an intermediate library that should be processed in the same manner as source files.\n"
|
||||
description = "A path to an intermediate library that should be processed in the same manner as source files"
|
||||
)
|
||||
var includes: Array<String>? = null
|
||||
|
||||
@Argument(
|
||||
value = "-Xshort-module-name",
|
||||
valueDescription = "<name>",
|
||||
description = "A short name used to denote this library in the IDE and during Objective-C export"
|
||||
)
|
||||
var shortModuleName: String? = null
|
||||
|
||||
@Argument(value = STATIC_FRAMEWORK_FLAG, description = "Create a framework with a static library instead of a dynamic one")
|
||||
var staticFramework: Boolean = false
|
||||
|
||||
|
||||
+2
@@ -131,6 +131,7 @@ internal fun produceOutput(context: Context) {
|
||||
CompilerOutputKind.LIBRARY -> {
|
||||
val output = context.config.outputFiles.outputName
|
||||
val libraryName = context.config.moduleId
|
||||
val shortLibraryName = context.config.shortModuleName
|
||||
val neededLibraries = context.librariesWithDependencies
|
||||
val abiVersion = KotlinAbiVersion.CURRENT
|
||||
val compilerVersion = CompilerVersion.CURRENT.toString()
|
||||
@@ -159,6 +160,7 @@ internal fun produceOutput(context: Context) {
|
||||
output,
|
||||
libraryName,
|
||||
nopack,
|
||||
shortLibraryName,
|
||||
manifestProperties,
|
||||
context.dataFlowGraph)
|
||||
|
||||
|
||||
+3
@@ -94,6 +94,9 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
val moduleId: String
|
||||
get() = configuration.get(KonanConfigKeys.MODULE_NAME) ?: File(outputFiles.outputName).name
|
||||
|
||||
val shortModuleName: String?
|
||||
get() = configuration.get(KonanConfigKeys.SHORT_MODULE_NAME)
|
||||
|
||||
val infoArgsOnly = configuration.kotlinSourceRoots.isEmpty()
|
||||
&& configuration[KonanConfigKeys.INCLUDED_LIBRARIES].isNullOrEmpty()
|
||||
&& librariesToCache.isEmpty()
|
||||
|
||||
+2
@@ -114,6 +114,8 @@ class KonanConfigKeys {
|
||||
= CompilerConfigurationKey("klibs processed in the same manner as source files")
|
||||
val SOURCE_MAP: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create("generate source map")
|
||||
val SHORT_MODULE_NAME: CompilerConfigurationKey<String?>
|
||||
= CompilerConfigurationKey("short module name for IDE and export")
|
||||
val STATIC_FRAMEWORK: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("produce a static library for a framework")
|
||||
val TARGET: CompilerConfigurationKey<String?>
|
||||
|
||||
@@ -85,7 +85,7 @@ project.rootProject.ext.platformManager.enabled.each { target ->
|
||||
"${fileNamePrefix}${it}".toString()
|
||||
}
|
||||
}
|
||||
extraOpts '-Xpurge-user-libs'
|
||||
extraOpts '-Xpurge-user-libs', "-Xshort-module-name", df.name
|
||||
compilerOpts "-fmodules-cache-path=${project.buildDir}/clangModulesCache"
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -30,10 +30,11 @@ class KonanLibraryWriterImpl(
|
||||
target: KonanTarget,
|
||||
builtInsPlatform: BuiltInsPlatform,
|
||||
nopack: Boolean = false,
|
||||
shortName: String? = null,
|
||||
|
||||
val layout: KonanLibraryLayoutForWriter = KonanLibraryLayoutForWriter(libDir, target),
|
||||
|
||||
base: BaseWriter = BaseWriterImpl(layout, moduleName, versions, builtInsPlatform, nopack),
|
||||
base: BaseWriter = BaseWriterImpl(layout, moduleName, versions, builtInsPlatform, nopack, shortName),
|
||||
bitcode: BitcodeWriter = BitcodeWriterImpl(layout),
|
||||
metadata: MetadataWriter = MetadataWriterImpl(layout),
|
||||
ir: IrWriter = IrMonoliticWriterImpl(layout)
|
||||
@@ -51,11 +52,20 @@ fun buildLibrary(
|
||||
output: String,
|
||||
moduleName: String,
|
||||
nopack: Boolean,
|
||||
shortName: String?,
|
||||
manifestProperties: Properties?,
|
||||
dataFlowGraph: ByteArray?
|
||||
): KonanLibraryLayout {
|
||||
|
||||
val library = KonanLibraryWriterImpl(File(output), moduleName, versions, target, BuiltInsPlatform.NATIVE, nopack)
|
||||
val library = KonanLibraryWriterImpl(
|
||||
File(output),
|
||||
moduleName,
|
||||
versions,
|
||||
target,
|
||||
BuiltInsPlatform.NATIVE,
|
||||
nopack,
|
||||
shortName
|
||||
)
|
||||
|
||||
library.addMetadata(metadata)
|
||||
if (ir != null) {
|
||||
|
||||
+5
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.konan.util.visibleName
|
||||
import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.DEFAULT_MODE
|
||||
import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.MODE_METADATA
|
||||
import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.MODE_SOURCECODE
|
||||
import org.jetbrains.kotlin.native.interop.tool.SHORT_MODULE_NAME
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
@@ -167,6 +168,9 @@ private class DefFile(val name: String, val depends: MutableList<DefFile>) {
|
||||
|
||||
val libraryName: String
|
||||
get() = "${PlatformLibsInfo.namePrefix}$name"
|
||||
|
||||
val shortLibraryName: String
|
||||
get() = name
|
||||
}
|
||||
|
||||
private fun createTempDir(prefix: String, parent: File): File =
|
||||
@@ -236,6 +240,7 @@ private fun generateLibrary(
|
||||
"-repo", outputDirectory.absolutePath,
|
||||
"-no-default-libs", "-no-endorsed-libs", "-Xpurge-user-libs", "-nopack",
|
||||
"-mode", mode,
|
||||
"-$SHORT_MODULE_NAME", def.shortLibraryName,
|
||||
*def.depends.flatMap { listOf("-l", "$outputDirectory/${it.libraryName}") }.toTypedArray()
|
||||
)
|
||||
logger.verbose("Run cinterop with args: ${cinteropArgs.joinToString(separator = " ")}")
|
||||
|
||||
@@ -26,6 +26,7 @@ fun invokeInterop(flavor: String, args: Array<String>): Array<String>? {
|
||||
val purgeUserLibs = arguments.purgeUserLibs
|
||||
val nopack = arguments.nopack
|
||||
val temporaryFilesDir = arguments.tempDir
|
||||
val shortModuleName = (arguments as? CInteropArguments)?.shortModuleName
|
||||
|
||||
val buildDir = File("$outputFileName-build")
|
||||
val generatedDir = File(buildDir, "kotlin")
|
||||
@@ -66,6 +67,7 @@ fun invokeInterop(flavor: String, args: Array<String>): Array<String>? {
|
||||
(if (noEndorsedLibs) arrayOf("-$NOENDORSEDLIBS") else emptyArray()) +
|
||||
(if (purgeUserLibs) arrayOf("-$PURGE_USER_LIBS") else emptyArray()) +
|
||||
(if (nopack) arrayOf("-$NOPACK") else emptyArray()) +
|
||||
shortModuleName?.let { arrayOf("-Xshort-module-name=$it") }.orEmpty() +
|
||||
arguments.kotlincOption
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user