diff --git a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt index 73f96e64f23..d5347f6bcff 100644 --- a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt +++ b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt @@ -27,6 +27,7 @@ const val NODEFAULTLIBS = "no-default-libs" const val NOENDORSEDLIBS = "no-endorsed-libs" const val PURGE_USER_LIBS = "Xpurge-user-libs" const val TEMP_DIR = "Xtemporary-files-dir" +const val PROJECT_DIR = "Xproject-dir" const val NOPACK = "nopack" const val COMPILE_SOURCES = "Xcompile-source" const val SHORT_MODULE_NAME = "Xshort-module-name" @@ -63,6 +64,8 @@ open class CommonInteropArguments(val argParser: ArgParser) { description = "Don't pack the produced library into a klib file").default(false) val tempDir by argParser.option(ArgType.String, TEMP_DIR, description = "save temporary files to the given directory") + val projectDir by argParser.option(ArgType.String, PROJECT_DIR, + description = "base directory for relative libraryPath") val kotlincOption by argParser.option(ArgType.String, "Xkotlinc-option", description = "additional kotlinc compiler option").multiple() val overrideKonanProperties by argParser.option(ArgType.String, diff --git a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt index 85833c45010..996dcbab4c0 100644 --- a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt +++ b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt @@ -45,6 +45,7 @@ import java.io.File import java.lang.IllegalArgumentException import java.nio.file.* import java.util.* +import kotlin.io.path.absolutePathString data class InternalInteropOptions(val generated: String, val natives: String, val manifest: String? = null, val cstubsName: String? = null) @@ -235,7 +236,12 @@ private fun processCLib(flavor: KotlinPlatform, cinteropArguments: CInteropArgum val excludedFunctions = def.config.excludedFunctions.toSet() val excludedMacros = def.config.excludedMacros.toSet() val staticLibraries = def.config.staticLibraries + cinteropArguments.staticLibrary.toTypedArray() - val libraryPaths = def.config.libraryPaths + cinteropArguments.libraryPath.toTypedArray() + val projectDir = cinteropArguments.projectDir + val libraryPaths = (def.config.libraryPaths + cinteropArguments.libraryPath).map { + if (projectDir == null || Paths.get(it).isAbsolute) + it + else Paths.get(projectDir, it).absolutePathString() + } val fqParts = (cinteropArguments.pkg ?: def.config.packageName)?.split('.') ?: defFile!!.name.split('.').reversed().drop(1)