Implement --purge_user_libs konanc and cinterop flag
This commit is contained in:
committed by
SvyatoslavScherbina
parent
68d30205c4
commit
9829605a95
@@ -120,6 +120,8 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
put(PRINT_LOCATIONS, arguments.printLocations)
|
put(PRINT_LOCATIONS, arguments.printLocations)
|
||||||
put(PRINT_BITCODE, arguments.printBitCode)
|
put(PRINT_BITCODE, arguments.printBitCode)
|
||||||
|
|
||||||
|
put(PURGE_USER_LIBS, arguments.purgeUserLibs)
|
||||||
|
|
||||||
put(VERIFY_IR, arguments.verifyIr)
|
put(VERIFY_IR, arguments.verifyIr)
|
||||||
put(VERIFY_DESCRIPTORS, arguments.verifyDescriptors)
|
put(VERIFY_DESCRIPTORS, arguments.verifyDescriptors)
|
||||||
put(VERIFY_BITCODE, arguments.verifyBitCode)
|
put(VERIFY_BITCODE, arguments.verifyBitCode)
|
||||||
|
|||||||
@@ -121,6 +121,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
|||||||
@Argument(value = "--print_locations", description = "Print locations")
|
@Argument(value = "--print_locations", description = "Print locations")
|
||||||
var printLocations: Boolean = false
|
var printLocations: Boolean = false
|
||||||
|
|
||||||
|
@Argument(value = "--purge_user_libs", description = "Don't link unused libraries even explicitly specified")
|
||||||
|
var purgeUserLibs: Boolean = false
|
||||||
|
|
||||||
@Argument(value = "--time", description = "Report execution time for compiler phases")
|
@Argument(value = "--time", description = "Report execution time for compiler phases")
|
||||||
var timePhases: Boolean = false
|
var timePhases: Boolean = false
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -73,6 +73,9 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
|||||||
val moduleId: String
|
val moduleId: String
|
||||||
get() = configuration.get(KonanConfigKeys.MODULE_NAME) ?: File(outputName).name
|
get() = configuration.get(KonanConfigKeys.MODULE_NAME) ?: File(outputName).name
|
||||||
|
|
||||||
|
internal val purgeUserLibs: Boolean
|
||||||
|
get() = configuration.getBoolean(KonanConfigKeys.PURGE_USER_LIBS)
|
||||||
|
|
||||||
private val libraryNames: List<String>
|
private val libraryNames: List<String>
|
||||||
get() = configuration.getList(KonanConfigKeys.LIBRARY_FILES)
|
get() = configuration.getList(KonanConfigKeys.LIBRARY_FILES)
|
||||||
|
|
||||||
@@ -95,7 +98,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
|||||||
fun librariesWithDependencies(moduleDescriptor: ModuleDescriptor?): List<KonanLibraryReader> {
|
fun librariesWithDependencies(moduleDescriptor: ModuleDescriptor?): List<KonanLibraryReader> {
|
||||||
if (moduleDescriptor == null) error("purgeUnneeded() only works correctly after resolve is over, and we have successfully marked package files as needed or not needed.")
|
if (moduleDescriptor == null) error("purgeUnneeded() only works correctly after resolve is over, and we have successfully marked package files as needed or not needed.")
|
||||||
|
|
||||||
return immediateLibraries.purgeUnneeded().withResolvedDependencies()
|
return immediateLibraries.purgeUnneeded(this).withResolvedDependencies()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val loadedDescriptors = loadLibMetadata()
|
private val loadedDescriptors = loadLibMetadata()
|
||||||
|
|||||||
+2
@@ -85,6 +85,8 @@ class KonanConfigKeys {
|
|||||||
= CompilerConfigurationKey.create("compiler output kind")
|
= CompilerConfigurationKey.create("compiler output kind")
|
||||||
val PROPERTY_FILE: CompilerConfigurationKey<String?>
|
val PROPERTY_FILE: CompilerConfigurationKey<String?>
|
||||||
= CompilerConfigurationKey.create("override default property file path")
|
= CompilerConfigurationKey.create("override default property file path")
|
||||||
|
val PURGE_USER_LIBS: CompilerConfigurationKey<Boolean>
|
||||||
|
= CompilerConfigurationKey.create("purge user-specified libs too")
|
||||||
val REPOSITORIES: CompilerConfigurationKey<List<String>>
|
val REPOSITORIES: CompilerConfigurationKey<List<String>>
|
||||||
= CompilerConfigurationKey.create("library search path repositories")
|
= CompilerConfigurationKey.create("library search path repositories")
|
||||||
val RUNTIME_FILE: CompilerConfigurationKey<String?>
|
val RUNTIME_FILE: CompilerConfigurationKey<String?>
|
||||||
|
|||||||
+3
-1
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan.library.impl
|
package org.jetbrains.kotlin.backend.konan.library.impl
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.konan.KonanConfig
|
||||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryReader
|
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryReader
|
||||||
import org.jetbrains.kotlin.backend.konan.createInteropLibrary
|
import org.jetbrains.kotlin.backend.konan.createInteropLibrary
|
||||||
import org.jetbrains.kotlin.backend.konan.serialization.emptyPackages
|
import org.jetbrains.kotlin.backend.konan.serialization.emptyPackages
|
||||||
@@ -98,5 +99,6 @@ class LibraryReaderImpl(var libraryFile: File, val currentAbiVersion: Int,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun <T: KonanLibraryReader> List<T>.purgeUnneeded(): List<T> = this.filter{ !it.isDefaultLibrary || it.isNeededForLink }
|
internal fun <T: KonanLibraryReader> List<T>.purgeUnneeded(config: KonanConfig): List<T> =
|
||||||
|
this.filter{ (!it.isDefaultLibrary && !config.purgeUserLibs) || it.isNeededForLink }
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -328,7 +328,7 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val librariesToLink: List<KonanLibraryReader> get() = context.config.immediateLibraries
|
val librariesToLink: List<KonanLibraryReader> get() = context.config.immediateLibraries
|
||||||
.filter { !it.isDefaultLibrary || it in usedLibraries }
|
.filter { (!it.isDefaultLibrary && !context.config.purgeUserLibs) || it in usedLibraries }
|
||||||
.withResolvedDependencies()
|
.withResolvedDependencies()
|
||||||
|
|
||||||
val librariesForLibraryManifest: List<KonanLibraryReader> get() {
|
val librariesForLibraryManifest: List<KonanLibraryReader> get() {
|
||||||
|
|||||||
@@ -28,15 +28,17 @@ import org.jetbrains.kotlin.native.interop.gen.jvm.interop
|
|||||||
import org.jetbrains.kotlin.cli.klib.main as klibMain
|
import org.jetbrains.kotlin.cli.klib.main as klibMain
|
||||||
|
|
||||||
private val NODEFAULTLIBS = "-nodefaultlibs"
|
private val NODEFAULTLIBS = "-nodefaultlibs"
|
||||||
|
private val PURGE_USER_LIBS = "--purge_user_libs"
|
||||||
|
|
||||||
fun invokeCinterop(args: Array<String>) {
|
fun invokeCinterop(args: Array<String>) {
|
||||||
val cinteropArgFilter = listOf(NODEFAULTLIBS)
|
val cinteropArgFilter = listOf(NODEFAULTLIBS, PURGE_USER_LIBS)
|
||||||
|
|
||||||
var outputFileName = "nativelib"
|
var outputFileName = "nativelib"
|
||||||
var target = "host"
|
var target = "host"
|
||||||
val libraries = mutableListOf<String>()
|
val libraries = mutableListOf<String>()
|
||||||
val repos = mutableListOf<String>()
|
val repos = mutableListOf<String>()
|
||||||
var noDefaultLibs = false
|
var noDefaultLibs = false
|
||||||
|
var purgeUserLibs = false
|
||||||
for (i in args.indices) {
|
for (i in args.indices) {
|
||||||
val arg = args[i]
|
val arg = args[i]
|
||||||
val nextArg = args.getOrNull(i + 1)
|
val nextArg = args.getOrNull(i + 1)
|
||||||
@@ -50,6 +52,8 @@ fun invokeCinterop(args: Array<String>) {
|
|||||||
repos.addIfNotNull(nextArg)
|
repos.addIfNotNull(nextArg)
|
||||||
if (arg == NODEFAULTLIBS)
|
if (arg == NODEFAULTLIBS)
|
||||||
noDefaultLibs = true
|
noDefaultLibs = true
|
||||||
|
if (arg == PURGE_USER_LIBS)
|
||||||
|
purgeUserLibs = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +101,8 @@ fun invokeCinterop(args: Array<String>) {
|
|||||||
"-target", target,
|
"-target", target,
|
||||||
"-manifest", manifest.path
|
"-manifest", manifest.path
|
||||||
) + cinteropArgsToCompiler + libraries.flatMap { listOf("-library", it) } + repos.flatMap { listOf("-repo", it) } +
|
) + cinteropArgsToCompiler + libraries.flatMap { listOf("-library", it) } + repos.flatMap { listOf("-repo", it) } +
|
||||||
if (noDefaultLibs) arrayOf(NODEFAULTLIBS) else emptyArray()
|
(if (noDefaultLibs) arrayOf(NODEFAULTLIBS) else emptyArray()) +
|
||||||
|
(if (purgeUserLibs) arrayOf(PURGE_USER_LIBS) else emptyArray())
|
||||||
|
|
||||||
konancMain(konancArgs)
|
konancMain(konancArgs)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user