-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add native libraries loading support #218
Comments
The native library does not make a lot of sense without its wrapper. The annotation that only hot-fixes the problem, but does not add anything new seems to be a rather weak solution. |
I came up to a hacky solution that solves this problem a bit easier. From the user perspective it looks like this: @file:DependsOn(<jni-wrapper.jar>")
import some.wrapper.Clazz
loadLibrary(Clazz::class.java, "<path-to-native-library>")
// some code that uses methods from <jni-wrapper.jar> All we need to do is to implement fun loadLibrary(javaClass: Class<*>, name: String, isAbsolute: Boolean = true) {
val clazz = ClassLoader::class.java
val method = clazz.getDeclaredMethod("loadLibrary", Class::class.java, java.lang.String::class.java, Boolean::class.java)
method.isAccessible = true
method.invoke(null, javaClass, name, isAbsolute)
}
|
Let's discuss the aforementioned JEP in a separate issue |
During the investigation of #214, it turned out that the only way to use a JNI library in notebook is to call
System.load()
orSystem.loadLibrary()
inside the library itself. In some cases (see RDKit) library authors don't do it and don't provide any methods for native library loading.In "general" project setup all dependencies (user code and libraries) are loaded with one URL classloader, so the user may call
System.load()
in their code, and it works. In kernel, library dependencies are loaded with URL classloader, and snippets loaded with anotherorg.jetbrains.kotlin.scripting.compiler.plugin.impl.CompiledScriptClassLoader
. So, loaded JNI wrapper just can't see the native definitions which were loaded bySystem.load()
call in the snippet code.I propose the following solution for this problem:
@file:NativeLibrary(path: String)
addedClasspath
list inorg.jetbrains.kotlinx.jupyter.dependencies.JupyterScriptDependenciesResolverImpl#resolveFromAnnotations
.Loader_$id.load()
After all, it allows to write the code like this:
Current workaround for this problem is to make up a wrapper for the native library with the wrapper inside it, see the warpper for RDKit here
The text was updated successfully, but these errors were encountered: