Pass linkerOpts from .def to klib manifest.
This commit is contained in:
committed by
alexander-gorshenev
parent
e2516f42e6
commit
5effdcb1d2
@@ -124,6 +124,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
put(ABI_VERSION, 1)
|
||||
|
||||
arguments.mainPackage ?.let{ put(ENTRY, it) }
|
||||
arguments.manifestFile ?.let{ put(MANIFEST_FILE, it) }
|
||||
arguments.runtimeFile ?.let{ put(RUNTIME_FILE, it) }
|
||||
arguments.propertyFile ?.let{ put(PROPERTY_FILE, it) }
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
||||
@field:Argument(value = "-list_targets", description = "List available hardware targets")
|
||||
@JvmField var listTargets: Boolean = false
|
||||
|
||||
@field:Argument(value = "-manifest", valueDescription = "<path>", description = "Provide a maniferst addend file")
|
||||
@JvmField var manifestFile: String? = null
|
||||
|
||||
@field:Argument(value = "-nativelibrary", shortName = "-nl", valueDescription = "<path>", description = "Include the native library")
|
||||
@JvmField var nativeLibraries: Array<String>? = null
|
||||
|
||||
|
||||
+2
@@ -43,6 +43,8 @@ class KonanConfigKeys {
|
||||
= CompilerConfigurationKey.create("list backend phases")
|
||||
val LIST_TARGETS: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("list available targets")
|
||||
val MANIFEST_FILE: CompilerConfigurationKey<String?>
|
||||
= CompilerConfigurationKey.create("provide manifest addend file")
|
||||
val META_INFO: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create("generate metadata")
|
||||
val MODULE_KIND: CompilerConfigurationKey<ModuleKind>
|
||||
|
||||
+7
-3
@@ -248,13 +248,14 @@ internal class LinkStage(val context: Context) {
|
||||
val entryPointSelector: List<String>
|
||||
get() = if (nomain) emptyList() else platform.entrySelector
|
||||
|
||||
fun link(objectFiles: List<ObjectFile>): ExecutableFile {
|
||||
fun link(objectFiles: List<ObjectFile>, libraryProvidedLinkerFlags: List<String>): ExecutableFile {
|
||||
val executable = context.config.outputFile
|
||||
val linkCommand = platform.linkCommand(objectFiles, executable, optimize, config.getBoolean(KonanConfigKeys.DEBUG)) +
|
||||
distribution.libffi +
|
||||
asLinkerArgs(config.getNotNull(KonanConfigKeys.LINKER_ARGS)) +
|
||||
entryPointSelector +
|
||||
platform.linkCommandSuffix()
|
||||
platform.linkCommandSuffix() +
|
||||
libraryProvidedLinkerFlags
|
||||
|
||||
runTool(*linkCommand.toTypedArray())
|
||||
if (platform is MacOSBasedPlatform && context.shouldContainDebugInfo()) {
|
||||
@@ -312,6 +313,9 @@ internal class LinkStage(val context: Context) {
|
||||
val bitcodeFiles = listOf(emitted) +
|
||||
libraries.map{it -> it.bitcodePaths}.flatten()
|
||||
|
||||
val libraryProvidedLinkerFlags =
|
||||
libraries.map{it -> it.linkerOpts}.flatten()
|
||||
|
||||
var objectFiles: List<String> = listOf()
|
||||
|
||||
val phaser = PhaseManager(context)
|
||||
@@ -319,7 +323,7 @@ internal class LinkStage(val context: Context) {
|
||||
objectFiles = listOf( llvmLto(bitcodeFiles ) )
|
||||
}
|
||||
phaser.phase(KonanPhase.LINKER) {
|
||||
link(objectFiles)
|
||||
link(objectFiles, libraryProvidedLinkerFlags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
interface KonanLibraryReader {
|
||||
val libraryName: String
|
||||
val bitcodePaths: List<String>
|
||||
val linkerOpts: List<String>
|
||||
fun moduleDescriptor(specifics: LanguageVersionSettings): ModuleDescriptor
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -22,6 +22,7 @@ interface KonanLibraryWriter {
|
||||
fun addLinkData(linkData: LinkData)
|
||||
fun addNativeBitcode(library: String)
|
||||
fun addKotlinBitcode(llvmModule: LLVMModuleRef)
|
||||
fun addManifestAddend(path: String)
|
||||
val mainBitcodeFileName: String
|
||||
fun commit()
|
||||
}
|
||||
|
||||
+2
@@ -89,5 +89,7 @@ class LibraryReaderImpl(override val libDir: File, currentAbiVersion: Int,
|
||||
override val bitcodePaths: List<String>
|
||||
get() = (kotlinDir.listFiles + nativeDir.listFiles).map{it.absolutePath}
|
||||
|
||||
override val linkerOpts: List<String>
|
||||
get() = manifestProperties.propertyList("linkerOpts", target!!.targetSuffix)
|
||||
}
|
||||
|
||||
|
||||
+16
-1
@@ -71,6 +71,12 @@ class LibraryWriterImpl(override val libDir: File, currentAbiVersion: Int,
|
||||
File(library).copyTo(File(nativeDir, basename))
|
||||
}
|
||||
|
||||
override fun addManifestAddend(path: String) {
|
||||
val properties = File(path).loadProperties()
|
||||
manifestProperties.putAll(properties)
|
||||
println("manifest addend: ${properties.stringPropertyNames().joinToString(" ")}")
|
||||
}
|
||||
|
||||
override fun commit() {
|
||||
manifestProperties.saveToFile(manifestFile)
|
||||
if (!nopack) {
|
||||
@@ -80,7 +86,15 @@ class LibraryWriterImpl(override val libDir: File, currentAbiVersion: Int,
|
||||
}
|
||||
}
|
||||
|
||||
internal fun buildLibrary(natives: List<String>, linkData: LinkData, abiVersion: Int, target: KonanTarget, output: String, llvmModule: LLVMModuleRef, nopack: Boolean): KonanLibraryWriter {
|
||||
internal fun buildLibrary(
|
||||
natives: List<String>,
|
||||
linkData: LinkData,
|
||||
abiVersion: Int,
|
||||
target: KonanTarget,
|
||||
output: String,
|
||||
llvmModule: LLVMModuleRef,
|
||||
nopack: Boolean,
|
||||
manifest: String?): KonanLibraryWriter {
|
||||
|
||||
val library = LibraryWriterImpl(output, abiVersion, target, nopack)
|
||||
|
||||
@@ -89,6 +103,7 @@ internal fun buildLibrary(natives: List<String>, linkData: LinkData, abiVersion:
|
||||
natives.forEach {
|
||||
library.addNativeBitcode(it)
|
||||
}
|
||||
manifest ?.let { library.addManifestAddend(it) }
|
||||
|
||||
library.commit()
|
||||
return library
|
||||
|
||||
+3
-1
@@ -110,6 +110,7 @@ internal fun produceOutput(context: Context) {
|
||||
val abiVersion = context.config.currentAbiVersion
|
||||
val target = context.config.targetManager.target
|
||||
val nopack = config.getBoolean(KonanConfigKeys.NOPACK)
|
||||
val manifest = config.get(KonanConfigKeys.MANIFEST_FILE)
|
||||
|
||||
val library = buildLibrary(
|
||||
context.config.nativeLibraries,
|
||||
@@ -118,7 +119,8 @@ internal fun produceOutput(context: Context) {
|
||||
target,
|
||||
libraryName,
|
||||
llvmModule,
|
||||
nopack)
|
||||
nopack,
|
||||
manifest)
|
||||
|
||||
context.library = library
|
||||
context.bitcodeFileName = library.mainBitcodeFileName
|
||||
|
||||
Reference in New Issue
Block a user